From ce6caff85f9b73ee0bf4ce60cedcc5544a61b4f3 Mon Sep 17 00:00:00 2001 From: TJWater CI Date: Fri, 7 Aug 2026 17:35:40 +0800 Subject: [PATCH] feat(ci): support internal offline build cache --- .gitea/workflows/container-cd.yml | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/container-cd.yml b/.gitea/workflows/container-cd.yml index b78fc63..7b83727 100644 --- a/.gitea/workflows/container-cd.yml +++ b/.gitea/workflows/container-cd.yml @@ -15,6 +15,11 @@ on: required: false default: . type: string + cache_image: + description: Optional internal image carrying BuildKit inline cache + required: false + default: "" + type: string test_command: description: Optional source-level test command required: false @@ -48,11 +53,6 @@ jobs: - name: Source tests if: ${{ inputs.test_command != '' }} run: ${{ inputs.test_command }} - - name: Build immutable candidate image - run: | - set -eu - docker build --pull=false -f "${{ inputs.dockerfile }}" \ - -t "${{ inputs.image_name }}:sha-${{ gitea.sha }}" "${{ inputs.build_context }}" - name: Login and publish candidate image env: REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }} @@ -61,6 +61,18 @@ jobs: set -eu registry="$(printf '%s' '${{ inputs.image_name }}' | cut -d/ -f1)" printf '%s' "$REGISTRY_PASSWORD" | docker login "$registry" -u "$REGISTRY_USERNAME" --password-stdin + if [ -n "${{ inputs.cache_image }}" ]; then + docker pull "${{ inputs.cache_image }}" + fi + - name: Build immutable candidate image + run: | + set -eu + cache_args=() + if [ -n "${{ inputs.cache_image }}" ]; then + cache_args+=(--cache-from "${{ inputs.cache_image }}") + fi + docker build --pull=false "${cache_args[@]}" -f "${{ inputs.dockerfile }}" \ + -t "${{ inputs.image_name }}:sha-${{ gitea.sha }}" "${{ inputs.build_context }}" docker push "${{ inputs.image_name }}:sha-${{ gitea.sha }}" - name: Candidate pull on Dev if: ${{ inputs.deploy_service != '' && inputs.deploy_host != '' }}