-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
80 lines (60 loc) · 2.57 KB
/
Copy pathDockerfile
File metadata and controls
80 lines (60 loc) · 2.57 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
# Multi-stage Dockerfile for Allegro Component Library
# Builds both frontend and backend in a single container
# Stage 1: Build Frontend
FROM node:25-alpine AS frontend-builder
# Accept build arguments for environment variables
ARG VITE_CONFIG_ECO=false
# Copy root package.json for version info (needed by vite.config.js)
WORKDIR /app
COPY package.json ./
# Copy all client source code
WORKDIR /app/client
COPY client/package.json client/package-lock.json ./
RUN npm ci --prefer-offline --no-audit
COPY client/ .
# Replace placeholder with actual build argument value in .env.production
RUN sed -i "s/__VITE_CONFIG_ECO__/${VITE_CONFIG_ECO}/g" .env.production
# Build the React app with the substituted environment variables
RUN npm run build
# Stage 2: Build Backend and Final Image
FROM node:25-alpine
WORKDIR /app
COPY database/ ./database/
COPY library/template/ ./template-defaults/
# Install bash for our startup script and nginx for frontend
RUN apk add --no-cache bash nginx wget
# Copy backend source code
WORKDIR /app/server
COPY server/package.json server/package-lock.json ./
RUN npm ci --omit=dev --prefer-offline --no-audit
COPY server/ .
# Copy built frontend to nginx html directory
COPY --from=frontend-builder /app/client/dist /usr/share/nginx/html
# Configure nginx for non-root execution
COPY docker/nginx.conf /etc/nginx/nginx.conf
# Create directories for CAD file library and templates
RUN mkdir -p /app/library/footprint /app/library/symbol /app/library/pad /app/library/pspice \
/app/library/template/CIS /app/library/template/label \
/app/image
# Prepare nginx directories for non-root execution
RUN mkdir -p /var/lib/nginx/logs /run/nginx \
/tmp/nginx/client_body /tmp/nginx/proxy /tmp/nginx/fastcgi \
/tmp/nginx/uwsgi /tmp/nginx/scgi && \
chown -R 1000:1000 /var/lib/nginx /var/log/nginx /run/nginx \
/usr/share/nginx/html /app /tmp/nginx && \
chmod -R 1777 /tmp/nginx
# Copy startup script
COPY start.sh /app/start.sh
COPY docker/repair /usr/local/bin/repair
RUN chmod +x /app/start.sh /usr/local/bin/repair
# Production environment variables (can be overridden at runtime)
ENV NODE_ENV=production \
PORT=3500
# Expose only port 80 (nginx handles both frontend and API proxy)
EXPOSE 80
# Set working directory back to /app
WORKDIR /app
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s \
CMD wget --quiet --tries=1 --spider http://localhost/health || exit 1
# Use our startup script as entrypoint
ENTRYPOINT ["/app/start.sh"]