2024-11-05 16:41:00 +00:00
|
|
|
# Build stage
|
2025-02-14 02:12:50 +00:00
|
|
|
FROM node:22.14.0-alpine AS builder
|
2024-08-19 22:24:13 +00:00
|
|
|
|
build(Docker): simplify Docker alpine build and runtime stage
same changes as for the "non-alpine" Dockerfile previously commited, but adapted to Alpine.
this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities.
Build Stage:
* do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally
* build into a "build" subfolder, for easier clean up during build stage
* get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist`
* no `npm prune` needed here, as we delete the whole build folder anyways in the last build step
Runtime stage:
* move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies
* move to `npm ci` for reproducible installations – but only installing runtime deps here
* get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
2025-03-05 07:48:49 +01: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
|
build(Docker): simplify Docker alpine build and runtime stage
same changes as for the "non-alpine" Dockerfile previously commited, but adapted to Alpine.
this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities.
Build Stage:
* do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally
* build into a "build" subfolder, for easier clean up during build stage
* get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist`
* no `npm prune` needed here, as we delete the whole build folder anyways in the last build step
Runtime stage:
* move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies
* move to `npm ci` for reproducible installations – but only installing runtime deps here
* get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
2025-03-05 07:48:49 +01:00
|
|
|
RUN npm ci && \
|
|
|
|
npm run build:prepare-dist && \
|
2024-11-05 16:41:00 +00:00
|
|
|
npm cache clean --force && \
|
build(Docker): simplify Docker alpine build and runtime stage
same changes as for the "non-alpine" Dockerfile previously commited, but adapted to Alpine.
this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities.
Build Stage:
* do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally
* build into a "build" subfolder, for easier clean up during build stage
* get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist`
* no `npm prune` needed here, as we delete the whole build folder anyways in the last build step
Runtime stage:
* move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies
* move to `npm ci` for reproducible installations – but only installing runtime deps here
* get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
2025-03-05 07:48:49 +01:00
|
|
|
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
|
2025-02-14 02:12:50 +00:00
|
|
|
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
|
|
|
|
|
build(Docker): simplify Docker alpine build and runtime stage
same changes as for the "non-alpine" Dockerfile previously commited, but adapted to Alpine.
this Dockerfile is aimed at production builds, i.e. trying to keep size as small as possible at the cost of "rebuild speed", due to missed docker cache opportunities.
Build Stage:
* do the complete build inside docker as oposed to the previous "hybrid", where tsc was run locally and the output got copied into the Docker build stage → you can now build this with Docker, without having to install the whole node/TS env locally
* build into a "build" subfolder, for easier clean up during build stage
* get rid of now unnecessary extra file/asset handling, as this is now handled by `npm run build:prepare-dist`
* no `npm prune` needed here, as we delete the whole build folder anyways in the last build step
Runtime stage:
* move the "electron" dep removal from the builder stage to the runtime stage, before installing the dependencies
* move to `npm ci` for reproducible installations – but only installing runtime deps here
* get rid of now unnecessary copying commands from the builder stage, as everything is now neatly available in "/usr/src/app"
2025-03-05 07:48:49 +01:00
|
|
|
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
|