forked from CISC375/Sage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (62 loc) · 2.66 KB
/
Dockerfile
File metadata and controls
83 lines (62 loc) · 2.66 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
# syntax=docker/dockerfile:1
# Define the Node version
ARG NODE_VERSION=20.18.3
# ─────────────────────────────────────────────────────────────
# Base image with Node and build tools
FROM node:${NODE_VERSION}-alpine AS base
# Set working directory
WORKDIR /usr/src/app
# Install system dependencies for building native modules
RUN apk add --no-cache \
python3 \
make \
g++ \
pixman-dev \
cairo-dev \
pango-dev \
giflib-dev \
jpeg-dev
# ─────────────────────────────────────────────────────────────
# Dependencies stage (production)
FROM base AS deps
# Copy package files and install-deps.js first for better caching
COPY package.json package-lock.json install-deps.js ./
# Create binding.gyp file required by some native modules
RUN printf '{\n "targets": [\n {\n "target_name": "sage",\n "sources": ["src/sage.ts"]\n }\n ]\n}\n' > binding.gyp
# Install production dependencies
RUN npm ci --omit=dev
# ─────────────────────────────────────────────────────────────
# Build stage (development + build)
FROM deps AS build
# Install all dependencies including devDeps for build
RUN npm ci
# Copy the rest of the source code into the container
COPY . .
# Ensure config.ts exists (fallback to example in CI/containers)
RUN test -f config.ts || cp config.example.ts config.ts
# Build the project
RUN npm run build
# Also include package.json in dist for module-alias '@root/package.json' resolution
RUN cp package.json dist/package.json
# ─────────────────────────────────────────────────────────────
# Final runtime stage (minimal image)
FROM base AS final
ENV NODE_ENV=production
# Install only runtime libraries needed by canvas
RUN apk add --no-cache \
cairo \
jpeg \
pango \
giflib
# Run the application as a non-root user
USER node
# Copy necessary files from previous stages
COPY --from=build /usr/src/app/package.json ./package.json
COPY --from=build /usr/src/app/package-lock.json ./package-lock.json
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist
COPY --from=build /usr/src/app/assets ./assets
# Expose the application port
EXPOSE 8080
# Run the application
CMD ["node", "dist/src/sage.js"]