Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation and examples #8

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# 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 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 Snapcraft extension. The Rust implementation is considered more stable.

To use snappy-env directly and without the Snapcraft extension; refer to [snap/snapcraft.yaml](snap/snapcraft.yaml) as an example.
4 changes: 4 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# Do nothing
# This is only to allow setting snap configuration options from outside
3 changes: 3 additions & 0 deletions snap/local/bin/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

env
62 changes: 62 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: envtester
base: core24
version: 'demo'
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
app-bash:
environment:
env_alias: app-bash
command-chain:
- bin/env-exporter.sh
command: bin/env.sh

# App using Rust implementation
app-rust:
environment:
env_alias: app-rust
command-chain:
- bin/env-exporter
command: bin/env.sh

# App without using snappy-env, for benchmarking purposes
app:
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

Loading