Notes/Dockerfile.alpine

41 lines
895 B
Docker
Raw Normal View History

2024-11-05 16:41:00 +00:00
# Build stage
FROM node:22.14.0-alpine AS builder
2024-08-19 22:24:13 +00:00
WORKDIR /usr/src/app/build
2024-08-19 22:24:13 +00:00
2024-11-05 16:41:00 +00:00
# Copy only necessary files for build
2024-08-19 22:24:13 +00:00
COPY . .
2024-11-05 16:41:00 +00:00
# Build and cleanup in a single layer
RUN npm ci && \
npm run build:prepare-dist && \
2024-11-05 16:41:00 +00:00
npm cache clean --force && \
mv dist/* \
start-docker.sh \
package-lock.json \
/usr/src/app/ && \
rm -rf /usr/src/app/build
#TODO: move package-lock copying into copy-dist
2024-08-19 22:24:13 +00:00
2024-11-05 16:41:00 +00:00
# Runtime stage
FROM node:22.14.0-alpine
2024-08-19 22:24:13 +00:00
2024-11-05 16:41:00 +00:00
# Install runtime dependencies
2024-08-19 22:24:13 +00:00
RUN apk add --no-cache su-exec shadow
2024-11-05 16:41:00 +00:00
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app ./
RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
npm cache clean --force
2024-11-05 16:41:00 +00:00
# Add application user
2024-08-19 22:24:13 +00:00
RUN adduser -s /bin/false node; exit 0
2024-11-05 16:41:00 +00:00
# Configure container
2024-08-19 22:24:13 +00:00
EXPOSE 8080
CMD [ "./start-docker.sh" ]
2024-11-05 16:41:00 +00:00
HEALTHCHECK --start-period=10s CMD exec su-exec node node docker_healthcheck.js