Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (58 loc) · 2.05 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (58 loc) · 2.05 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
# ---- Stage 1: Builder ----
# Use a Node.js image with build tools. Alpine is smaller.
FROM node:20-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy package files and install *all* dependencies (including dev)
# This leverages Docker layer caching
COPY package.json package-lock.json ./
RUN npm ci
# Copy the rest of the application source code
COPY . .
# Build both frontend and backend
RUN npm run build
# ---- Stage 2: Runtime ----
# Use a minimal Node.js Alpine image for the final stage
FROM node:20-alpine
# Set the working directory
WORKDIR /app
# Set NODE_ENV to production
ENV NODE_ENV=production
# Optional: Define the port, although the app reads it or defaults
# ENV PORT=3000
# Install dependencies required for Puppeteer in Alpine
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont \
nodejs \
yarn
# Set environment variables for Puppeteer to use the installed Chromium
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# Copy package files again
COPY package.json package-lock.json ./
# Install *only* production dependencies
RUN npm ci --omit=dev
# Copy the built application artifacts from the builder stage
# This includes dist/backend and dist/public
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/verify-puppeteer.js ./verify-puppeteer.js
# Verify Puppeteer is working correctly
RUN node verify-puppeteer.js
# Create directories for volumes if they don't exist (optional but safer)
# The application code might create these, but being explicit is good practice
# These directories will be mount points for volumes
RUN mkdir -p data uploads
# Optional but recommended: Run as a non-root user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
RUN chown -R appuser:appgroup /app
USER appuser
# Expose the port the application listens on
EXPOSE 3000
# The command to run the application using the container-specific script
CMD ["npm", "run", "start-container"]