Add docker entrypoint for loading secrets
continuous-integration/drone/push Build is failing Details

This commit is contained in:
3wc 2024-04-04 11:29:05 -03:00
parent 7f508fc04b
commit 509b6b5e8b
2 changed files with 35 additions and 1 deletions

32
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
set -eu
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 "TOKEN"
file_env "MONGODB_PASSWORD"
file_env "PAYLOAD_SECRET"
export MONGODB_URI="mongodb://$MONGODB_USER:$MONGODB_PASSWORD@$MONGODB_HOST:$MONGODB_PORT"
"$@"

View File

@ -26,4 +26,6 @@ COPY --from=build /build/tsconfig.json ./tsconfig.json
COPY --from=build /build/dist ./dist
COPY --from=build /build/build ./build
EXPOSE 3000
CMD ["yarn", "serve"]
COPY docker-entrypoint.sh /
ENTRYPOINT /docker-entrypoint.sh
CMD ["yarn", "serve"]