Skip to content

Commit

Permalink
[Issue 591 healthcheck (#592)
Browse files Browse the repository at this point in the history
* curl and healthcheck support
  • Loading branch information
SammySteiner authored Oct 12, 2023
1 parent e949742 commit 8bb0c92
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ RUN poetry install --no-root --with dev

COPY . /api

COPY --from=ghcr.io/tarampampam/curl:8.1.1 /bin/curl /bin/curl

# Set the host to 0.0.0.0 to make the server available external
# to the Docker container that it's running in.
ENV HOST=0.0.0.0
Expand Down Expand Up @@ -98,6 +100,8 @@ RUN poetry install --no-root --only main
# or the application will not build
RUN poetry build --format wheel && poetry run pip install 'dist/grants_equity_api-0.1.0-py3-none-any.whl'

COPY --from=ghcr.io/tarampampam/curl:8.1.1 /bin/curl /bin/curl

# Add project's virtual env to the PATH so we can directly run poetry scripts
# defiend in pyproject.toml
ENV PATH="/api/.venv/bin:$PATH"
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ services:
restart: always
ports:
- 3000:3000
healthcheck:
# CMD-SHELL runs on the default shell client, ie /bin/sh
# CMD runs the command directly
test: ["CMD",
"curl",
"--fail",
"-sLo",
"/dev/null",
"-w",
"%{http_code}",
"http://localhost:3000/health"
]
interval: 60s
timeout: 5s
retries: 3
start_period: 20s


storybook:
container_name: storybook
Expand Down
4 changes: 4 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ COPY src ./src
COPY stories ./stories
COPY .storybook ./.storybook

COPY --from=ghcr.io/tarampampam/curl:8.1.1 /bin/curl /bin/curl

ENV NEXT_TELEMETRY_DISABLED 1

CMD ["npm", "run", "dev"]
Expand Down Expand Up @@ -86,6 +88,8 @@ RUN adduser --system --uid 1001 nextjs
RUN chown nextjs:nodejs /frontend/.next/cache/images/
USER nextjs

COPY --from=ghcr.io/tarampampam/curl:8.1.1 /bin/curl /bin/curl

COPY --from=builder /frontend/public ./public

# Automatically leverage output traces to reduce image size
Expand Down
10 changes: 8 additions & 2 deletions infra/modules/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,14 @@ resource "aws_ecs_task_definition" "app" {
interval = 30,
retries = 3,
timeout = 5,
command = ["CMD-SHELL",
"wget --no-verbose --tries=1 --spider http://localhost:${var.container_port}/health || exit 1"
command = ["CMD",
"curl",
"--fail",
"-sLo",
"/dev/null",
"-w",
"%%{http_code}",
"http://localhost:8000/health"
]
},
environment = local.environment_variables,
Expand Down

0 comments on commit 8bb0c92

Please sign in to comment.