Skip to content

Commit

Permalink
docker: Add healthcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Woomymy <woomy@woomy.be>
  • Loading branch information
Woomymy committed Feb 5, 2023
1 parent 6104667 commit 4bb316b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ COPY ./src ./src
COPY ./prisma ./prisma
COPY ./*.json ./
COPY ./docker/entrypoint.sh ./
COPY ./docker/healthcheck.sh ./

RUN npm install
RUN npx tsc
Expand All @@ -13,7 +14,7 @@ RUN npx prisma generate
FROM node:18-alpine3.17 as prod
WORKDIR /usr/src/bot
RUN apk update && \
apk add --no-cache postgresql
apk add --no-cache postgresql curl
RUN adduser -D -H bot bot

COPY --from=build --chown=bot:bot /app/bot/package.json ./package.json
Expand All @@ -25,8 +26,12 @@ COPY --from=build --chown=bot:bot /app/bot/prisma ./prisma
COPY --from=build --chown=bot:bot /app/bot/node_modules/@prisma/client/ ./node_modules/@prisma/client/
COPY --from=build --chown=bot:bot /app/bot/node_modules/.prisma/client/ ./node_modules/.prisma/client/
COPY --from=build --chown=bot:bot /app/bot/entrypoint.sh ./
COPY --from=build --chown=bot:bot /app/bot/healthcheck.sh ./

USER bot

ENV NODE_ENV production

HEALTHCHECK --interval=1m --timeout=10s --start-period=5s --retries=3 \
CMD [ "/usr/src/bot/healthcheck.sh" ]
ENTRYPOINT [ "/usr/src/bot/entrypoint.sh" ]
7 changes: 7 additions & 0 deletions docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
if test "$(curl http://localhost:${HEALTHCHECK_PORT})" == "ok"
then
exit 0
else
exit 1
fi

0 comments on commit 4bb316b

Please # to comment.