Notes/Dockerfile.alpine

46 lines
1.2 KiB
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 && \
rm -rf dist/node_modules && \
mv dist/* \
start-docker.sh \
/usr/src/app/ && \
rm -rf \
/usr/src/app/build \
/tmp/node-compile-cache
#TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work
# currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down),
# as we install necessary dependencies in runtime buildstage anyways
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 && \
rm -rf /tmp/node-compile-cache
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