Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
34 changes: 27 additions & 7 deletions docker/inbuilt/entrypoint-proxy.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down