Files
immich-magic-proxy/Dockerfile.upload
T
2026-10-07 20:33:45 +13:00

61 lines
2.7 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=upload-app
COPY --chown=node:node shared/ shared/
COPY --chown=node:node upload-app/ upload-app/
RUN npm run build --workspace=shared --workspace=upload-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 the upload app at /app, and IPP
# has no place in this image.
RUN rm -rf node_modules \
&& npm ci --workspace=upload-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/upload-app/dist/tsconfig.tsbuildinfo
FROM node:lts-alpine AS runner
RUN apk --no-cache add curl tini
# At /app, as IPP, so a config.json mounts at the same path in both images
WORKDIR /app
COPY --from=builder --chown=root:root /ipp/upload-app/package.json ./
COPY --from=builder --chown=root:root /ipp/prod_modules ./node_modules
COPY --from=builder --chown=root:root /ipp/upload-app/dist ./dist
COPY --from=builder --chown=root:root /ipp/upload-app/public ./public
COPY --from=builder --chown=root:root /ipp/upload-app/config.json ./
# The code is root-owned and the app runs as node, so a compromised process
# cannot rewrite it; nothing writes to disk at runtime. The explicit --chown
# is for buildah, which keeps the builder's owner on COPY --from.
USER node
ARG PACKAGE_VERSION
ENV APP_VERSION=${PACKAGE_VERSION}
ENV NODE_ENV=production
# 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" ]