entrypoint for env vars

This commit is contained in:
Mayel de Borniol 2022-03-09 15:36:58 +13:00
parent 1cd075d8a2
commit 4b34097657
2 changed files with 43 additions and 0 deletions

View File

@ -30,6 +30,11 @@ services:
- internal
ports:
- "4000:4000" # make sure this is commented in production
entrypoint: "/docker-entrypoint.sh"
configs:
- source: app_entrypoint
target: /docker-entrypoint.sh
mode: 0555
deploy:
restart_policy:
condition: on-failure
@ -74,6 +79,11 @@ services:
- "search-data:/data.ms"
networks:
- internal
entrypoint: ["/tini", "--", "/docker-entrypoint.sh"]
configs:
- source: app_entrypoint
target: /docker-entrypoint.sh
mode: 0555
volumes:
db-data:
@ -85,6 +95,12 @@ networks:
external: true
internal:
configs:
app_entrypoint:
name: ${STACK_NAME}_app_entrypoint_${APP_ENTRYPOINT_VERSION}
file: entrypoint.sh.tmpl
template_driver: golang
secrets:
postgres_password:
external: true

27
entrypoint.sh.tmpl Normal file
View File

@ -0,0 +1,27 @@
#!/bin/bash
set -e
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env "MEILI_MASTER_KEY"