From f9706c9fb013030f3aa8115ee36e9ac1d940d017 Mon Sep 17 00:00:00 2001 From: SennayT Date: Wed, 15 Jul 2026 10:51:35 +0000 Subject: [PATCH] refactor: separate base image configuration into Dockerfile.base for improved build management --- apps/edr-freight-api/Dockerfile | 34 ++++------------------- apps/edr-freight-api/Dockerfile.base | 41 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 apps/edr-freight-api/Dockerfile.base diff --git a/apps/edr-freight-api/Dockerfile b/apps/edr-freight-api/Dockerfile index 5051d13d9..3c05c8a9f 100644 --- a/apps/edr-freight-api/Dockerfile +++ b/apps/edr-freight-api/Dockerfile @@ -1,34 +1,12 @@ # syntax=docker/dockerfile:1 # Build from monorepo root: docker build -f apps/edr-freight-api/Dockerfile . +# +# The base image (Node + Alpine Chromium/Puppeteer + pnpm) is built and pushed +# separately — see Dockerfile.base. Override the pinned tag at build time with +# --build-arg BASE_IMAGE=registry.license.aafda.gov.et/edr-public/freight-api-base: +ARG BASE_IMAGE=registry.license.aafda.gov.et/edr-public/freight-api-base:node24-alpine -FROM node:24.15.0-alpine AS base - -# Puppeteer ships a glibc Chrome that cannot run on Alpine; skip the ~150MB -# download at install time. The runner stage installs Alpine's system Chromium. -ENV PUPPETEER_SKIP_DOWNLOAD=true -# Chromium + fonts for Puppeteer PDF rendering (contract/invoice/receipt docs). -# Without these, Puppeteer fails to launch and the code degrades to an -# unformatted plain-text PDF fallback. Use Alpine's system Chromium (musl-built); -# the glibc Chrome that `puppeteer install` downloads cannot run on Alpine. -RUN apk add --no-cache \ - libc6-compat \ - chromium \ - nss \ - freetype \ - harfbuzz \ - ca-certificates \ - ttf-freefont \ - font-noto-cjk -ENV NODE_ENV=production -# Point Puppeteer at the system Chromium and skip its bundled download. -ENV PUPPETEER_SKIP_DOWNLOAD=true -ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser -# Store pnpm's content-addressable store under PNPM_HOME so the BuildKit -# `--mount=type=cache,target=/pnpm/store` cache actually persists deps across builds. -ENV PNPM_HOME="/pnpm" -ENV PATH="$PNPM_HOME:$PATH" -RUN corepack enable -WORKDIR /app +FROM ${BASE_IMAGE} AS base FROM base AS pruner COPY . . diff --git a/apps/edr-freight-api/Dockerfile.base b/apps/edr-freight-api/Dockerfile.base new file mode 100644 index 000000000..9459958a2 --- /dev/null +++ b/apps/edr-freight-api/Dockerfile.base @@ -0,0 +1,41 @@ +# syntax=docker/dockerfile:1 +# Base image for edr-freight-api — Node + Alpine Chromium/Puppeteer + pnpm. +# Built and pushed separately so app builds pull it from Harbor instead of +# reinstalling the ~system Chromium toolchain on every build. +# +# Build + push (from monorepo root): +# docker build -f apps/edr-freight-api/Dockerfile.base \ +# -t registry.license.aafda.gov.et/edr/freight-api-base:node24-alpine . +# docker push registry.license.aafda.gov.et/edr/freight-api-base:node24-alpine +# +# Bump the tag whenever Node, Chromium, or the apk set below changes, then +# update BASE_IMAGE in Dockerfile to match. + +FROM node:24.15.0-alpine + +# Puppeteer ships a glibc Chrome that cannot run on Alpine; skip the ~150MB +# download at install time. This stage installs Alpine's system Chromium. +ENV PUPPETEER_SKIP_DOWNLOAD=true +# Chromium + fonts for Puppeteer PDF rendering (contract/invoice/receipt docs). +# Without these, Puppeteer fails to launch and the code degrades to an +# unformatted plain-text PDF fallback. Use Alpine's system Chromium (musl-built); +# the glibc Chrome that `puppeteer install` downloads cannot run on Alpine. +RUN apk add --no-cache \ + libc6-compat \ + chromium \ + nss \ + freetype \ + harfbuzz \ + ca-certificates \ + ttf-freefont \ + font-noto-cjk +ENV NODE_ENV=production +# Point Puppeteer at the system Chromium and skip its bundled download. +ENV PUPPETEER_SKIP_DOWNLOAD=true +ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser +# Store pnpm's content-addressable store under PNPM_HOME so the BuildKit +# `--mount=type=cache,target=/pnpm/store` cache actually persists deps across builds. +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +RUN corepack enable +WORKDIR /app