From cafe94df23f73990561be4d12496cb34697d9ffd Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 3 Sep 2024 16:42:05 +0200 Subject: [PATCH 1/5] Create README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d03d727 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# Snappy Env + +This program can be used to add runtime environment variable support to snaps. +By adding this program to the command chain of snapped applications, it will add support for: +- Converting snap options to environment variables based on a custom mapping +- Taking path to env files as input, loaded before starting the applications + +The program is intended to be used by the Env Injector extension; the documentation for that is available [here](https://forum.snapcraft.io/t/the-env-injector-extension/41477). + +There are currently two implementations for the extension. The Rust implementation is considered more stable. + +The program can also be used without the extension. Refer to [snap/snapcraft.yaml](snap/snapcraft.yaml) for an example. + +Testing and benchmarking scripts are under [tests](/tests). From 238347ae760a244beb495687fcce170f71799d5e Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Tue, 3 Sep 2024 17:56:03 +0200 Subject: [PATCH 2/5] Add example snap --- .gitignore | 3 ++ snap/local/bin/env.sh | 3 ++ snap/snapcraft.yaml | 79 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100755 snap/local/bin/env.sh create mode 100644 snap/snapcraft.yaml diff --git a/.gitignore b/.gitignore index cf662f7..55ff073 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ target/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +*.snap +squashfs-root \ No newline at end of file diff --git a/snap/local/bin/env.sh b/snap/local/bin/env.sh new file mode 100755 index 0000000..076e427 --- /dev/null +++ b/snap/local/bin/env.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +env \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 0000000..7b55093 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,79 @@ +name: envtester +base: core24 +version: 'demo' +summary: Demonstration of env-exporter program +description: | + envtester is a demo snap to show the env-exporter program usecases + +grade: stable +confinement: strict + +apps: + # App using bash implementation + app1: + environment: + app_alias: app1 + command-chain: + - bin/env-exporter.sh + command: bin/env.sh + + # App using bash implementation - with app alias + app2: + environment: + app_alias: myapp2 + command-chain: + - bin/env-exporter.sh + command: bin/env.sh + + # App using Rust implementation + app3: + environment: + app_alias: app1 + command-chain: + - bin/env-exporter + command: bin/env.sh + + # App using Rust implementation - with app alias + app4: + environment: + app_alias: myapp4 + command-chain: + - bin/env-exporter + command: bin/env.sh + + # App without using env exporter for benchmarking purposes + app0: + command: bin/env.sh + +parts: + myapp: + plugin: dump + source: snap/local + + env-exporter-bash: + plugin: dump + source: env-exporter.sh + source-type: file + organize: + env-exporter.sh: bin/env-exporter.sh + + env-exporter-rust: + plugin: nil + source: . + build-snaps: + - rustup + build-packages: + - upx-ucl # for binary compression + override-build: | + rustup default stable + + TARGET=x86_64-unknown-linux-gnu + + rustup target add $TARGET + cargo build --target $TARGET --release + mkdir -p $SNAPCRAFT_PART_INSTALL/bin + + # compress the binary + upx --best --lzma target/$TARGET/release/env-exporter + cp target/$TARGET/release/env-exporter $SNAPCRAFT_PART_INSTALL/bin + \ No newline at end of file From fa771b995bc91b0da942238487612097d7e5d091 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Wed, 4 Sep 2024 10:25:09 +0200 Subject: [PATCH 3/5] Create cla-check.yml --- .github/workflows/cla-check.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/cla-check.yml diff --git a/.github/workflows/cla-check.yml b/.github/workflows/cla-check.yml new file mode 100644 index 0000000..27bc14d --- /dev/null +++ b/.github/workflows/cla-check.yml @@ -0,0 +1,9 @@ +name: CLA Check +on: [pull_request_target] + +jobs: + cla-check: + runs-on: ubuntu-latest + steps: + - name: Check if CLA signed + uses: canonical/has-signed-canonical-cla@v1 From 88557205caa98cef01d978c7bde6ab9ca839ff26 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Wed, 4 Sep 2024 16:50:14 +0200 Subject: [PATCH 4/5] Simplify snap --- snap/hooks/configure | 4 ++++ snap/snapcraft.yaml | 33 ++++++++------------------------- 2 files changed, 12 insertions(+), 25 deletions(-) create mode 100644 snap/hooks/configure diff --git a/snap/hooks/configure b/snap/hooks/configure new file mode 100644 index 0000000..417eec2 --- /dev/null +++ b/snap/hooks/configure @@ -0,0 +1,4 @@ +#!/bin/bash + +# Do nothing +# This is only to allow setting snap configuration options from outside \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 7b55093..e97495f 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,48 +1,31 @@ name: envtester base: core24 version: 'demo' -summary: Demonstration of env-exporter program -description: | - envtester is a demo snap to show the env-exporter program usecases +summary: Demonstration of snappy-env program +description: A demo snap to test the usage of snappy-env grade: stable confinement: strict apps: # App using bash implementation - app1: + app-bash: environment: - app_alias: app1 - command-chain: - - bin/env-exporter.sh - command: bin/env.sh - - # App using bash implementation - with app alias - app2: - environment: - app_alias: myapp2 + env_alias: app-bash command-chain: - bin/env-exporter.sh command: bin/env.sh # App using Rust implementation - app3: - environment: - app_alias: app1 - command-chain: - - bin/env-exporter - command: bin/env.sh - - # App using Rust implementation - with app alias - app4: + app-rust: environment: - app_alias: myapp4 + env_alias: app-rust command-chain: - bin/env-exporter command: bin/env.sh - # App without using env exporter for benchmarking purposes - app0: + # App without using snappy-env, for benchmarking purposes + app: command: bin/env.sh parts: From 5f7f325d31bdbf4b8feb59b299cff4f15bb27e04 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Wed, 4 Sep 2024 16:52:56 +0200 Subject: [PATCH 5/5] Improve manual usage explanation --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d03d727..3164fb5 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ By adding this program to the command chain of snapped applications, it will add - Converting snap options to environment variables based on a custom mapping - Taking path to env files as input, loaded before starting the applications -The program is intended to be used by the Env Injector extension; the documentation for that is available [here](https://forum.snapcraft.io/t/the-env-injector-extension/41477). +The program is intended to be used by the Env Injector Snapcraft extension; the documentation for that is available [here](https://forum.snapcraft.io/t/the-env-injector-extension/41477). -There are currently two implementations for the extension. The Rust implementation is considered more stable. +There are currently two implementations for the Snapcraft extension. The Rust implementation is considered more stable. -The program can also be used without the extension. Refer to [snap/snapcraft.yaml](snap/snapcraft.yaml) for an example. - -Testing and benchmarking scripts are under [tests](/tests). +To use snappy-env directly and without the Snapcraft extension; refer to [snap/snapcraft.yaml](snap/snapcraft.yaml) as an example.