Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
70 lines (51 loc) 路 2.22 KB
/
Copy pathDockerfile
File metadata and controls
70 lines (51 loc) 路 2.22 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
# Stage 1 - build: Compiles the frontend and API code
FROM node:20.12.0-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files and install dependencies
COPY package.json package-lock.json ./
# Set NPM registry and config
RUN npm config set registry https://registry.npmmirror.com && \
npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 2000 && \
npm config set fetch-retry-maxtimeout 60000
# Install dependencies, with retry
RUN for i in 1 2 3; do npm ci --legacy-peer-deps && break || sleep 20; done
# Copy application source code
COPY . .
# Build the app
ENV NODE_OPTIONS="--max-old-space-size=8192"
ENV DL_ENV_TYPE="selfHosted"
RUN npm run build
# Stage 2 - run: Alpine-based runtime to serve the app
FROM node:20.12.0-alpine AS runner
# Install PostgreSQL client to run pg_isready and psql, plus wget for healthchecks
RUN apk add --no-cache postgresql-client whois wget
# Create non-root app user
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
# Set working directory
WORKDIR /app
# Copy required build artifacts and scripts
COPY --chown=appuser:appgroup --from=builder /app/dist ./dist
COPY --chown=appuser:appgroup --from=builder /app/package.json ./package.json
COPY --chown=appuser:appgroup --from=builder /app/db/schema.sql ./schema.sql
COPY --chown=appuser:appgroup --from=builder /app/start.sh ./start.sh
# Install only production dependencies
RUN npm config set registry https://registry.npmmirror.com && \
npm config set fetch-retries 5 && \
npm config set fetch-retry-mintimeout 2000 && \
npm config set fetch-retry-maxtimeout 60000 && \
for i in 1 2 3; do npm install --omit=dev --legacy-peer-deps && break || sleep 20; done
# Switch to the app user
USER appuser
# Expose application port
EXPOSE 3000
# Set environment variables
ENV DL_ENV_TYPE="selfHosted"
# Healthcheck
HEALTHCHECK --interval=15s --timeout=2s --start-period=5s --retries=5 \
CMD wget --spider -q http://localhost:3000/api/health || exit 1
# Run the start script to init the database and start the app server
CMD ["./start.sh"]
# The app can actually just be started with: node ./dist/analog/server/index.mjs
# However, we need the init script to wait for the DB and initialize the schema