Reduce image size by pruning stuff and things

Ref https://github.com/orgs/fosrl/discussions/2069
This commit is contained in:
Owen
2026-10-12 15:41:50 -04:00
parent 3d590493d6
commit 9afcd68d68
3 changed files with 112 additions and 18 deletions
+15 -17
View File
@@ -24,13 +24,19 @@ RUN if [ "$BUILD" = "oss" ]; then rm -rf server/private; fi && \
npm run build:cli && \
test -f dist/server.mjs
# Create placeholder files for MaxMind databases to avoid COPY errors
# Real files should be present for saas builds, placeholders for oss builds
RUN touch /app/GeoLite2-Country.mmdb /app/GeoLite2-ASN.mmdb
# Instead of shipping the full production node_modules (most of which is UI-only
# code already compiled into .next), copy only the files the server bundles can
# load, merged with the node_modules Next.js traced for its standalone server.
# Pruning first keeps dev dependencies out of the trace.
RUN npm prune --omit=dev && \
node trace-deps.mjs -o .next/standalone dist/server.mjs dist/migrations.mjs dist/cli.mjs
FROM base AS builder
RUN npm ci --omit=dev
# MaxMind databases are only shipped in saas builds
RUN mkdir -p maxmind && \
if [ "$BUILD" = "saas" ]; then \
touch GeoLite2-Country.mmdb GeoLite2-ASN.mmdb && \
mv GeoLite2-Country.mmdb GeoLite2-ASN.mmdb maxmind/; \
fi
# FROM node:24.18.1-slim AS runner
FROM public.ecr.aws/docker/library/node:24.18.1-slim AS runner
@@ -39,9 +45,6 @@ WORKDIR /app
RUN apt-get update && apt-get install -y curl tzdata && rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder-dev /app/.next/standalone ./
COPY --from=builder-dev /app/.next/static ./.next/static
COPY --from=builder-dev /app/dist ./dist
@@ -55,17 +58,12 @@ COPY server/db/ios_models.json ./dist/ios_models.json
COPY server/db/mac_models.json ./dist/mac_models.json
COPY public ./public
# Copy MaxMind databases for SaaS builds
# Copy MaxMind databases (empty directory for non-saas builds)
ARG BUILD=oss
RUN mkdir -p ./maxmind
COPY --from=builder-dev /app/maxmind ./maxmind
# Copy MaxMind databases (placeholders exist for oss builds, real files for saas)
COPY --from=builder-dev /app/GeoLite2-Country.mmdb ./maxmind/GeoLite2-Country.mmdb
COPY --from=builder-dev /app/GeoLite2-ASN.mmdb ./maxmind/GeoLite2-ASN.mmdb
# Remove MaxMind databases for non-saas builds (keep only for saas)
RUN if [ "$BUILD" != "saas" ]; then rm -rf ./maxmind; fi
RUN if [ "$BUILD" != "saas" ]; then rmdir ./maxmind; fi
# OCI Image Labels - Build Args for dynamic values
ARG VERSION="dev"