-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
32 lines (24 loc) · 764 Bytes
/
Dockerfile
File metadata and controls
32 lines (24 loc) · 764 Bytes
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
# Step 1: Build the application
FROM docker.io/library/node:20-alpine3.17 AS builder
RUN npm install -g pkg pkg-fetch
ENV NODE node18
ENV PLATFORM alpine
RUN /usr/local/bin/pkg-fetch ${NODE} ${PLATFORM} ${TARGETARCH}
# Run tests
WORKDIR /app
COPY . /app
RUN npm install
RUN npm test
# Build the application
RUN npm run build
# Package the result into a binary without dependencies
RUN /usr/local/bin/pkg --targets ${NODE}-${PLATFORM}-${TARGETARCH} -o server.bin dist/src/index.js
# Step 2: Create the runtime image
FROM docker.io/library/alpine:3.23
RUN apk add --no-cache libstdc++
COPY index /site/index
COPY --from=builder /app/server.bin /node/bin/server
EXPOSE 3000
# Don't run as root even in plain docker
USER 1001:0
ENTRYPOINT ["/node/bin/server"]