66 lines
2.8 KiB
Docker
66 lines
2.8 KiB
Docker
# The builder runs on the build host's own architecture whatever the target.
|
|
# Every production dependency is pure JavaScript and the native tooling
|
|
# (esbuild, rolldown, lightningcss) is dev-only, so the install and compile
|
|
# never need emulation; only the small runner stage below is built per target.
|
|
FROM --platform=$BUILDPLATFORM node:lts-alpine AS builder
|
|
|
|
# /ipp must be node-owned for npm ci; WORKDIR leaves it root-owned on some builders
|
|
RUN mkdir /ipp && chown node:node /ipp
|
|
|
|
USER node
|
|
WORKDIR /ipp
|
|
|
|
# npm ci needs the manifest of every workspace in the root `workspaces` array
|
|
COPY --chown=node:node package.json package-lock.json ./
|
|
COPY --chown=node:node shared/package.json shared/
|
|
COPY --chown=node:node app/package.json app/
|
|
COPY --chown=node:node upload-app/package.json upload-app/
|
|
RUN npm ci --workspace=app
|
|
|
|
COPY --chown=node:node shared/ shared/
|
|
COPY --chown=node:node app/ app/
|
|
RUN npm run build --workspace=shared --workspace=app
|
|
|
|
# Production tree with @ipp/core dereferenced from its workspace symlink into a
|
|
# real folder (cp -L), so the runner's /app is self-contained. The apps'
|
|
# workspace links go first: the runner has IPP at /app, and the upload app
|
|
# has no place in this image.
|
|
RUN rm -rf node_modules \
|
|
&& npm ci --workspace=app --omit=dev \
|
|
&& rm -rf node_modules/immich-public-proxy node_modules/immich-public-proxy-upload node_modules/.bin/immich-public-proxy* \
|
|
&& cp -rL node_modules /ipp/prod_modules \
|
|
&& cd /ipp/prod_modules/@ipp/core \
|
|
&& rm -rf src tests tsconfig.json vitest.config.ts dist/tsconfig.tsbuildinfo \
|
|
&& rm -f /ipp/app/dist/tsconfig.tsbuildinfo
|
|
|
|
FROM node:lts-alpine AS runner
|
|
|
|
RUN apk --no-cache add curl tini
|
|
|
|
# IPP stays at /app so the documented mounts (/app/config.json,
|
|
# /app/dist/invalidRequestHandler.js) and the IPP_CONFIG default keep working
|
|
WORKDIR /app
|
|
COPY --from=builder --chown=root:root /ipp/app/package.json ./
|
|
COPY --from=builder --chown=root:root /ipp/prod_modules ./node_modules
|
|
COPY --from=builder --chown=root:root /ipp/app/dist ./dist
|
|
COPY --from=builder --chown=root:root /ipp/app/public ./public
|
|
COPY --from=builder --chown=root:root /ipp/app/config.json ./
|
|
|
|
# The code is root-owned and the app runs as node, so a compromised process
|
|
# cannot rewrite it. The only runtime writes are the SQLite database of
|
|
# recipients, sessions and comments, in the /data volume. The explicit --chown
|
|
# is for buildah, which keeps the builder's owner on COPY --from.
|
|
RUN mkdir /data && chown node:node /data
|
|
VOLUME /data
|
|
USER node
|
|
|
|
ARG PACKAGE_VERSION
|
|
ENV APP_VERSION=${PACKAGE_VERSION}
|
|
ENV NODE_ENV=production
|
|
ENV DATA_DIR=/data
|
|
|
|
# tini as PID 1 reaps orphaned healthcheck processes, which node does not (GitHub #66).
|
|
# -s keeps reaping, without a warning, when PID 1 is already an init (compose `init: true`).
|
|
ENTRYPOINT ["/sbin/tini", "-s", "--"]
|
|
CMD ["node", "dist/index.js" ]
|