Skip to content

Commit 7c63d45

Browse files
committed
[add] Health Check service in Docker Compose
[optimize] reduce Docker image size
1 parent a8c4f95 commit 7c63d45

File tree

2 files changed

+54
-36
lines changed

2 files changed

+54
-36
lines changed

Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
FROM node:18-slim
1+
# Reference: https://pnpm.io/docker#example-1-build-a-bundle-in-a-docker-container
22

3-
USER root
3+
FROM node:18-slim AS base
4+
RUN apt-get update && \
5+
apt-get install curl -y --no-install-recommends
6+
COPY . /app
7+
WORKDIR /app
48

5-
RUN npm rm yarn -g
9+
FROM base AS prod-deps
10+
RUN npm i --prod
611

7-
RUN mkdir /home/node/app
8-
WORKDIR /home/node/app
9-
10-
COPY package.json package-lock.json file-content-injector.js /home/node/app/
12+
FROM base AS build
1113
RUN npm i
12-
13-
COPY . /home/node/app
1414
RUN npm run build
1515

16-
RUN npm prune --production || true \
17-
npm cache clean -f
18-
16+
FROM base
17+
COPY --from=prod-deps /app/node_modules /app/node_modules
18+
COPY --from=build /app/dist /app/dist
1919
EXPOSE 3000
2020
CMD ["npm", "start"]

docker-compose.yml

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '3'
1+
version: "3"
22

33
volumes:
44
polyfill-cache:
@@ -12,28 +12,46 @@ volumes:
1212
secret-key: ${SECRET_KEY}
1313

1414
networks:
15-
polyfiller:
15+
polyfiller:
1616

1717
services:
18-
api-service:
19-
image: polyfiller/api-service
20-
environment:
21-
- NODE_ENV=production
22-
ports:
23-
- 3000:3000
24-
volumes:
25-
- polyfill-cache:/tmp/@wessberg/polyfiller
26-
networks:
27-
- polyfiller
28-
restart: always
29-
caddy:
30-
depends_on:
31-
- api-service
32-
image: caddy
33-
ports:
34-
- 80:80
35-
- 443:443
36-
networks:
37-
- polyfiller
38-
restart: always
39-
command: caddy reverse-proxy --from polyfiller.app --to api-service:3000
18+
api-service:
19+
image: polyfiller/api-service
20+
environment:
21+
- NODE_ENV=production
22+
ports:
23+
- 3000:3000
24+
volumes:
25+
- polyfill-cache:/tmp/@wessberg/polyfiller
26+
networks:
27+
- polyfiller
28+
healthcheck:
29+
test: ["CMD-SHELL", "curl -f http://localhost:1337/ || exit 1"]
30+
interval: 3s
31+
retries: 5
32+
start_period: 30s
33+
labels:
34+
- autoheal=true
35+
restart: always
36+
logging:
37+
driver: json-file
38+
options:
39+
max-size: 10m
40+
41+
autoheal:
42+
image: willfarrell/autoheal:1.2.0
43+
volumes:
44+
- /var/run/docker.sock:/var/run/docker.sock
45+
restart: always
46+
47+
caddy:
48+
depends_on:
49+
- api-service
50+
image: caddy
51+
ports:
52+
- 80:80
53+
- 443:443
54+
networks:
55+
- polyfiller
56+
restart: always
57+
command: caddy reverse-proxy --from polyfiller.app --to api-service:3000

0 commit comments

Comments
 (0)