Skip to content

Commit

Permalink
build(docker): require commands in the entry point script to pass
Browse files Browse the repository at this point in the history
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
  • Loading branch information
thewilkybarkid committed Aug 17, 2021
1 parent 3c403cd commit b835e5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
set -e

TRIES=30
DELAY=4
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b835e5f

Please sign in to comment.