From b835e5f0f0be7811e183b958c4b0c415f748d5f6 Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Tue, 17 Aug 2021 09:42:53 +0100 Subject: [PATCH] build(docker): require commands in the entry point script to pass By default, a shell script carries on even if a step fails. If, for example, a migration fails, the app starts up anyway with an unknown and possibly dangerous result. This change causes a failure in any command to fail the whole script, except in cases where it's acceptable (as we test the exit code). Refs #390, #395 --- docker-entrypoint.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index d1fe64a2..b782dfe7 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,4 +1,5 @@ #!/bin/sh +set -e TRIES=30 DELAY=4 @@ -18,9 +19,11 @@ FROM_NAME=${IMPORT_FROM_NAME:-production} wait_for() { echo "Waiting for service => HOST: $HOST, PORT: $PORT" for i in $(seq $TRIES); do + set +e nc -z "$HOST" "$PORT" >/dev/null 2>&1 - result=$? + set -e + if [ $result -eq 0 ]; then echo "Service is up!" return 0 @@ -68,9 +71,11 @@ elif [ $NODE_ENV == "integration" ]; then init_db npm run db:apiKey else + set +e env -i PGPASSWORD="$PASS" /usr/bin/psql -U "$USER" -d "$NAME" -h "$HOST" -p "$PORT" -tAc "SELECT to_regclass('public.user')" | grep -q user - result=$? + set -e + if [ $result -ne 0 ]; then init_db if [ $NODE_ENV == "development" ]; then