From 1cb6133a5aa93cdb46e0ec07b3ce5792336522f6 Mon Sep 17 00:00:00 2001 From: Wenying Dong Date: Wed, 22 May 2024 15:31:44 +0800 Subject: [PATCH] address comments Signed-off-by: Wenying Dong --- .github/workflows/build.yml | 5 ++-- .github/workflows/build_tag.yml | 5 ++-- .../workflows/docker_update_base_windows.yml | 2 +- Makefile | 12 ++++++-- build/images/Dockerfile.build.windows | 9 +++--- build/images/ovs/Dockerfile.windows | 7 +++-- hack/build-antrea-windows-all.sh | 30 +++++++++++++++---- 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e5ef0b725f4..7a36941da4a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -125,7 +125,8 @@ jobs: with: show-progress: false - name: Build Antrea Windows Docker image - run: make build-windows + if: ${{ github.repository != 'antrea-io/antrea' || github.event_name != 'push' || github.ref != 'refs/heads/main' }} + run: ./hack/build-antrea-windows-all.sh --pull - name: Push Antrea Windows Docker image to registry if: ${{ github.repository == 'antrea-io/antrea' && github.event_name == 'push' && github.ref == 'refs/heads/main' }} env: @@ -133,7 +134,7 @@ jobs: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - make build-and-push-windows + ./hack/build-antrea-windows-all.sh --pull --push-base-images --push-agent-image shell: bash build-antrea-mc-controller: diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml index f24cf4a4336..ceb8ca84f29 100644 --- a/.github/workflows/build_tag.yml +++ b/.github/workflows/build_tag.yml @@ -66,7 +66,7 @@ jobs: docker push antrea/antrea-controller-ubi:"${VERSION}" build-windows: - runs-on: [windows-2019] + runs-on: [ubuntu-latest] needs: get-version steps: - uses: actions/checkout@v4 @@ -78,9 +78,8 @@ jobs: DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} VERSION: ${{ needs.get-version.outputs.version }} run: | - make build-windows echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker push antrea/antrea-windows:"${VERSION}" + ./hack/build-antrea-windows-all.sh --pull --push-agent-image shell: bash build-antrea-mc-controller: diff --git a/.github/workflows/docker_update_base_windows.yml b/.github/workflows/docker_update_base_windows.yml index 393521fc34d..4b533a6a3ff 100644 --- a/.github/workflows/docker_update_base_windows.yml +++ b/.github/workflows/docker_update_base_windows.yml @@ -22,7 +22,7 @@ on: jobs: build: - runs-on: windows-2019 + runs-on: ubuntu-latest steps: - name: Check-out code uses: actions/checkout@v4 diff --git a/Makefile b/Makefile index 940eb82466f..062c54bde49 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,14 @@ UNAME_S := $(shell uname -s) USERID := $(shell id -u) GRPID := $(shell id -g) +WINDOWS_BUILD_OPTIONS := +ifeq ($(NO_PULL),) + WINDOWS_BUILD_OPTIONS += --pull +endif +ifeq ($(RELEASE_STATUS),released) + WINDOWS_BUILD_OPTIONS += --agent-tag ${DOCKER_IMG_VERSION} +endif + .PHONY: install-hooks install-hooks: @echo "===> Copying Antrea git hooks to local <===" @@ -373,12 +381,12 @@ build-controller-ubi: .PHONY: build-windows build-windows: @echo "===> Building Antrea bins and antrea/antrea-windows Docker image <===" - $(CURDIR)/build/images/build-windows.sh --agent-tag "latest" + $(CURDIR)/build/images/build-windows.sh ${WINDOWS_BUILD_OPTIONS} .PHONY: build-and-push-windows build-and-push-windows: @echo "===> Building Antrea bins and antrea/antrea-windows Docker image and pushing to registry <===" - $(CURDIR)/build/images/build-windows.sh --agent-tag $(DOCKER_IMG_VERSION) --push + $(CURDIR)/build/images/build-windows.sh --push ${WINDOWS_BUILD_OPTIONS} .PHONY: build-ubuntu-coverage build-ubuntu-coverage: build-controller-ubuntu-coverage build-agent-ubuntu-coverage diff --git a/build/images/Dockerfile.build.windows b/build/images/Dockerfile.build.windows index 0227f112931..24cab356715 100644 --- a/build/images/Dockerfile.build.windows +++ b/build/images/Dockerfile.build.windows @@ -22,6 +22,9 @@ ENV CNI_PLUGINS="./host-local.exe" WORKDIR /antrea ADD https://github.com/containernetworking/plugins/releases/download/${CNI_BINARIES_VERSION}/cni-plugins-windows-amd64-${CNI_BINARIES_VERSION}.tgz cni-plugins-windows-amd64.tgz +RUN mkdir -p /go/k/antrea/cni && \ + tar -xzf cni-plugins-windows-amd64.tgz -C /go/k/antrea/cni ${CNI_PLUGINS} && \ + rm cni-plugins-windows-amd64.tgz RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=bind,source=go.sum,target=go.sum \ @@ -34,12 +37,10 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \ --mount=type=cache,target=/root/.cache/go-build/ \ make windows-bin -RUN mkdir -p /go/k/antrea/bin && mkdir -p /go/k/antrea/cni && \ +RUN mkdir -p /go/k/antrea/bin && \ cp /antrea/bin/antrea-agent.exe /go/k/antrea/bin/ && \ cp /antrea/bin/antctl.exe /go/k/antrea/bin/ && \ - cp /antrea/build/images/scripts/Install-WindowsCNI.ps1 /go/k/antrea/ && \ - cp /antrea/bin/antrea-cni.exe /go/k/antrea/cni/antrea.exe && \ - tar -xzf cni-plugins-windows-amd64.tgz -C /go/k/antrea/cni ${CNI_PLUGINS} + cp /antrea/bin/antrea-cni.exe /go/k/antrea/cni/antrea.exe FROM antrea/windows-ovs:${OVS_VERSION} as antrea-ovs diff --git a/build/images/ovs/Dockerfile.windows b/build/images/ovs/Dockerfile.windows index 18d30ba6d9e..5de9d973ebd 100644 --- a/build/images/ovs/Dockerfile.windows +++ b/build/images/ovs/Dockerfile.windows @@ -22,9 +22,10 @@ ADD https://downloads.antrea.io/ovs/ovs-${OVS_VERSION}-antrea.0-win64.zip ovs-${ RUN unzip -q ovs-${OVS_VERSION}-antrea.0-win64.zip && mkdir -p openvswitch/redist ADD https://aka.ms/vs/17/release/vc_redist.x64.exe /openvswitch/redist/redist.x64.exe ADD https://indy.fulgan.com/SSL/openssl-1.0.2u-x64_86-win64.zip openssl-1.0.2u-x64_86-win64.zip -RUN mkdir openssl && unzip -q openssl-1.0.2u-x64_86-win64.zip -d openssl -RUN cp openssl/*.dll /openvswitch/usr/bin/ && \ - cp openssl/*.dll /openvswitch/usr/sbin/ +RUN mkdir openssl && unzip -q openssl-1.0.2u-x64_86-win64.zip -d openssl && \ + cp openssl/*.dll /openvswitch/usr/bin/ && \ + cp openssl/*.dll /openvswitch/usr/sbin/ && \ + rm -rf openssl openssl-1.0.2u-x64_86-win64.zip FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 COPY --from=antrea-windows-builder /openvswitch /openvswitch diff --git a/hack/build-antrea-windows-all.sh b/hack/build-antrea-windows-all.sh index 5810d342928..281bf178cfb 100755 --- a/hack/build-antrea-windows-all.sh +++ b/hack/build-antrea-windows-all.sh @@ -23,11 +23,13 @@ function echoerr { >&2 echo "$@" } -_usage="Usage: $0 [--push-base-images] [--no-cache] +_usage="Usage: $0 [--pull] [--push-base-images] [--push-agent-image] Build the antrea/antrea-windows image, as well as all the base images in the build chain. This is typically used in CI to build the image with the latest version of all dependencies, taking into account changes to all Dockerfiles. + --pull Always attempt to pull a newer version of the base images. --push-base-images Push built images to the registry. Only Windows OVS image will be pushed. + --push-agent-image Push built antrea/antrea-windows image to the registry. This script is run on a Linux machine." @@ -35,15 +37,25 @@ function print_usage { echoerr "$_usage" } -PUSH=false +PULL=false +PUSH_BASE=false +PUSH_AGENT=false while [[ $# -gt 0 ]] do key="$1" case $key in + --pull) + PULL=true + shift + ;; --push-base-images) - PUSH=true + PUSH_BASE=true + shift + ;; + --push-agent-image) + PUSH_AGENT=true shift ;; -h|--help) @@ -62,7 +74,11 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" pushd "$THIS_DIR/.." > /dev/null ARGS="" -if $PUSH; then +if $PULL; then + ARGS="$ARGS --pull" +fi + +if $PUSH_BASE; then ARGS="$ARGS --push" fi @@ -70,6 +86,10 @@ cd build/images/ovs ./build.sh --distro windows $ARGS cd - -make build-windows +if $PUSH_AGENT; then + make build-and-push-windows +else + make build-windows +fi popd > /dev/null