-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
106 lines (82 loc) · 2.65 KB
/
Copy pathDockerfile.backend
File metadata and controls
106 lines (82 loc) · 2.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Production Backend Dockerfile for Antagents DB Tool
# Multi-stage build for optimized Node.js production image
# Base dependencies stage
FROM node:18-alpine AS base
WORKDIR /app
# Install system dependencies and configure pnpm
RUN apk add --no-cache \
libc6-compat \
git \
curl \
python3 \
make \
g++ \
&& corepack enable pnpm \
&& pnpm config set store-dir /root/.pnpm-store
# Copy workspace configuration
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
COPY turbo.json ./
# Dependencies stage
FROM base AS deps
# Copy package files for all workspaces
COPY apps/backend/package.json ./apps/backend/
COPY packages/*/package.json ./packages/*/
# Install dependencies
RUN pnpm install --frozen-lockfile --production=false
# Build stage
FROM base AS builder
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /root/.pnpm-store /root/.pnpm-store
# Copy source code
COPY . .
# Build packages first
RUN pnpm --filter @antagents/types build
RUN pnpm --filter @antagents/shared build
# Build backend
RUN pnpm --filter @antagents/backend build
# Production dependencies stage
FROM base AS prod-deps
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-workspace.yaml ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/apps/backend/package.json ./apps/backend/
COPY --from=builder /app/packages/*/package.json ./packages/*/
# Install only production dependencies
RUN pnpm install --frozen-lockfile --production=true
# Production stage
FROM node:18-alpine AS runner
WORKDIR /app
# Create non-root user
RUN addgroup --system --gid 1001 backend \
&& adduser --system --uid 1001 backend
# Install runtime dependencies
RUN apk add --no-cache \
dumb-init \
curl \
postgresql-client
# Copy production dependencies
COPY --from=prod-deps /app/node_modules ./node_modules
COPY --from=prod-deps /app/packages ./packages
# Copy built application
COPY --from=builder /app/apps/backend/dist ./dist
COPY --from=builder /app/apps/backend/package.json ./
# Copy database migrations and seeds
COPY --from=builder /app/apps/backend/migrations ./migrations
COPY --from=builder /app/apps/backend/seeders ./seeders
# Copy configuration files
COPY --from=builder /app/config ./config
# Set ownership
RUN chown -R backend:backend /app
# Switch to non-root user
USER backend
# Expose port
EXPOSE 8000
# Set environment variables
ENV NODE_ENV=production
ENV PORT=8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# Start application with dumb-init
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "dist/index.js"]