mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-05-21 13:38:26 -05:00
c68b0b02e4
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"
56 lines
1.3 KiB
Docker
56 lines
1.3 KiB
Docker
# Build stage
|
|
FROM node:22.14.0-bullseye-slim AS builder
|
|
|
|
# Configure build dependencies in a single layer
|
|
# TriliumNextTODO: These don't seem to be required at all
|
|
# RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
# autoconf \
|
|
# automake \
|
|
# g++ \
|
|
# gcc \
|
|
# libtool \
|
|
# make \
|
|
# nasm \
|
|
# libpng-dev \
|
|
# python3 \
|
|
# && rm -rf /var/lib/apt/lists/*
|
|
|
|
WORKDIR /usr/src/app/build
|
|
|
|
# Copy only necessary files for build
|
|
COPY . .
|
|
|
|
# Build and cleanup in a single layer
|
|
RUN npm ci && \
|
|
npm run build:prepare-dist && \
|
|
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
|
|
|
|
# Runtime stage
|
|
FROM node:22.14.0-bullseye-slim
|
|
|
|
WORKDIR /usr/src/app
|
|
|
|
# Install only runtime dependencies
|
|
RUN apt-get update && \
|
|
apt-get install -y --no-install-recommends \
|
|
gosu && \
|
|
rm -rf /var/lib/apt/lists/* && \
|
|
rm -rf /var/cache/apt/*
|
|
|
|
COPY --from=builder /usr/src/app ./
|
|
|
|
RUN sed -i "/electron/d" package.json && \
|
|
npm ci --omit=dev && \
|
|
npm cache clean --force
|
|
|
|
# Configure container
|
|
EXPOSE 8080
|
|
CMD [ "./start-docker.sh" ]
|
|
HEALTHCHECK --start-period=10s CMD exec gosu node node docker_healthcheck.js |