Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add healthchecks to docker-compose.yml #186

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM docker.io/library/python:3.9-slim

ARG BUILD_DEPS="build-essential curl"
ARG BUILD_DEPS="build-essential"

RUN set -ex \
&& apt-get update && apt-get -y --no-install-recommends install $BUILD_DEPS libpq-dev netcat make git \
&& apt-get update && apt-get -y --no-install-recommends install $BUILD_DEPS libpq-dev make git curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL "https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py" | python \
&& . $HOME/.poetry/env \
Expand Down
28 changes: 26 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: "3.8"

x-gunicorn-master: &x-gunicorn-master
build: .
Expand All @@ -22,6 +22,12 @@ x-gunicorn-master: &x-gunicorn-master
- SQL_USER=postgres
- SQL_DATABASE=postgres
- EMAIL_PROVIDER=CONSOLE
depends_on:
database:
condition: service_healthy
redis:
condition: service_started


services:
redis:
Expand All @@ -32,6 +38,11 @@ services:
environment:
- POSTGRES_EXTENSIONS=citext
- POSTGRES_HOST_AUTH_METHOD=trust
healthcheck:
test: ["CMD", "pg_isready", "-U", "postgres"]
interval: 1s
timeout: 30s
retries: 30

shell:
image: ghcr.io/ractf/shell:latest
Expand All @@ -55,10 +66,23 @@ services:
command: gunicorn backend.wsgi:application
depends_on:
- database
healthcheck:
test: ["CMD", "curl", "--silent", "--fail", "http://localhost:8000/api/v2/healthcheck/?format=json"]
interval: 10s
timeout: 50s
retries: 5

sockets:
<<: *x-gunicorn-master
entrypoint: /app/entrypoints/sockets.sh
command: gunicorn backend.asgi:application
depends_on:
- backend
backend:
condition: service_healthy

watchtower:
image: docker.io/containrrr/watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/.docker/config.json:/config.json
command: --interval 5
13 changes: 0 additions & 13 deletions entrypoints/backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,10 @@ else
rm $prometheus_multiproc_dir/* -rf
fi

echo "Waiting for postgres... "
while ! nc -z $SQL_HOST $SQL_PORT
do
sleep 0.69
done
echo "Done."

echo "Running migrations..."
/app/src/manage.py migrate
echo "Done."

if [ "$LOAD_FIXTURES" ]
jerbob marked this conversation as resolved.
Show resolved Hide resolved
then
/app/src/manage.py flush --no-input
/app/src/manage.py loaddata test_fixtures
fi

export GUNICORN_CMD_ARGS="--chdir=/app/src/ --reload --workers=4 --bind=0.0.0.0:8000 --worker-class=gthread"
if [ -f /etc/newrelic.ini ]
then
Expand Down
14 changes: 0 additions & 14 deletions entrypoints/sockets.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/usr/bin/env sh

echo "Waiting for postgres... "
while ! nc -z $SQL_HOST $SQL_PORT
do
sleep 0.69
done
echo "Done."

echo "Waiting for django... "
while ! nc -z backend 8000
do
sleep 0.69
done
echo "Done."

export GUNICORN_CMD_ARGS="--chdir=/app/src/ --reload --workers=4 --bind=0.0.0.0:8000 --worker-class=uvicorn.workers.UvicornWorker"
if [ -f /etc/newrelic.ini ]
then
Expand Down
Loading