Notes/Dockerfile

49 lines
1.4 KiB
Docker
Raw Normal View History

2024-11-02 23:19:00 +00:00
# Build stage
FROM node:22.14.0-bullseye-slim AS builder
2018-06-10 15:06:52 -04:00
WORKDIR /usr/src/app/build
2018-06-10 15:06:52 -04:00
2024-11-02 23:19:00 +00:00
# Copy only necessary files for build
COPY . .
2018-06-10 15:06:52 -04:00
2024-11-02 23:19:00 +00:00
# Build and cleanup in a single layer
RUN npm ci && \
npm run build:prepare-dist && \
2024-11-02 23:19:00 +00:00
npm cache clean --force && \
rm -rf build/node_modules && \
mv build/* \
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-11-02 23:19:00 +00:00
# Runtime stage
FROM node:22.14.0-bullseye-slim
2018-06-10 15:06:52 -04:00
WORKDIR /usr/src/app
2024-11-02 23:19:00 +00:00
# Install only runtime dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
gosu && \
rm -rf \
/var/lib/apt/lists/* \
/var/cache/apt/*
2024-11-02 23:19:00 +00:00
COPY --from=builder /usr/src/app ./
2020-11-15 20:51:47 +01:00
RUN sed -i "/electron/d" package.json && \
npm ci --omit=dev && \
node --experimental-strip-types ./bin/cleanupNodeModules.ts . --skip-prune-dev-deps && \
npm cache clean --force && \
rm -rf /tmp/node-compile-cache
2024-11-02 23:19:00 +00:00
# Configure container
2018-06-10 15:06:52 -04:00
EXPOSE 8080
CMD [ "./start-docker.sh" ]
2024-08-08 14:38:39 -07:00
HEALTHCHECK --start-period=10s CMD exec gosu node node docker_healthcheck.js