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:
@@ -59,5 +59,4 @@ jobs:
|
|||||||
build-args: |
|
build-args: |
|
||||||
APP_VERSION=ci-${{ github.sha }}
|
APP_VERSION=ci-${{ github.sha }}
|
||||||
APP_REVISION=${{ github.sha }}
|
APP_REVISION=${{ github.sha }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha,scope=image-shared
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
type: string
|
type: string
|
||||||
|
refresh_shared_cache:
|
||||||
|
description: 'Rebuild from scratch and refresh the shared image cache'
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
type: boolean
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
build-and-push:
|
||||||
@@ -26,7 +31,7 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 1
|
||||||
ref: ${{ inputs.ref }}
|
ref: ${{ inputs.ref }}
|
||||||
|
|
||||||
- name: Generate Preview Tag
|
- name: Generate Preview Tag
|
||||||
@@ -51,9 +56,6 @@ jobs:
|
|||||||
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
|
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
|
||||||
echo "Preview tag: $preview_tag"
|
echo "Preview tag: $preview_tag"
|
||||||
|
|
||||||
- name: Set Up QEMU for Multi-Arch Builds
|
|
||||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
|
|
||||||
|
|
||||||
- name: Set Up Docker Buildx
|
- name: Set Up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
||||||
|
|
||||||
@@ -65,11 +67,12 @@ jobs:
|
|||||||
password: ${{ github.token }}
|
password: ${{ github.token }}
|
||||||
|
|
||||||
- name: Build and push Preview image
|
- name: Build and push Preview image
|
||||||
|
if: ${{ !inputs.refresh_shared_cache }}
|
||||||
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: Dockerfile
|
file: Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/grimmory-tools/grimmory:${{ env.preview_tag }}
|
ghcr.io/grimmory-tools/grimmory:${{ env.preview_tag }}
|
||||||
@@ -77,6 +80,23 @@ jobs:
|
|||||||
APP_VERSION=${{ env.preview_tag }}
|
APP_VERSION=${{ env.preview_tag }}
|
||||||
APP_REVISION=${{ env.commit_sha }}
|
APP_REVISION=${{ env.commit_sha }}
|
||||||
cache-from: |
|
cache-from: |
|
||||||
type=gha
|
type=gha,scope=image-shared
|
||||||
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
|
- name: Build and push Preview image with cache refresh
|
||||||
|
if: ${{ inputs.refresh_shared_cache }}
|
||||||
|
uses: docker/build-push-action@d08e5c354a6adb9ed34480a06d141179aa583294 # v7.0.0
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
no-cache: true
|
||||||
|
tags: |
|
||||||
|
ghcr.io/grimmory-tools/grimmory:${{ env.preview_tag }}
|
||||||
|
build-args: |
|
||||||
|
APP_VERSION=${{ env.preview_tag }}
|
||||||
|
APP_REVISION=${{ env.commit_sha }}
|
||||||
|
cache-to: |
|
||||||
|
type=gha,scope=image-shared,mode=max
|
||||||
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 1
|
||||||
ref: develop
|
ref: develop
|
||||||
|
|
||||||
- name: Record Resolved Commit
|
- name: Record Resolved Commit
|
||||||
@@ -48,7 +48,7 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 1
|
||||||
ref: ${{ needs.resolve_ref.outputs.commit_sha }}
|
ref: ${{ needs.resolve_ref.outputs.commit_sha }}
|
||||||
|
|
||||||
- name: Generate Nightly Tag
|
- name: Generate Nightly Tag
|
||||||
@@ -95,8 +95,8 @@ jobs:
|
|||||||
APP_VERSION=${{ env.nightly_tag }}
|
APP_VERSION=${{ env.nightly_tag }}
|
||||||
APP_REVISION=${{ env.commit_sha }}
|
APP_REVISION=${{ env.commit_sha }}
|
||||||
cache-from: |
|
cache-from: |
|
||||||
type=gha
|
type=gha,scope=image-shared
|
||||||
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
||||||
cache-to: |
|
cache-to: |
|
||||||
type=gha,mode=max
|
type=gha,scope=image-shared,mode=max
|
||||||
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 1
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
- name: Record Release Tag and Commit
|
- name: Record Release Tag and Commit
|
||||||
@@ -63,10 +63,10 @@ jobs:
|
|||||||
APP_VERSION=${{ env.release_tag }}
|
APP_VERSION=${{ env.release_tag }}
|
||||||
APP_REVISION=${{ env.commit_sha }}
|
APP_REVISION=${{ env.commit_sha }}
|
||||||
cache-from: |
|
cache-from: |
|
||||||
type=gha
|
type=gha,scope=image-shared
|
||||||
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
|
||||||
cache-to: |
|
cache-to: |
|
||||||
type=gha,mode=max
|
type=gha,scope=image-shared,mode=max
|
||||||
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
|
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max
|
||||||
|
|
||||||
- name: Publish Draft GitHub Release
|
- name: Publish Draft GitHub Release
|
||||||
|
|||||||
+15
-14
@@ -1,4 +1,4 @@
|
|||||||
FROM node:24-alpine AS frontend-build
|
FROM --platform=$BUILDPLATFORM node:24-alpine AS frontend-build
|
||||||
|
|
||||||
WORKDIR /workspace/booklore-ui
|
WORKDIR /workspace/booklore-ui
|
||||||
|
|
||||||
@@ -7,9 +7,10 @@ RUN --mount=type=cache,target=/root/.npm \
|
|||||||
npm ci --no-audit --no-fund
|
npm ci --no-audit --no-fund
|
||||||
|
|
||||||
COPY booklore-ui/ ./
|
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
|
WORKDIR /workspace/booklore-api
|
||||||
|
|
||||||
@@ -36,6 +37,17 @@ RUN set -eux; \
|
|||||||
FROM linuxserver/unrar:7.1.10 AS unrar-layer
|
FROM linuxserver/unrar:7.1.10 AS unrar-layer
|
||||||
|
|
||||||
FROM eclipse-temurin:25-jre-alpine
|
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_VERSION=development
|
||||||
ARG APP_REVISION=unknown
|
ARG APP_REVISION=unknown
|
||||||
@@ -50,20 +62,9 @@ LABEL org.opencontainers.image.title="Grimmory" \
|
|||||||
org.opencontainers.image.licenses="AGPL-3.0" \
|
org.opencontainers.image.licenses="AGPL-3.0" \
|
||||||
org.opencontainers.image.base.name="docker.io/library/eclipse-temurin:25-jre-alpine"
|
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} \
|
ENV APP_VERSION=${APP_VERSION} \
|
||||||
APP_REVISION=${APP_REVISION}
|
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
|
ARG BOOKLORE_PORT=6060
|
||||||
EXPOSE ${BOOKLORE_PORT}
|
EXPOSE ${BOOKLORE_PORT}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user