Skip to content

Commit b857d8e

Browse files
committed
feat(docker): add multi-stage docker build
1 parent f7ddb64 commit b857d8e

File tree

6 files changed

+158
-52
lines changed

6 files changed

+158
-52
lines changed

apps/auth-service/Dockerfile

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM node:18-slim
1+
FROM node:18-slim AS base
2+
WORKDIR /app
3+
RUN npm install -g pnpm turbo
24

5+
# BUILDER
6+
FROM base AS builder
37
WORKDIR /app
8+
COPY . .
9+
RUN turbo prune --scope=auth-service --docker
410

5-
RUN npm install -g pnpm
11+
#INSTALLER
12+
FROM base AS installer
13+
WORKDIR /app
614

7-
ENV HUSKY=0
8-
ENV CI=true
9-
10-
COPY . .
15+
COPY --from=builder /app/out/json/ .
16+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
17+
18+
RUN pnpm install --frozen-lockfile
1119

20+
COPY --from=builder /app/out/full/ .
1221

13-
RUN pnpm install
22+
RUN pnpm turbo run build --filter=auth-service
1423

15-
RUN pnpm --filter ./apps/auth-service... exec tsc
24+
# RUNNER
25+
FROM node:18-slim AS runner
26+
WORKDIR /app
27+
28+
RUN apt-get update && apt-get install -y curl
29+
30+
ENV NODE_ENV=production
31+
32+
COPY --from=installer /app .
1633

1734
EXPOSE 4001
1835

19-
CMD ["pnpm","--filter","./apps/auth-service...","start"]
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
37+
CMD curl -f http://localhost:4001/api/health || exit 1
38+
39+
CMD ["node","apps/auth-service/dist/index.js"]

apps/clinical-service/Dockerfile

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM node:18-slim
1+
FROM node:18-slim AS base
2+
WORKDIR /app
3+
RUN npm install -g pnpm turbo
24

5+
# BUILDER
6+
FROM base AS builder
37
WORKDIR /app
8+
COPY . .
9+
RUN turbo prune --scope=clinical-service --docker
410

5-
RUN npm install -g pnpm
11+
# INSTALLER
12+
FROM base AS installer
13+
WORKDIR /app
614

7-
ENV HUSKY=0
8-
ENV CI=true
9-
10-
COPY . .
15+
COPY --from=builder /app/out/json/ .
16+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
17+
18+
RUN pnpm install --frozen-lockfile
19+
20+
COPY --from=builder /app/out/full/ .
21+
22+
RUN pnpm turbo run build --filter=clinical-service
23+
24+
# RUNNER
25+
FROM node:18-slim AS runner
26+
WORKDIR /app
27+
28+
RUN apt-get update && apt-get install -y curl
1129

30+
ENV NODE_ENV=production
1231

13-
RUN pnpm install
32+
COPY --from=installer /app .
1433

15-
RUN pnpm --filter ./apps/clinical-service... exec tsc
34+
EXPOSE 4004
1635

17-
EXPOSE 4003
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
37+
CMD curl -f http://localhost:4004/api/clinical/health-clinical || exit 1
1838

19-
CMD ["pnpm","--filter","./apps/clinical-service...","start"]
39+
CMD ["node","apps/clinical-service/dist/index.js"]

apps/patient-service/Dockerfile

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM node:18-slim
1+
FROM node:18-slim AS base
2+
WORKDIR /app
3+
RUN npm install -g pnpm turbo
24

5+
# BUILDER
6+
FROM base AS builder
37
WORKDIR /app
8+
COPY . .
9+
RUN turbo prune --scope=patient-service --docker
410

5-
RUN npm install -g pnpm
11+
# INSTALLER
12+
FROM base AS installer
13+
WORKDIR /app
614

7-
ENV HUSKY=0
8-
ENV CI=true
9-
10-
COPY . .
15+
COPY --from=builder /app/out/json/ .
16+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
17+
18+
RUN pnpm install --frozen-lockfile
1119

20+
COPY --from=builder /app/out/full/ .
1221

13-
RUN pnpm install
22+
RUN pnpm turbo run build --filter=patient-service
1423

15-
RUN pnpm --filter ./apps/patient-service... exec tsc
24+
# RUNNER
25+
FROM node:18-slim AS runner
26+
WORKDIR /app
27+
28+
RUN apt-get update && apt-get install -y curl
29+
30+
ENV NODE_ENV=production
31+
32+
COPY --from=installer /app .
1633

1734
EXPOSE 4002
1835

19-
CMD ["pnpm","--filter","./apps/patient-service...","start"]
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
37+
CMD curl -f http://localhost:4002/api/patient/health-patient || exit 1
38+
39+
CMD ["node","apps/patient-service/dist/index.js"]
Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM node:18-slim
1+
FROM node:18-slim AS base
2+
WORKDIR /app
3+
RUN npm install -g pnpm turbo
24

5+
# BUILDER
6+
FROM base AS builder
37
WORKDIR /app
8+
COPY . .
9+
RUN turbo prune --scope=report-analytics-service --docker
410

5-
RUN npm install -g pnpm
11+
# INSTALLER
12+
FROM base AS installer
13+
WORKDIR /app
614

7-
ENV HUSKY=0
8-
ENV CI=true
9-
10-
COPY . .
15+
COPY --from=builder /app/out/json/ .
16+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
17+
18+
RUN pnpm install --frozen-lockfile
19+
20+
COPY --from=builder /app/out/full/ .
21+
22+
RUN pnpm turbo run build --filter=report-analytics-service
23+
24+
# RUNNER
25+
FROM node:18-slim AS runner
26+
WORKDIR /app
27+
28+
RUN apt-get update && apt-get install -y curl
1129

30+
ENV NODE_ENV=production
1231

13-
RUN pnpm install
32+
COPY --from=installer /app .
1433

15-
RUN pnpm --filter ./apps/report-analytics-service... exec tsc
34+
EXPOSE 4002
1635

17-
EXPOSE 4006
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
37+
CMD curl -f http://localhost:4006/api/reports-analytics/health-report || exit 1
1838

19-
CMD ["pnpm","--filter","./apps/report-analytics-service...","start"]
39+
CMD ["node","apps/report-analytics-service/dist/index.js"]

apps/web-app/Dockerfile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
1+
# BUILD STAGE
22
FROM node:18-slim AS builder
33

44
WORKDIR /app
5+
56
RUN npm install -g pnpm
6-
ENV CI=true
77

88
COPY . .
9+
910
RUN pnpm install
11+
1012
RUN pnpm --filter web-app build
1113

14+
# NGINX STAGE
1215
FROM nginx:alpine
1316

14-
COPY --from=builder /app/apps/web-app/dist /usr/share/nginx/html
17+
RUN apk add --no-cache curl
18+
19+
COPY apps/web-app/dist /usr/share/nginx/html
1520
COPY infra/nginx/default.conf /etc/nginx/conf.d/default.conf
16-
21+
1722
EXPOSE 80
1823

19-
CMD ["nginx","-g", "daemon off;"]
24+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
25+
CMD curl -f http://localhost/ || exit 1

apps/worker-service/Dockerfile

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM node:18-slim
1+
FROM node:18-slim AS base
2+
WORKDIR /app
3+
RUN npm install -g pnpm turbo
24

5+
#BUILDER
6+
FROM base AS builder
37
WORKDIR /app
8+
COPY . .
9+
RUN turbo prune --scope=worker-service --docker
410

5-
RUN npm install -g pnpm
11+
# INSTALLER
12+
FROM base AS installer
13+
WORKDIR /app
614

7-
ENV HUSKY=0
8-
ENV CI=true
9-
10-
COPY . .
15+
COPY --from=builder /app/out/json/ .
16+
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
17+
18+
RUN pnpm install --frozen-lockfile
1119

20+
COPY --from=builder /app/out/full/ .
1221

13-
RUN pnpm install
22+
RUN pnpm turbo run build --filter=worker-service
1423

15-
RUN pnpm --filter ./apps/worker-service... exec tsc
24+
# RUNNER
25+
FROM node:18-slim AS runner
26+
WORKDIR /app
27+
28+
RUN apt-get update && apt-get install -y curl
29+
30+
ENV NODE_ENV=production
31+
32+
COPY --from=installer /app .
1633

1734
EXPOSE 4005
1835

19-
CMD ["pnpm","--filter","./apps/worker-service...","start"]
36+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
37+
CMD curl -f http://localhost:4005/api/worker/health-worker || exit 1
38+
39+
CMD ["node","apps/worker-service/dist/worker.js"]

0 commit comments

Comments
 (0)