From 0aa9d59be725e8cf00413cf8927ddd883281da6f Mon Sep 17 00:00:00 2001 From: PintoPirate <189064953+PintoPirate@users.noreply.github.com> Date: Wed, 31 Dec 2025 18:15:13 -0500 Subject: [PATCH] Adjust entrypoint command to wait for redis to come online --- docker/docker-compose.yml | 2 +- docker/inbuilt/entrypoint-proxy.sh | 34 ++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 9a629b7..b3ddb04 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -8,7 +8,7 @@ services: - "${KOAJS_PORT}:3000" env_file: - .env - entrypoint: ["./entrypoint-proxy.sh", "postgres", "5432", "npm", "start"] + entrypoint: ["./entrypoint-proxy.sh", "postgres", "5432", "redis", "6379", "npm", "start"] restart: no healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/healthcheck"] diff --git a/docker/inbuilt/entrypoint-proxy.sh b/docker/inbuilt/entrypoint-proxy.sh index 46e55aa..55bfb26 100755 --- a/docker/inbuilt/entrypoint-proxy.sh +++ b/docker/inbuilt/entrypoint-proxy.sh @@ -1,24 +1,44 @@ #!/bin/sh # This script is used by the compose file as an entrypoint proxy for the api container. -# Waits for postgres to be available before running any following startup commands. +# Waits for postgres and redis to be available before running any following startup commands. set -e -host=$1 -port=$2 -shift -shift +pg_host=$1 +pg_port=$2 +redis_host=$3 +redis_port=$4 +shift 4 cmd="$@" echo "Entrypoint script for $NODE_ENV" -until pg_isready -h "$host" -p "$port"; do +# Wait for Postgres +echo "Waiting for Postgres at $pg_host:$pg_port..." +until pg_isready -h "$pg_host" -p "$pg_port"; do echo "Postgres is unavailable - sleeping" sleep 1 done +echo "Postgres is up" -echo "Postgres is up - running any sequelize migrations/seeders..." +# Wait for Redis +echo "Waiting for Redis at $redis_host:$redis_port..." +until node -e " + const net = require('net'); + const client = net.createConnection({host: '$redis_host', port: $redis_port}, () => { + client.end(); + process.exit(0); + }); + client.on('error', () => process.exit(1)); + setTimeout(() => process.exit(1), 2000); +" 2>/dev/null; do + echo "Redis is unavailable - sleeping" + sleep 1 +done +echo "Redis is up" + +echo "Running any sequelize migrations/seeders..." if [ "$NODE_ENV" != "indexing" ]; then echo "Running migrations" npx sequelize-cli db:migrate