ci: fix dind anchor (services must be an array); push images to Docker Hub instead of docker-save artifacts

This commit is contained in:
EnderTheCoder
2026-09-20 02:30:00 +08:00
parent b6d619254d
commit 7cb4d18308
+42 -33
View File
@@ -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: