From 0c592efa51421238aea8fa89d504f3b0739ce93c Mon Sep 17 00:00:00 2001 From: Ryan W Date: Sat, 30 Sep 2023 11:46:38 -0700 Subject: [PATCH] Add healthcheck --- .github/workflows/docker.yml | 4 ++-- production.Dockerfile | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 8a004236..1cedff86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -49,8 +49,8 @@ jobs: - name: Check Health run: | - HEALTH_STATUS=$(docker inspect --format='{{.State.Status}}' rails-on-docker); + HEALTH_STATUS=$(docker inspect --format='{{.State.Health}}' rails-on-docker); echo "$HEALTH_STATUS" - if [ "$HEALTH_STATUS" != "running" ]; then + if [ "$HEALTH_STATUS" != "healthy" ]; then exit 1 fi diff --git a/production.Dockerfile b/production.Dockerfile index 989723dc..72329875 100644 --- a/production.Dockerfile +++ b/production.Dockerfile @@ -78,6 +78,9 @@ USER rails:rails # Entrypoint prepares the database. ENTRYPOINT ["/rails/bin/docker-entrypoint-production"] +HEALTHCHECK --interval=5m --timeout=3s --start-period=30s \ + CMD curl -f http://localhost:3000/up || exit 1 + # Start the server by default, this can be overwritten at runtime EXPOSE 3000 CMD ["./bin/rails", "server"]