Skip to content

Commit 39d5b86

Browse files
committed
generate bucket.env
1 parent 91300fb commit 39d5b86

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ update:
2424
update-recipes:
2525
${composer} symfony:sync-recipes --force
2626
shell:
27-
${exec} $${SERVICE:-app} sh
27+
${exec} $${SERVICE:-app} sh -c "if [ -f /run/secrets/env_bucket ]; then set -a && . /run/secrets/env_bucket; fi; sh"
2828
mysql:
2929
${exec} $${SERVICE:-db} sh -c "mysql -u \$${MYSQL_USER} -p\$${MYSQL_PASSWORD} \$${MYSQL_DATABASE}"
3030

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,19 @@ devops/bin/json.sh -f devops/environment/dev/secrets/bucket.json '{"SOME_SECRET"
196196
197197
# read value
198198
value=$(devops/bin/json.sh -r devops/environment/dev/secrets/bucket.json SOME_SECRET)
199+
200+
# export .env file
201+
devops/bin/json.sh -e devops/environment/dev/secrets/bucket.json devops/environment/dev/secrets/bucket.env
199202
```
200203

201-
The [OpenSSL] binary is available at:
204+
The [OpenSSL] binary is available using:
202205

203206
```bash
204207
devops/bin/openssl.sh genrsa ...
205208
```
206209

210+
ℹ️ The environment variables from `bucket.env` are sourced as real environment variables on start-up
211+
207212
# Create Application
208213

209214
Bootstrap the initial skeleton first:

devops/bin/json.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
force=0; [ "$1" = -f ] && shift && force=1
44
read=0; [ "$1" = -r ] && shift && read=1
5+
export=0; [ "$1" = -e ] && shift && export=1
56
file=${1:?}
67
json=${2:?}
78

89
php="docker run --init -i --rm -v $(pwd):/app -w /app -u $(id -u):$(id -g) composer php"
910
source='{}'; [ -f "${file}" ] && source=$(cat "${file}")
1011
old=$(printf '%s' "${source}" | ${php} -r "var_export(json_decode(trim(file_get_contents('php://stdin')), true, 512, JSON_THROW_ON_ERROR));")
1112

13+
if [ ${export} -eq 1 ]; then
14+
${php} -r "foreach (array_map('escapeshellarg', array_filter(${old}, 'is_string')) as \$k => \$v) { echo \"{\$k}={\$v}\n\"; }" > "${json}"
15+
exit $?
16+
fi
17+
1218
if [ ${read} -eq 1 ]; then
1319
printf '%s' "${json}" | ${php} -r "echo (${old})[file_get_contents('php://stdin')] ?? '';"
1420
exit $?

devops/environment/base/docker-compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ services:
1515
build:
1616
<<: *base
1717
target: "app-${STAGING_ENV:?}"
18-
secrets: [json_bucket]
18+
secrets: [json_bucket, env_bucket]
19+
command: [sh, -c, "set -a && . /run/secrets/env_bucket && php-fpm"]
1920

2021
web:
2122
build:
@@ -26,3 +27,5 @@ services:
2627
secrets:
2728
json_bucket:
2829
file: ./secrets/bucket.json
30+
env_bucket:
31+
file: ./secrets/bucket.env

devops/environment/base/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ cd "../${staging_env}/secrets"
4040
${json} bucket.json "{\"APP_SECRET\": \"$(${openssl} rand -hex 16)\"}"
4141
[ $? -ne 0 ] && cd - && exit 1
4242

43+
${json} -e bucket.json bucket.env
44+
[ $? -ne 0 ] && cd - && exit 1
45+
4346
cd - >/dev/null

0 commit comments

Comments
 (0)