Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
feat: Loading environment variable values from file (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
lholota committed May 15, 2020
1 parent 2a3e3f3 commit 8bc1ceb
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* text=auto
*.sh eol=lf
**/run eol=lf
*/services.d/* eol=lf
*/services.d/* eol=lf
**/run eol=lf
10 changes: 10 additions & 0 deletions alpine/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.7"
services:
base_centos:
build: .
image: homecentr/base:alpine-local
environment:
FILE__TEST_VAR: "/var-value.txt"
volumes:
- "./example/run:/etc/services.d/env-test/run"
- "./example/var-value.txt:/var-value.txt"
9 changes: 0 additions & 9 deletions alpine/example/Dockerfile

This file was deleted.

3 changes: 3 additions & 0 deletions alpine/example/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv ash

exec echo "TEST_VAR=$TEST_VAR"
1 change: 1 addition & 0 deletions alpine/example/var-value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
14 changes: 14 additions & 0 deletions alpine/fs/etc/cont-init.d/01-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/with-contenv ash

for FILENAME in /var/run/s6/container_environment/FILE__*; do
VAR_VALUE_FILE=$(cat ${FILENAME})
VAR_NAME="${FILENAME#'/var/run/s6/container_environment/FILE__'}"

if [ -f "$VAR_VALUE_FILE" ]; then
cat "$VAR_VALUE_FILE" > "/var/run/s6/container_environment/${VAR_NAME}"
echo "[env-vars] Variable $VAR_NAME set from ${VAR_VALUE_FILE}"
else
echo "[env-vars] Variable $VAR_NAME could not be set from ${VAR_VALUE_FILE}. File not found."
fi

done
10 changes: 10 additions & 0 deletions centos/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.7"
services:
base_centos:
build: .
image: homecentr/base:centos-local
environment:
FILE__TEST_VAR: "/var-value.txt"
volumes:
- "./example/run:/etc/services.d/env-test/run"
- "./example/var-value.txt:/var-value.txt"
9 changes: 0 additions & 9 deletions centos/example/Dockerfile

This file was deleted.

3 changes: 3 additions & 0 deletions centos/example/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

exec echo "TEST_VAR=$TEST_VAR"
1 change: 1 addition & 0 deletions centos/example/var-value.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, world!
14 changes: 14 additions & 0 deletions centos/fs/etc/cont-init.d/01-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/with-contenv bash

for FILENAME in /var/run/s6/container_environment/FILE__*; do
VAR_VALUE_FILE=$(cat ${FILENAME})
VAR_NAME="${FILENAME#'/var/run/s6/container_environment/FILE__'}"

if [ -f "$VAR_VALUE_FILE" ]; then
cat "$VAR_VALUE_FILE" > "/var/run/s6/container_environment/${VAR_NAME}"
echo "[env-vars] Variable $VAR_NAME set from ${VAR_VALUE_FILE}"
else
echo "[env-vars] Variable $VAR_NAME could not be set from ${VAR_VALUE_FILE}. File not found."
fi

done

0 comments on commit 8bc1ceb

Please sign in to comment.