From 5b0e4f7b29dd0a504dfc1dd1613f326605864527 Mon Sep 17 00:00:00 2001 From: Dumitru Ceara Date: Tue, 14 Nov 2023 22:34:56 +0100 Subject: [PATCH] ci: Use per-branch CI container images. That allows us to use different distro bases for different stable branches. Signed-off-by: Dumitru Ceara --- .ci/ci.sh | 9 ++++++++- .cirrus.yml | 2 +- .github/workflows/containers.yml | 13 ++++++++++--- .github/workflows/test.yml | 7 ++++++- utilities/containers/Makefile | 4 ++-- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.ci/ci.sh b/.ci/ci.sh index 3f1b41eadc..ccec572c3a 100755 --- a/.ci/ci.sh +++ b/.ci/ci.sh @@ -20,7 +20,8 @@ DPDK_PATH=${DPDK_PATH:-$OVN_PATH/dpdk-dir} CONTAINER_CMD=${CONTAINER_CMD:-podman} CONTAINER_WORKSPACE="/workspace" CONTAINER_WORKDIR="/workspace/ovn-tmp" -IMAGE_NAME=${IMAGE_NAME:-"ovn-org/ovn-tests"} +DEFAULT_IMAGE_NAME="ovn-org/ovn-tests:main-fedora" +IMAGE_NAME=${IMAGE_NAME:-${DEFAULT_IMAGE_NAME}} # Test variables ARCH=${ARCH:-$(uname -m)} @@ -167,6 +168,12 @@ if [ -z "$DPDK" ]; then mkdir -p "$DPDK_PATH" fi +# Check if the IMAGE_NAME is a real image we can pull, otherwise fall +# back to DEFAULT_IMAGE_NAME. +if ! $CONTAINER_CMD pull $IMAGE_NAME; then + IMAGE_NAME=$DEFAULT_IMAGE_NAME +fi + CONTAINER_ID="$($CONTAINER_CMD run --privileged -d \ --pids-limit=-1 \ --env ASAN_OPTIONS=$ASAN_OPTIONS \ diff --git a/.cirrus.yml b/.cirrus.yml index bd4cd08aaf..23e720cc47 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -1,7 +1,7 @@ arm_unit_tests_task: arm_container: - image: ghcr.io/ovn-org/ovn-tests:fedora + image: ghcr.io/ovn-org/ovn-tests:main-fedora memory: 4G cpu: 2 diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml index 1aee8de91c..729f80ec80 100644 --- a/.github/workflows/containers.yml +++ b/.github/workflows/containers.yml @@ -7,8 +7,6 @@ on: - cron: '0 0 * * 1' env: - IMAGE_REGISTRY: ghcr.io - IMAGE_NAMESPACE: ovn-org IMAGE_NAME: ovn-tests CONTAINERS_PATH: ./utilities/containers DEPENDENCIES: podman @@ -34,13 +32,22 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v2 + - name: Build image name + run: | + echo "IMAGE_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" \ + >> $GITHUB_ENV + echo "IMAGE_REGISTRY=ghcr.io" \ + >> $GITHUB_ENV + echo "IMAGE_NAMESPACE=$GITHUB_REPOSITORY_OWNER" \ + >> $GITHUB_ENV + - name: Build container images id: build-image uses: redhat-actions/buildah-build@v2 with: image: ${{ env.IMAGE_NAME }} archs: amd64, arm64 - tags: ${{ matrix.distro }} + tags: ${{ env.IMAGE_BRANCH }}-${{ matrix.distro }} build-args: CONTAINERS_PATH=${{ env.CONTAINERS_PATH }} dockerfiles: ${{ env.CONTAINERS_PATH }}/${{ matrix.distro }}/Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 53e676eccc..c87865bf12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,7 +83,6 @@ jobs: build-linux: needs: build-dpdk env: - IMAGE_NAME: ghcr.io/ovn-org/ovn-tests:ubuntu ARCH: ${{ matrix.cfg.arch }} CC: ${{ matrix.cfg.compiler }} DPDK: ${{ matrix.cfg.dpdk }} @@ -134,6 +133,12 @@ jobs: with: submodules: recursive + - name: Build image name + run: | + IMAGE_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + echo "IMAGE_NAME=ghcr.io/$GITHUB_REPOSITORY_OWNER/ovn-tests:${IMAGE_BRANCH}-ubuntu" \ + >> $GITHUB_ENV + # For weekly runs, don't update submodules - name: checkout without submodule if: github.event_name == 'schedule' diff --git a/utilities/containers/Makefile b/utilities/containers/Makefile index d79e4ad5ee..e2e8f95064 100644 --- a/utilities/containers/Makefile +++ b/utilities/containers/Makefile @@ -1,5 +1,5 @@ CONTAINER_CMD ?= podman -IMAGE_NAME ?= "ovn-org/ovn-tests" +IMAGE_NAME ?= "ovn-org/ovn-tests:main" CONTAINERS_PATH ?= "." distros := fedora ubuntu @@ -7,5 +7,5 @@ distros := fedora ubuntu .PHONY: $(distros) $(distros): - $(CONTAINER_CMD) build --no-cache --rm -t $(IMAGE_NAME):$@ \ + $(CONTAINER_CMD) build --no-cache --rm -t $(IMAGE_NAME)-$@ \ -f $@/Dockerfile . --build-arg=CONTAINERS_PATH=$(CONTAINERS_PATH)