From a0434d974f0c156415af8d52111951fa6742574d Mon Sep 17 00:00:00 2001 From: TapTap Date: Fri, 13 Nov 2026 13:52:49 +0000 Subject: [PATCH] ci: build images with kaniko inside the job image The runner does not expose its Docker socket to job containers, so the image job could not run docker build. Include the kaniko executor in the CI image and build/push directly from the job; docker login only writes the registry credentials file. Bump the CI image tag to 2. --- .gitea/workflows/ci.yaml | 29 ++++++++++++++++------------- ci/Dockerfile | 5 +++++ scripts/build-ci-image.sh | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index a12b5bb..1bf03e1 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -13,13 +13,13 @@ env: IMAGE_NAME: taptap/audiomanager # Built by scripts/build-ci-image.sh from ci/Dockerfile. Bump the tag when # ci/Dockerfile changes. - CI_IMAGE: gitea.tap-tap.win/taptap/audiomanager-ci:1 + CI_IMAGE: gitea.tap-tap.win/taptap/audiomanager-ci:2 jobs: test: runs-on: ubuntu-latest container: - image: gitea.tap-tap.win/taptap/audiomanager-ci:1 + image: gitea.tap-tap.win/taptap/audiomanager-ci:2 steps: - uses: actions/checkout@v4 - name: Test @@ -30,7 +30,7 @@ jobs: chart: runs-on: ubuntu-latest container: - image: gitea.tap-tap.win/taptap/audiomanager-ci:1 + image: gitea.tap-tap.win/taptap/audiomanager-ci:2 steps: - uses: actions/checkout@v4 - name: Lint and render the chart @@ -44,11 +44,8 @@ jobs: - chart if: github.event_name == 'push' runs-on: ubuntu-latest - # The runner executes jobs in containers; expose its Docker daemon so the - # image build works without a separate DinD service. container: - image: gitea.tap-tap.win/taptap/audiomanager-ci:1 - options: --volume /var/run/docker.sock:/var/run/docker.sock + image: gitea.tap-tap.win/taptap/audiomanager-ci:2 permissions: contents: read packages: write @@ -70,12 +67,18 @@ jobs: tags+=("$REGISTRY/$IMAGE_NAME:latest") fi - build_args=() + destinations=() for tag in "${tags[@]}"; do - build_args+=(-t "$tag") + destinations+=(--destination "$tag") done - docker build "${build_args[@]}" . - for tag in "${tags[@]}"; do - docker push "$tag" - done + # Kaniko builds without a Docker daemon. docker login wrote the + # credentials to the default Docker config location. + mkdir -p /kaniko/.docker + cp "$HOME/.docker/config.json" /kaniko/.docker/config.json + + kaniko-executor \ + --context="dir://$PWD" \ + --dockerfile="$PWD/Dockerfile" \ + --snapshot-mode=redo \ + "${destinations[@]}" diff --git a/ci/Dockerfile b/ci/Dockerfile index 036f327..9004f5b 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -2,6 +2,8 @@ # workflows do not download a JDK or install packages on every run. # # Build and push it with scripts/build-ci-image.sh. +FROM gcr.io/kaniko-project/executor:v1.23.2-debug AS kaniko + FROM gradle:8.14.3-jdk21 ARG NODE_VERSION=22.14.0 @@ -42,6 +44,9 @@ RUN curl -fsSL "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" \ && rm -rf /tmp/helm.tgz /tmp/linux-amd64 \ && helm version --short +# Build images inside the job container without a Docker daemon. +COPY --from=kaniko /kaniko/executor /usr/local/bin/kaniko-executor + ENV GRADLE_USER_HOME=/root/.gradle \ JAVA_HOME=/opt/java/openjdk diff --git a/scripts/build-ci-image.sh b/scripts/build-ci-image.sh index 6bac23f..ec8ddfb 100755 --- a/scripts/build-ci-image.sh +++ b/scripts/build-ci-image.sh @@ -7,7 +7,7 @@ set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" IMAGE="${CI_IMAGE:-gitea.tap-tap.win/taptap/audiomanager-ci}" -TAG="${1:-1}" +TAG="${1:-2}" docker build -f "$ROOT/ci/Dockerfile" -t "$IMAGE:$TAG" "$ROOT" docker push "$IMAGE:$TAG"