-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (39 loc) · 1.94 KB
/
Copy pathDockerfile
File metadata and controls
59 lines (39 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ── Build stage ──────────────────────────────────────────────────────────
FROM node:22-alpine AS builder
WORKDIR /build
COPY package.json yarn.lock .yarnrc.yml ./
RUN corepack enable && yarn install --immutable
COPY tsconfig.json ./
COPY src ./src
RUN yarn build
# ── Dev stage (docker compose target) ────────────────────────────────────
# Includes dev dependencies so `tsx watch` and other dev tooling work.
FROM builder AS dev
WORKDIR /app
COPY --from=builder /build/node_modules ./node_modules
COPY --from=builder /build/dist ./dist
COPY --from=builder /build/package.json ./
EXPOSE 8000
CMD ["yarn", "tsx", "watch", "src/main.ts"]
# ── Production stage ─────────────────────────────────────────────────────
# Install only production dependencies so the image is lean.
FROM node:22-alpine AS prod-builder
WORKDIR /build
COPY package.json yarn.lock .yarnrc.yml ./
ENV NODE_ENV=production
RUN corepack enable && yarn install --immutable
COPY --from=builder /build/dist ./dist
FROM node:22-alpine
ENV NODE_ENV=production \
PORT=8000
WORKDIR /app
RUN addgroup -S app && adduser -S app -G app
COPY --from=prod-builder /build/dist ./dist
COPY --from=prod-builder /build/node_modules ./node_modules
COPY --from=prod-builder /build/package.json ./
RUN chown -R app:app /app
USER app
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD ["node", "-e", "const http=require('node:http');const req=http.get('http://127.0.0.1:8000/health',res=>{res.resume();process.exit(res.statusCode===200?0:1)});req.on('error',()=>process.exit(1));req.setTimeout(4000,()=>{req.destroy();process.exit(1)});"]
CMD ["node", "dist/main.js"]