-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathDockerfile
More file actions
65 lines (48 loc) · 1.66 KB
/
Copy pathDockerfile
File metadata and controls
65 lines (48 loc) · 1.66 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
60
61
62
63
64
65
# Z-Image API - Docker Configuration
#
# Build: docker build -t z-image-api .
# Run: docker run -p 8787:8787 z-image-api
#
# Multi-stage build for optimal image size
# === Build Stage ===
FROM node:20-alpine AS builder
# Install pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Copy workspace configuration
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY apps/api/package.json ./apps/api/
COPY packages/shared/package.json ./packages/shared/
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy source code
COPY packages/shared ./packages/shared
COPY apps/api ./apps/api
# Build shared package first, then API
RUN pnpm --filter @z-image/shared build
RUN pnpm --filter @z-image/api build
# === Production Stage ===
FROM node:20-alpine AS runner
# Install pnpm for production
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app
# Set production environment
ENV NODE_ENV=production
ENV PORT=8787
# Copy package files
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY apps/api/package.json ./apps/api/
COPY packages/shared/package.json ./packages/shared/
# Install production dependencies only
RUN pnpm install --frozen-lockfile --prod
# Copy built files
COPY --from=builder /app/packages/shared/dist ./packages/shared/dist
COPY --from=builder /app/apps/api/dist ./apps/api/dist
COPY --from=builder /app/apps/api/src ./apps/api/src
# Expose port
EXPOSE 8787
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8787/api/ || exit 1
# Run the server
CMD ["pnpm", "--filter", "@z-image/api", "start"]