perf(ci): speed up image builds and centralize cache writes

- Image builds:
  - pin frontend and backend Docker build stages to the build platform so multi-arch packaging can reuse architecture-independent work
  - add an Angular build cache mount and move dynamic version metadata to the end of the runtime stage so static layers stay reusable across tags
  - reduce image workflow checkout depth and keep preview builds on `linux/amd64` only to avoid unnecessary QEMU and history overhead

- Cache policy:
  - make CI packaging smoke builds consume the shared image cache without writing new BuildKit cache state
  - make normal preview builds consume shared GHA and registry caches without mutating the canonical cache
  - keep nightly and stable release builds as the workflows that refresh the shared image cache in both GHA and registry backends

- Preview override:
  - add a `refresh_shared_cache` input to the preview workflow for an explicit no-cache rebuild that repopulates the shared cache when maintainers need to bust and refresh it
  - keep the default preview behavior optimized for fast disposable builds rather than cache churn

- Validation:
  - keep workflow YAML parsing clean after the cache-policy changes
  - keep `git diff --check` clean for the touched Docker and workflow files
This commit is contained in:
James Cox
2026-03-20 15:51:42 -05:00
parent 9373b50b5b
commit d148a097c6
5 changed files with 50 additions and 30 deletions
+15 -14
View File
@@ -1,4 +1,4 @@
FROM node:24-alpine AS frontend-build
FROM --platform=$BUILDPLATFORM node:24-alpine AS frontend-build
WORKDIR /workspace/booklore-ui
@@ -7,9 +7,10 @@ RUN --mount=type=cache,target=/root/.npm \
npm ci --no-audit --no-fund
COPY booklore-ui/ ./
RUN npm run build --configuration=production
RUN --mount=type=cache,target=/workspace/booklore-ui/.angular/cache \
npm run build --configuration=production
FROM gradle:9.3.1-jdk25-alpine AS backend-build
FROM --platform=$BUILDPLATFORM gradle:9.3.1-jdk25-alpine AS backend-build
WORKDIR /workspace/booklore-api
@@ -36,6 +37,17 @@ RUN set -eux; \
FROM linuxserver/unrar:7.1.10 AS unrar-layer
FROM eclipse-temurin:25-jre-alpine
ENV JAVA_TOOL_OPTIONS="-XX:+UseG1GC -XX:+UseCompactObjectHeaders -XX:+UseStringDeduplication -XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError"
RUN apk add --no-cache su-exec libstdc++ libgcc && \
mkdir -p /bookdrop
COPY packaging/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY --from=unrar-layer /usr/bin/unrar-alpine /usr/local/bin/unrar
COPY --from=backend-build /workspace/booklore-api/app.jar /app/app.jar
ARG APP_VERSION=development
ARG APP_REVISION=unknown
@@ -50,20 +62,9 @@ LABEL org.opencontainers.image.title="Grimmory" \
org.opencontainers.image.licenses="AGPL-3.0" \
org.opencontainers.image.base.name="docker.io/library/eclipse-temurin:25-jre-alpine"
ENV JAVA_TOOL_OPTIONS="-XX:+UseG1GC -XX:+UseCompactObjectHeaders -XX:+UseStringDeduplication -XX:MaxRAMPercentage=75.0 -XX:+ExitOnOutOfMemoryError"
ENV APP_VERSION=${APP_VERSION} \
APP_REVISION=${APP_REVISION}
RUN apk update && apk add --no-cache su-exec libstdc++ libgcc && \
mkdir -p /bookdrop
COPY packaging/docker/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
COPY --from=unrar-layer /usr/bin/unrar-alpine /usr/local/bin/unrar
COPY --from=backend-build /workspace/booklore-api/app.jar /app/app.jar
ARG BOOKLORE_PORT=6060
EXPOSE ${BOOKLORE_PORT}