This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
generated from homecentr/docker-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Loading environment variable values from file (#17)
- Loading branch information
Showing
11 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello, world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |