File size: 1,220 Bytes
97dab2a
 
 
0964a6d
 
 
 
97dab2a
 
 
f8a3d63
 
 
 
 
0964a6d
 
97dab2a
4a1661d
f8a3d63
ca41e99
0964a6d
f8a3d63
97dab2a
0964a6d
 
4a1661d
f8a3d63
 
4a1661d
f8a3d63
 
 
 
 
 
 
 
 
 
 
 
 
 
97dab2a
0964a6d
97dab2a
f8a3d63
 
 
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
# Use an official Node.js runtime as a parent image
FROM node:20-alpine AS builder

# Create app directory and set permissions
RUN mkdir -p /app /app/logs && \
    chown -R node:node /app

# Set working directory
WORKDIR /app

# Copy package files first for better caching
COPY --chown=node:node package*.json ./
COPY --chown=node:node ./apps/apigateway/package*.json ./apps/apigateway/
COPY --chown=node:node ./libs/proto ./libs/proto

# Switch to non-root user
USER node

# Install dependencies
RUN npm ci

# Copy the rest of the app's source code
COPY --chown=node:node . .

# Build the NestJS app
RUN npm run build:apigateway

# Create production image
FROM node:20-alpine

# Create app directory and set permissions
RUN mkdir -p /app /app/logs && \
    chown -R node:node /app

WORKDIR /app

# Copy built files from builder
COPY --from=builder --chown=node:node /app/dist ./dist
COPY --from=builder --chown=node:node /app/libs/proto ./libs/proto
COPY --from=builder --chown=node:node /app/package*.json ./
COPY --from=builder --chown=node:node /app/node_modules ./node_modules

# Switch to non-root user
USER node

# Expose app port
EXPOSE 8080

# Start the application
CMD ["node", "dist/apps/apigateway/main.js"]