Skip to content

Commit

Permalink
Enhance CI Compatibility with Different Docker Registry
Browse files Browse the repository at this point in the history
When a user switches the Docker registry for image access, building both Linux
and Windows images still pulls images from the default registry. This patch
improves compatibility for registry changes.

Signed-off-by: Shuyang Xin <[email protected]>
  • Loading branch information
XinShuYang committed Feb 28, 2025
1 parent 61f55bb commit 16579ab
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DOCKER_CACHE := $(CURDIR)/.cache
ANTCTL_BINARY_NAME ?= antctl
OVS_VERSION := $(shell head -n 1 build/images/deps/ovs-version)
GO_VERSION := $(shell head -n 1 build/images/deps/go-version)
DOCKER_REGISTRY := $(shell head -n 1 ci/docker-registry)
CNI_BINARIES_VERSION := $(shell head -n 1 build/images/deps/cni-binaries-version)
GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print)
DOCKER_NETWORK ?= default
Expand Down Expand Up @@ -49,6 +50,7 @@ ifneq ($(DOCKER_TARGETPLATFORM),)
endif
DOCKER_BUILD_ARGS += --build-arg OVS_VERSION=$(OVS_VERSION)
DOCKER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION)
DOCKER_BUILD_ARGS += --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY)

export CGO_ENABLED

Expand Down
5 changes: 3 additions & 2 deletions build/images/Dockerfile.build.windows
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

ARG GO_VERSION
ARG OVS_VERSION
ARG DOCKER_REGISTRY

FROM --platform=linux/amd64 golang:${GO_VERSION} AS antrea-build-windows
FROM --platform=linux/amd64 ${DOCKER_REGISTRY}/golang:${GO_VERSION} AS antrea-build-windows
ARG CNI_BINARIES_VERSION
ENV CNI_PLUGINS="./host-local.exe"

Expand Down Expand Up @@ -43,7 +44,7 @@ RUN mkdir -p /go/k/antrea/bin && \
cp /antrea/bin/antrea-cni.exe /go/k/antrea/cni/antrea.exe && \
cp /antrea/hack/windows/Install-OVS.ps1 /go/k/antrea/

FROM antrea/windows-ovs:${OVS_VERSION} AS antrea-ovs
FROM ${DOCKER_REGISTRY}/antrea/windows-ovs:${OVS_VERSION} AS antrea-ovs

FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
COPY --from=antrea-build-windows /go/k /k
Expand Down
3 changes: 2 additions & 1 deletion build/images/build-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ docker_file=""
CNI_BINARIES_VERSION=$(head -n 1 deps/cni-binaries-version)
GO_VERSION=$(head -n 1 deps/go-version)
OVS_VERSION=$(head -n 1 deps/ovs-version-windows)
DOCKER_REGISTRY=$(head -n 1 ../../../ci/docker-registry)

registry="antrea"
image_name="antrea-windows"
image="${registry}/${image_name}"
BUILD_ARGS="--build-arg GO_VERSION=${GO_VERSION} --build-arg OVS_VERSION=${OVS_VERSION} --build-arg CNI_BINARIES_VERSION=${CNI_BINARIES_VERSION}"
BUILD_ARGS="--build-arg GO_VERSION=${GO_VERSION} --build-arg OVS_VERSION=${OVS_VERSION} --build-arg CNI_BINARIES_VERSION=${CNI_BINARIES_VERSION} --build-arg DOCKER_REGISTRY=${DOCKER_REGISTRY}"

ANTREA_DIR=${THIS_DIR}/../../
pushd $ANTREA_DIR > /dev/null
Expand Down
6 changes: 4 additions & 2 deletions build/images/ovs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:24.04 AS ovs-debs
ARG DOCKER_REGISTRY

FROM ${DOCKER_REGISTRY}/ubuntu:24.04 AS ovs-debs

# Some patches may not apply cleanly if a non-default version is provided.
# See build/images/deps/ovs-version for the default version.
Expand All @@ -39,7 +41,7 @@ RUN wget -q -O - https://www.openvswitch.org/releases/openvswitch-$OVS_VERSION.t
cd / && rm -rf /tmp/openvswitch*


FROM ubuntu:24.04
FROM ${DOCKER_REGISTRY}/ubuntu:24.04

LABEL maintainer="Antrea <[email protected]>"
LABEL description="A Docker image based on Ubuntu 24.04 which includes Open vSwitch built from source."
Expand Down
4 changes: 3 additions & 1 deletion build/images/ovs/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 ubuntu:24.04 AS antrea-windows-builder
ARG DOCKER_REGISTRY

FROM --platform=linux/amd64 ${DOCKER_REGISTRY}/ubuntu:24.04 AS antrea-windows-builder
ARG OVS_VERSION

RUN apt-get update && \
Expand Down
3 changes: 2 additions & 1 deletion build/images/ovs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ fi
pushd $THIS_DIR > /dev/null

OVS_VERSION=$(head -n 1 ${OVS_VERSION_FILE})
DOCKER_REGISTRY=$(head -n 1 ../../../ci/docker-registry)

BUILD_CACHE_TAG=$(../build-tag.sh)

Expand All @@ -139,7 +140,7 @@ fi
function docker_build_and_push() {
local image="$1"
local dockerfile="$2"
local build_args="--build-arg OVS_VERSION=$OVS_VERSION"
local build_args="--build-arg OVS_VERSION=$OVS_VERSION --build-arg DOCKER_REGISTRY=$DOCKER_REGISTRY"
local cache_args=""
if $PUSH; then
cache_args="$cache_args --cache-to type=registry,ref=$image-cache:$BUILD_CACHE_TAG,mode=max"
Expand Down
2 changes: 1 addition & 1 deletion ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ function deliver_antrea_windows {
revert_snapshot_windows ${WORKER_NAME}
k8s_images=("registry.k8s.io/e2e-test-images/agnhost:2.52" "registry.k8s.io/e2e-test-images/jessie-dnsutils:1.5" "registry.k8s.io/e2e-test-images/nginx:1.14-2" "registry.k8s.io/pause:3.10")
conformance_images=("k8sprow.azurecr.io/kubernetes-e2e-test-images/agnhost:2.52" "k8sprow.azurecr.io/kubernetes-e2e-test-images/jessie-dnsutils:1.5" "k8sprow.azurecr.io/kubernetes-e2e-test-images/nginx:1.14-2" "registry.k8s.io/e2e-test-images/pause:3.10")
e2e_images=("${DOCKER_REGISTRY}/antrea/toolbox:1.4-0" "registry.k8s.io/e2e-test-images/agnhost:2.40")
e2e_images=("${DOCKER_REGISTRY}/antrea/toolbox:1.5-1" "registry.k8s.io/e2e-test-images/agnhost:2.40")
# Pull necessary images in advance to avoid transient error
for i in "${!k8s_images[@]}"; do
ssh -o StrictHostKeyChecking=no -n Administrator@${IP} "ctr -n k8s.io images pull --user ${DOCKER_USERNAME}:${DOCKER_PASSWORD} ${k8s_images[i]} && ctr -n k8s.io images tag ${k8s_images[i]} ${conformance_images[i]}" || true
Expand Down

0 comments on commit 16579ab

Please sign in to comment.