-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
94 lines (68 loc) · 2.52 KB
/
Copy pathDockerfile
File metadata and controls
94 lines (68 loc) · 2.52 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
# ================================
# Stage 1: Dependencies
# ================================
FROM node:20-alpine AS deps
# Install pnpm globally
RUN npm install -g pnpm
WORKDIR /app
# Copy package files and pnpm config
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# Use hoisted node_modules layout for Angular CLI builder resolution
RUN echo "node-linker=hoisted" > .npmrc && pnpm install
# ================================
# Stage 2: Development
# ================================
FROM node:20-alpine AS development
RUN npm install -g pnpm
WORKDIR /app
# Copy package files and pnpm config
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# Use hoisted layout so Angular CLI can resolve @ngx-env/builder
RUN echo "node-linker=hoisted" > .npmrc && pnpm install
# Copy all source files
COPY . .
# Expose Angular dev server port
EXPOSE 4200
# Start Angular dev server with hot reload
# --host 0.0.0.0 allows access from outside container
# --poll ensures file changes are detected in Docker
CMD ["pnpm", "exec", "ng", "serve", "--host", "0.0.0.0", "--poll", "2000"]
# ================================
# Stage 3: Builder
# ================================
FROM node:20-alpine AS builder
RUN npm install -g pnpm
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/.npmrc ./
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
# Copy source code
COPY . .
# Build the application for production
RUN pnpm build --configuration=production
# ================================
# Stage 4: Production
# ================================
FROM nginx:alpine AS production
# Remove default nginx static assets
RUN rm -rf /usr/share/nginx/html/*
# Copy custom nginx configuration
COPY nginx.conf /etc/nginx/nginx.conf
# Copy built application from builder stage
COPY --from=builder /app/dist/nirman/browser /usr/share/nginx/html
# Create non-root user for security
RUN addgroup --system --gid 1001 nginx-app && \
adduser --system --uid 1001 --ingroup nginx-app nginx-user && \
chown -R nginx-user:nginx-app /usr/share/nginx/html && \
chown -R nginx-user:nginx-app /var/cache/nginx && \
chown -R nginx-user:nginx-app /var/log/nginx && \
touch /var/run/nginx.pid && \
chown -R nginx-user:nginx-app /var/run/nginx.pid
# Expose port 80
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:80/ || exit 1
# Start nginx
CMD ["nginx", "-g", "daemon off;"]