From 7cb4d18308b00ab58b9f220075a3c59e612bdcc6 Mon Sep 17 00:00:00 2001 From: EnderTheCoder Date: Sun, 20 Sep 2026 02:30:00 +0800 Subject: [PATCH] ci: fix dind anchor (services must be an array); push images to Docker Hub instead of docker-save artifacts --- .gitlab-ci.yml | 75 ++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3130739..8ba24c2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,17 +9,18 @@ variables: DOCKER_BUILDKIT: "1" # apt mirror used inside both images (override per pipeline if needed) APT_MIRROR: "http://mirrors.tuna.tsinghua.edu.cn/ubuntu" + # Images are shared through Docker Hub (never as artifacts). + IMAGE: "docker.io/$DOCKERHUB_USERNAME/$CI_PROJECT_NAME" +# dind pulls docker.io images through the intranet Harbor pull-through cache. +# NOTE: anchor only the *array* so `services: *dind` stays an array. .dind: &dind - services: - - name: docker:dind - # Pull docker.io images through the intranet Harbor pull-through cache; - # plain HTTP registry, hence --insecure-registry. - command: - - --registry-mirror=http://192.168.1.11:9090/dockerhub - - --insecure-registry=192.168.1.11:9090 + - name: docker:dind + command: + - --registry-mirror=http://192.168.1.11:9090/dockerhub + - --insecure-registry=192.168.1.11:9090 -# --- build the two isolated toolchain images --------------------------------- +# --- build the two isolated toolchain images and push them -------------------- linux_image: stage: image image: docker:latest @@ -27,13 +28,18 @@ linux_image: tags: - docker script: - - docker build --target dev -t openra3-linux:local --build-arg APT_MIRROR=$APT_MIRROR . - - docker save openra3-linux:local -o linux-image.tar - artifacts: - name: "linux-image-$CI_COMMIT_SHORT_SHA" - paths: - - linux-image.tar - expire_in: 1 day + - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + # Registry cache export needs the docker-container driver, not the default + # docker driver ("Cache export is not supported for the docker driver"). + - docker buildx create --use --name ci-builder --driver docker-container + - | + docker buildx build \ + --cache-from type=registry,ref=$IMAGE:cache-linux \ + --cache-to type=registry,ref=$IMAGE:cache-linux,mode=max \ + --build-arg APT_MIRROR=$APT_MIRROR \ + --target dev \ + -t $IMAGE:$CI_COMMIT_SHORT_SHA-linux \ + --push -f Dockerfile . windows_image: stage: image @@ -42,13 +48,16 @@ windows_image: tags: - docker script: - - docker build -f Dockerfile.win --target dev -t openra3-windows:local --build-arg APT_MIRROR=$APT_MIRROR . - - docker save openra3-windows:local -o windows-image.tar - artifacts: - name: "windows-image-$CI_COMMIT_SHORT_SHA" - paths: - - windows-image.tar - expire_in: 1 day + - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - docker buildx create --use --name ci-builder --driver docker-container + - | + docker buildx build \ + --cache-from type=registry,ref=$IMAGE:cache-windows \ + --cache-to type=registry,ref=$IMAGE:cache-windows,mode=max \ + --build-arg APT_MIRROR=$APT_MIRROR \ + --target dev \ + -t $IMAGE:$CI_COMMIT_SHORT_SHA-windows \ + --push -f Dockerfile.win . # --- build and test each target ---------------------------------------------- build_linux: @@ -59,13 +68,13 @@ build_linux: - docker needs: - linux_image - before_script: - - docker load -i linux-image.tar script: - - docker run --rm -v "$(pwd):/work" -w /work openra3-linux:local cmake -S . -B build/linux -G Ninja -DCMAKE_BUILD_TYPE=Release - - docker run --rm -v "$(pwd):/work" -w /work openra3-linux:local cmake --build build/linux -j - - docker run --rm -v "$(pwd):/work" -w /work openra3-linux:local ctest --test-dir build/linux --output-on-failure - - docker run --rm -v "$(pwd):/work" -w /work openra3-linux:local bash -c "mkdir -p artifacts/linux && cp build/linux/bin/openra3 artifacts/linux/" + - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - docker pull $IMAGE:$CI_COMMIT_SHORT_SHA-linux + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-linux cmake -S . -B build/linux -G Ninja -DCMAKE_BUILD_TYPE=Release + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-linux cmake --build build/linux -j + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-linux ctest --test-dir build/linux --output-on-failure + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-linux bash -c "mkdir -p artifacts/linux && cp build/linux/bin/openra3 artifacts/linux/" artifacts: name: "$CI_PROJECT_NAME-linux-$CI_COMMIT_SHORT_SHA" paths: @@ -80,15 +89,15 @@ build_windows: - docker needs: - windows_image - before_script: - - docker load -i windows-image.tar script: - - docker run --rm -v "$(pwd):/work" -w /work openra3-windows:local + - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin + - docker pull $IMAGE:$CI_COMMIT_SHORT_SHA-windows + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-windows cmake -S . -B build/windows -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/llvm-mingw-x86_64.cmake -DCMAKE_BUILD_TYPE=Release - - docker run --rm -v "$(pwd):/work" -w /work openra3-windows:local cmake --build build/windows -j - - docker run --rm -v "$(pwd):/work" -w /work openra3-windows:local bash -c "mkdir -p artifacts/windows && cp build/windows/bin/openra3.exe build/windows/bin/SDL3.dll artifacts/windows/" + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-windows cmake --build build/windows -j + - docker run --rm -v "$(pwd):/work" -w /work $IMAGE:$CI_COMMIT_SHORT_SHA-windows bash -c "mkdir -p artifacts/windows && cp build/windows/bin/openra3.exe build/windows/bin/SDL3.dll artifacts/windows/" artifacts: name: "$CI_PROJECT_NAME-windows-$CI_COMMIT_SHORT_SHA" paths: