-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (38 loc) · 1.31 KB
/
Dockerfile
File metadata and controls
51 lines (38 loc) · 1.31 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
# Multi-stage build for optimal image size
FROM node:lts-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat wget openssl
WORKDIR /app
# Build-time token for GitHub Packages — never stored in the final image
ARG NODE_AUTH_TOKEN
ENV NODE_AUTH_TOKEN=${NODE_AUTH_TOKEN}
# Copy package files
COPY .npmrc package.json yarn.lock* ./
# Install dependencies, then remove .npmrc so the token is not cached
RUN yarn --frozen-lockfile --production=false && rm -f .npmrc
# Build the source code
FROM base AS builder
RUN apk add --no-cache wget openssl
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build application
RUN yarn build
# Production image, copy all the files and run the app
FROM base AS runner
RUN apk add --no-cache wget openssl
WORKDIR /app
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nestjs
# Copy necessary files from builder stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/yarn.lock ./yarn.lock
# Copy node_modules from deps stage (production only)
COPY --from=deps /app/node_modules ./node_modules
# Change ownership to nestjs user
RUN chown -R nestjs:nodejs /app
USER nestjs
CMD ["yarn", "start"]