Skip to content

Commit

Permalink
feat(auditor): add health check to docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumDancer committed Apr 22, 2024
1 parent 5b8f0ea commit 2c5b6da
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- AUDITOR: Add benchmark to measure db performance (#736) ([@raghuvar-vijay](https://github.com/raghuvar-vijay))
- AUDITOR: Add health check to docker container ([@QuantumDancer](https://github.com/QuantumDancer))
- API: The health check (`GET /health_check`) now fails with an `500 INTERNAL SERVER ERROR` if no connection can be made to the database (#622) ([@QuantumDancer](https://github.com/QuantumDancer))
- CI: Add workflow for testing the pyaudtitor source distribution ([@dirksammel](https://github.com/dirksammel))
- CI: Add workflow for building the Rust documentation ([@dirksammel](https://github.com/dirksammel))
Expand Down
4 changes: 3 additions & 1 deletion containers/auditor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FROM debian:bookworm-slim AS runtime
WORKDIR /auditor

RUN apt-get update -y \
&& apt-get install -y --no-install-recommends openssl ca-certificates \
&& apt-get install -y --no-install-recommends openssl ca-certificates curl \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
Expand All @@ -35,8 +35,10 @@ COPY --from=builder /auditor/target/release/auditor auditor
COPY --from=builder /usr/local/cargo/bin/sqlx sqlx
COPY --from=builder /auditor/migrations migrations
COPY --from=builder /auditor/containers/auditor/entrypoint.sh entrypoint.sh
COPY --from=builder /auditor/containers/auditor/health_check.sh health_check.sh

COPY auditor/configuration configuration

ENV AUDITOR_ENVIRONMENT production
HEALTHCHECK --start-period=3s CMD [ "/auditor/health_check.sh" ]
ENTRYPOINT ["./entrypoint.sh"]
20 changes: 20 additions & 0 deletions containers/auditor/health_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

run_health_check() {
AUDITOR_APPLICATION__PORT="${AUDITOR_APPLICATION__PORT:=8000}"
curl "localhost:${AUDITOR_APPLICATION__PORT}/health_check" || exit 1
}


if [ $# -eq 0 ]; then
run_health_check
fi

command="$1"
shift

if [ "$command" = "auditor" ]; then
run_health_check
else
exit 0
fi

0 comments on commit 2c5b6da

Please sign in to comment.