Skip to content

Commit c7f5640

Browse files
authored
Add healthcheck on the Docker container (#46)
* Add healthcheck * Small syntax fixes
1 parent e80e72e commit c7f5640

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:trixie-slim as prod
1+
FROM debian:trixie-slim AS prod
22

33
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
44

@@ -27,15 +27,18 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \
2727
fonts-noto-mono \
2828
fonts-sil-gentium-basic \
2929
fonts-recommended \
30+
curl \
3031
&& useradd -d /app python
3132
COPY . /app
33+
COPY ./healthcheck.sh /healthcheck.sh
3234
WORKDIR /app
3335
RUN chown python /app -R \
3436
&& pip install -r requirements.txt --break-system-packages
3537
USER python
38+
HEALTHCHECK --retries=5 CMD ["/healthcheck.sh"]
3639

3740

38-
From prod as dev
41+
FROM prod AS dev
3942
USER root
4043
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt,sharing=locked \
4144
--mount=type=cache,id=apt-lib,target=/var/lib/apt,sharing=locked \
@@ -52,5 +55,3 @@ RUN USER=python && \
5255
printf "user: $USER\ngroup: $GROUP\n" > /etc/fixuid/config.yml
5356

5457
ENTRYPOINT ["fixuid" ]
55-
56-

docker-compose.override.yml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3'
1+
---
22
services:
33
lo_api:
44
build:

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
services:
23
lo_api:
34
build:

healthcheck.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
HTTP_CODE=$(curl -qs -o /dev/null -w "%{http_code}" -X GET -H "secretkey: $SECRET_KEY" localhost:8000)
4+
RETURN_CODE=$?
5+
if [ "$RETURN_CODE" -eq 0 ]; then
6+
if [ "$HTTP_CODE" != 200 ]; then
7+
echo "Return code for localhost:8000 is not 200"
8+
exit 1
9+
fi
10+
else
11+
echo "Can't query localhost:8000 with curl"
12+
exit 1
13+
fi

0 commit comments

Comments
 (0)