@cryptotaxi247 / CoPilot / commits / 536db65c

Refactor Dockerfile to streamline build stages and improve dependency management

taylorwalton committed Nov 30, 2025 at 10:09 UTC 536db65c902312c672b4d8778f934e9fc2797e27
1 file changed +49 -21
customer_portal/Dockerfile
+49 -21
@@ -1,34 +1,62 @@
1 -# Build stage
2 -FROM node:20-alpine AS build
1 +# Use a node.js base image
2 +FROM node:21 as builder
3
4 +# Install pnpm globally
5 +RUN npm install -g pnpm
6 +
7 +# Drop root
8 +USER node
9 +
10 +# Set the working directory
11 WORKDIR /app
12
6 -# Copy package files
7 -COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
13 +# Copy the package.json and pnpm-lock.yaml files into the working directory
14 +COPY package.json pnpm-lock.yaml ./
15
9 -# Install pnpm
10 -RUN npm install -g pnpm
16 +# Install project dependencies using pnpm
17 +RUN pnpm install
18 +
19 +# Copy project files into the working directory
20 +COPY --chown=node . .
21 +
22 +# Run the Vue.js project build using pnpm
23 +RUN pnpm run build:only
24 +
25 +FROM node:21 as dev
26 +
27 +RUN apt-get update && apt-get install -y openssl
28 +
29 +RUN mkdir -p /certs & \
30 + openssl req -x509 -subj "/CN=localhost" -nodes -newkey rsa:4096 -keyout /certs/key.pem -out /certs/cert.pem -days 365 && \
31 + chown -R node:node /certs
32 +
33 +# Drop root
34 +USER node
35 +
36 +# Set the working directory
37 +WORKDIR /app
38
12 -# Install dependencies
13 -RUN pnpm install --frozen-lockfile
39 +CMD pnpm install && pnpm run start-frontend
40
15 -# Copy source files
16 -COPY . .
41 +FROM nginx:1.24.0-alpine
42
18 -# Build the application
19 -RUN pnpm run build
43 +# Added to create self-signed cert on run time if needed
44 +RUN apk add openssl
45
21 -# Production stage
22 -FROM nginx:alpine
46 +# Set environment variables
47 +ENV SERVER_HOST=localhost
48 +ENV TLS_CERT_PATH=/etc/nginx/certs.d/server.crt
49 +ENV TLS_KEY_PATH=/etc/nginx/certs.d/server.key
50
24 -# Copy custom nginx config
25 -COPY nginx.conf /etc/nginx/nginx.conf
51 +# Copy entrypoint
52 +COPY build/docker-entrypoint.d/90-copilot-ssl.sh /docker-entrypoint.d/90-copilot-ssl.sh
53 +RUN chmod +x /docker-entrypoint.d/90-copilot-ssl.sh
54
27 -# Copy built files from build stage
28 -COPY --from=build /app/dist /usr/share/nginx/html
55 +# Setup template
56 +RUN mkdir /etc/nginx/templates
57 +COPY build/etc/nginx/sites-enabled/default.conf /etc/nginx/templates/default.conf.template
58
30 -# Expose port 80
31 -EXPOSE 80
59 +# Copy built static files from the builder stage
60 +COPY --from=builder /app/dist /var/www/copilot
61
33 -# Start nginx
62 CMD ["nginx", "-g", "daemon off;"]