Skip to content

Commit

Permalink
hobby: Wait for ClickHouse and for Postgres before starting (#8686)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech authored Feb 18, 2022
1 parent d7a0c10 commit 24eb266
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion bin/deploy-hobby
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,42 @@ SENTRY_DSN=$SENTRY_DSN
DOMAIN=$DOMAIN
EOF


# write entrypoint
rm -rf compose
mkdir -p compose
cat > compose/start <<EOF
#!/bin/bash
/compose/wait
./bin/migrate
./bin/docker-server
./bin/docker-frontend
EOF
chmod +x compose/start

# write wait script
cat > compose/wait <<EOF
#!/usr/bin/env python3
import socket
import time
def loop():
print("Waiting for ClickHouse and Postgres to be ready")
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('clickhouse', 9000))
print("Clickhouse is ready")
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('db', 5432))
print("Postgres is ready")
except ConnectionRefusedError as e:
time.sleep(5)
loop()
loop()
EOF
chmod +x compose/wait

# setup docker
echo "Setting up Docker"
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
Expand Down Expand Up @@ -100,10 +124,12 @@ curl -L --header "Content-Type: application/json" -d '{
}' https://app.posthog.com/batch/

# start up the stack
echo "Configuring Docker Compose...."
rm -f docker-compose.yml
cp posthog/docker-compose.hobby.yml docker-compose.yml.tmpl
envsubst < docker-compose.yml.tmpl > docker-compose.yml
rm docker-compose.yml.tmpl
echo "Starting the stack!"
sudo -E docker-compose -f docker-compose.yml up -d

echo "We will need to wait ~5-10 minutes for things to settle down, migrations to finish, and TLS certs to be issued"
Expand Down

0 comments on commit 24eb266

Please sign in to comment.