Skip to content

Commit

Permalink
[add] Health Check service in Docker Compose
Browse files Browse the repository at this point in the history
[optimize] reduce Docker image size
  • Loading branch information
TechQuery committed Nov 23, 2023
1 parent a8c4f95 commit b188437
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
24 changes: 12 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FROM node:18-slim
# Reference: https://pnpm.io/docker#example-1-build-a-bundle-in-a-docker-container

USER root
FROM node:18-slim AS base
RUN apt-get update && \
apt-get install curl -y --no-install-recommends
COPY . /app
WORKDIR /app

RUN npm rm yarn -g
FROM base AS prod-deps
RUN npm i --prod

RUN mkdir /home/node/app
WORKDIR /home/node/app

COPY package.json package-lock.json file-content-injector.js /home/node/app/
FROM base AS build
RUN npm i

COPY . /home/node/app
RUN npm run build

RUN npm prune --production || true \
npm cache clean -f

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/dist /app/dist
EXPOSE 3000
CMD ["npm", "start"]
66 changes: 42 additions & 24 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

volumes:
polyfill-cache:
Expand All @@ -12,28 +12,46 @@ volumes:
secret-key: ${SECRET_KEY}

networks:
polyfiller:
polyfiller:

services:
api-service:
image: polyfiller/api-service
environment:
- NODE_ENV=production
ports:
- 3000:3000
volumes:
- polyfill-cache:/tmp/@wessberg/polyfiller
networks:
- polyfiller
restart: always
caddy:
depends_on:
- api-service
image: caddy
ports:
- 80:80
- 443:443
networks:
- polyfiller
restart: always
command: caddy reverse-proxy --from polyfiller.app --to api-service:3000
api-service:
image: polyfiller/api-service
environment:
- NODE_ENV=production
ports:
- 3000:3000
volumes:
- polyfill-cache:/tmp/@wessberg/polyfiller
networks:
- polyfiller
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/ || exit 1"]
interval: 3s
retries: 5
start_period: 30s
labels:
- autoheal=true
restart: always
logging:
driver: json-file
options:
max-size: 10m

autoheal:
image: willfarrell/autoheal:1.2.0
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: always

caddy:
depends_on:
- api-service
image: caddy
ports:
- 80:80
- 443:443
networks:
- polyfiller
restart: always
command: caddy reverse-proxy --from polyfiller.app --to api-service:3000

0 comments on commit b188437

Please sign in to comment.