Skip to content

Commit

Permalink
update CI support
Browse files Browse the repository at this point in the history
Signed-off-by: Wenying Dong <wenyingd@vmware.com>
  • Loading branch information
wenyingd committed May 14, 2024
1 parent b6f4a97 commit 26230c7
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 137 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
build-windows:
needs: check-changes
if: ${{ needs.check-changes.outputs.has_changes == 'yes' || github.event_name == 'push' }}
runs-on: [windows-2019]
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -133,7 +133,7 @@ jobs:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push antrea/antrea-windows:latest
WINDOWS_PUSH=1; make build-windows
shell: bash

build-antrea-mc-controller:
Expand Down
19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ 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)
CNI_BINARIES_VERSION := $(shell head -n 1 build/images/deps/cni-binaries-version)
NANOSERVER_VERSION := $(shell head -n 1 build/images/deps/nanoserver-version)
BUILD_TAG := $(shell build/images/build-tag.sh)
WIN_BUILD_TAG := $(shell echo $(GO_VERSION) $(CNI_BINARIES_VERSION) $(NANOSERVER_VERSION)|md5sum|head -c 10)
WIN_OVS_VERSION := $(shell head -n 1 build/images/deps/ovs-version-windows)
WIN_BUILD_OVS_TAG := $(NANOSERVER_VERSION)-$(WIN_OVS_VERSION)
GIT_HOOKS := $(shell find hack/git_client_side_hooks -type f -print)
DOCKER_NETWORK ?= default
TRIVY_TARGET_IMAGE ?=
Expand All @@ -39,12 +35,9 @@ endif
ifneq ($(NO_CACHE),)
DOCKER_BUILD_ARGS += --no-cache
endif
WIN_BUILD_ARGS := DOCKER_BUILD_ARGS
DOCKER_BUILD_ARGS += --build-arg OVS_VERSION=$(OVS_VERSION)
DOCKER_BUILD_ARGS += --build-arg GO_VERSION=$(GO_VERSION)
DOCKER_BUILD_ARGS += --build-arg BUILD_TAG=$(BUILD_TAG)
WIN_BUILD_ARGS := --build-arg GO_VERSION=$(GO_VERSION)
WIN_BUILD_ARGS += --build-arg BUILD_TAG=$(BUILD_TAG)

export CGO_ENABLED

Expand Down Expand Up @@ -380,13 +373,11 @@ build-controller-ubi:
.PHONY: build-windows
build-windows:
@echo "===> Building Antrea bins and antrea/antrea-windows Docker image <==="
docker build -t antrea/antrea-windows:$(DOCKER_IMG_VERSION) -f build/images/Dockerfile.build.windows --network $(DOCKER_NETWORK) $(WIN_BUILD_ARGS) .
docker tag antrea/antrea-windows:$(DOCKER_IMG_VERSION) antrea/antrea-windows

.PHONY: buildx-windows
buildx-windows:
@echo "===> Building Antrea bins and antrea/antrea-windows Docker image <==="
build/images/base-windows/build.sh --target agent --agent-tag $(DOCKER_IMG_VERSION)
ifneq ($(WINDOWS_PUSH),)
$(CURDIR)/build/images/build-windows.sh --target agent --agent-tag $(DOCKER_IMG_VERSION) --push
else
$(CURDIR)/build/images/build-windows.sh --target agent --agent-tag $(DOCKER_IMG_VERSION)
endif

.PHONY: build-ubuntu-coverage
build-ubuntu-coverage: build-controller-ubuntu-coverage build-agent-ubuntu-coverage
Expand Down
13 changes: 10 additions & 3 deletions build/images/Dockerfile.build.windows
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ FROM --platform=linux/amd64 golang:${GO_VERSION} as antrea-build-windows

WORKDIR /antrea

RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download

COPY . /antrea

RUN go mod download && make windows-bin
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 && \
cp /antrea/bin/antrea-agent.exe /go/k/antrea/bin/ && \
Expand All @@ -33,8 +40,8 @@ FROM antrea/windows-ovs:${BUILD_TAG} 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
COPY --from=antrea-base /cni /k/antrea/cni
COPY --from=antrea-base /cni/host-local.exe /k/antrea/cni/
COPY --from=antrea-build-windows /antrea/bin/antrea-cni.exe /k/antrea/cni/antrea.exe
COPY --from=antrea-ovs /openvswitch /openvswitch
COPY --from=antrea-ovs /openvswitch /openvswitchg

ENV PATH="C:\Windows\system32;C:\Windows;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\wbem;"
4 changes: 2 additions & 2 deletions build/images/base-windows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 alpine:3.14 as antrea-build-windows
FROM --platform=linux/amd64 ubuntu:22.04 as antrea-windows-builder
ARG CNI_BINARIES_VERSION

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/cni && tar xzf cni-plugins-windows-amd64.tgz -C /go/cni

FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
COPY --from=antrea-build-windows /go/cni /cni
COPY --from=antrea-windows-builder /go/cni /cni
11 changes: 7 additions & 4 deletions build/images/base-windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ If you need to build a new version of the image and push it to Dockerhub, you
can run the following:

```bash
cd build/images/base-windows
./build.sh --push
cd build/images
./build.sh --target base --push
```

If you want to build a new version of the image and save it locally, you
can run the following:

```bash
cd build/images/base-windows
./build.sh --local-name windows-base
cd build/images
./build.sh --target base
```

After that, a file named as "base-windows.tar" is created in the path where you
run the command.

The command will fail if you do not have permission to push to the
`antrea` Dockerhub repository.

Expand Down
42 changes: 33 additions & 9 deletions build/images/build-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ function check_docker_build_driver() {
}

function switch_windows_buildx() {
local windows_buildx_name="windows-img-builder"
original_buildx_instance=$(docker buildx inspect | grep -oP '^Name:\s*\K\S+' | head -n 1)
if [ "$original_buildx_instance" = "${windows_buildx_name}" ]; then
return
fi
trap 'docker buildx use --default ${original_buildx_instance}' EXIT
local windows_buildx_name="windows-img-builder"
if docker buildx ls | grep -q "${windows_buildx_name}" ; then
docker buildx ls | grep -q "${windows_buildx_name}"
if [ $? -eq 0 ] ; then
docker buildx use --builder windows/amd64 "${windows_buildx_name}"
else
docker buildx create --name "${windows_buildx_name}" --use --platform windows/amd64
Expand All @@ -56,15 +60,35 @@ function switch_windows_buildx() {
function docker_build_and_push_windows() {
local image="$1"
local dockerfile="$2"
local build_args="$3"
local local_file="$4"
local cache_args="$3"
local build_args="$4"
local build_tag="$5"
local push=$6

switch_windows_buildx
local_file=$(echo "${image}" | awk -F'/' '{print $NF}')
image_output="type=registry"
if [ "${local_file}" != "" ]; then
image_output="type=docker,dest=./${local_file}.tar"
if $push; then
output="type=registry"
else
local_file=$(echo "${image}" | awk -F'/' '{print $NF}')
output="type=docker,dest=./${local_file}.tar"
fi

docker buildx build --platform windows/amd64 -o ${output} -t ${image}:${build_tag} ${cache_args} ${build_args} -f $dockerfile .
}

function get_cache_args() {
local image=$1
local build_tag=$2
local push=$3
local no_cache=$4
local cache_args=""
if $push; then
cache_args="$cache_args --cache-to type=registry,ref=$image-cache:$build_tag,mode=max"
fi
if $no_cache; then
cache_args="$cache_args --no-cache"
else
cache_args="$cache_args --cache-from type=registry,ref=$image-cache:$build_tag,mode=max"
fi
docker buildx build --platform windows/amd64 -o ${image_output} -t $image:${build_tag} ${build_args} -f $dockerfile .
echo $cache_args
}
49 changes: 32 additions & 17 deletions build/images/base-windows/build.sh → build/images/build-windows.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ set -eo pipefail

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

source $THIS_DIR/../build-utils.sh
source $THIS_DIR/build-utils.sh

_usage="Usage: $0 [--pull] [--local-file] [--target base|agent] [--agent-tag]
_usage="Usage: $0 [--push] [--no-cache] [--target base|agent] [--agent-tag]
Build the antrea base image.
--push Push the built image to the registry
--no-cache Do not use the local build cache nor the cached image from the registry
--target Target container image to build.
--agent-tag Antrea Agent image tag. It is set only when target is agent"

PUSH=false
NO_CACHE=false
TARGET="base"
AGENT_TAG=""

Expand All @@ -42,6 +44,10 @@ case $key in
PUSH=true
shift
;;
--no-cache)
NO_CACHE=true
shift
;;
--target)
TARGET="$2"
shift 2
Expand Down Expand Up @@ -74,35 +80,44 @@ elif [ "$TARGET" = "base" ] && [ "${AGENT_TAG}" != "" ]; then
AGENT_TAG=""
fi

if [ "$PUSH" = "false" ] && [ -n "${WINDOWS_PUSH}" ]; then
PUSH=true
fi

pushd $THIS_DIR > /dev/null

BUILD_ARG=""
BUILD_ARGS=""
docker_file=""
BUILD_TAG=$(../build-tag.sh)
BUILD_TAG=$(./build-tag.sh)

repository="antrea"

if [ "$TARGET" = "base" ]; then
CNI_BINARIES_VERSION=$(head -n 1 ../deps/cni-binaries-version)
BUILD_ARG="--build-arg CNI_BINARIES_VERSION=${CNI_BINARIES_VERSION}"
docker_file="Dockerfile"
CNI_BINARIES_VERSION=$(head -n 1 deps/cni-binaries-version)
BUILD_ARGS="--build-arg CNI_BINARIES_VERSION=${CNI_BINARIES_VERSION}"
image_name="base-windows"
image="${repository}/${image_name}"
popd > /dev/null
pushd base-windows
docker_file="Dockerfile"
cache_args=$(get_cache_args $image $BUILD_TAG $PUSH $NO_CACHE)
elif [ "$TARGET" = "agent" ]; then
GO_VERSION=$(head -n 1 ../deps/go-version)
BUILD_ARG="--build-arg GO_VERSION=${GO_VERSION} --build-arg BUILD_TAG=${BUILD_TAG}"
GO_VERSION=$(head -n 1 deps/go-version)
BUILD_ARGS="--build-arg GO_VERSION=${GO_VERSION} --build-arg BUILD_TAG=${BUILD_TAG}"
image_name="antrea-windows"
BUILD_TAG="${AGENT_TAG}"
image="${repository}/${image_name}"
popd > /dev/null
ANTREA_DIR=${THIS_DIR}/../../../
ANTREA_DIR=${THIS_DIR}/../../
pushd $ANTREA_DIR > /dev/null
docker_file="build/images/Dockerfile.build.windows"
fi
image="${repository}/${image_name}"
local_file="$image_name"
if $PUSH ; then
local_file=""
cache_args=$(get_cache_args $image $AGENT_TAG $PUSH $NO_CACHE)
if $PUSH ; then
BUILD_TAG="${AGENT_TAG}"
else
BUILD_TAG="latest"
fi
fi

docker_build_and_push_windows "${image}" "${docker_file}" "$BUILD_ARG" "${local_file}" "${BUILD_TAG}"
docker_build_and_push_windows "${image}" "${docker_file}" "${cache_args}" "${BUILD_ARGS}" "${BUILD_TAG}" $PUSH

popd > /dev/null
7 changes: 5 additions & 2 deletions build/images/ovs/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=linux/amd64 alpine:3.14 as builder
FROM --platform=linux/amd64 ubuntu:22.04 as antrea-windows-builder
ARG OVS_VERSION

RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends unzip

ADD https://downloads.antrea.io/ovs/ovs-${OVS_VERSION}-antrea.0-win64.zip ovs-${OVS_VERSION}-antrea.0-win64.zip
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
Expand All @@ -24,4 +27,4 @@ RUN cp openssl/*.dll /openvswitch/usr/bin/ && \
cp openssl/*.dll /openvswitch/usr/sbin/

FROM mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
COPY --from=builder /openvswitch /openvswitch
COPY --from=antrea-windows-builder /openvswitch /openvswitch
21 changes: 7 additions & 14 deletions build/images/ovs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,16 @@ if $PULL; then
elif [ "$DISTRO" == "ubi" ]; then
docker pull $PLATFORM_ARG quay.io/centos/centos:stream9
docker pull $PLATFORM_ARG registry.access.redhat.com/ubi9
elif [ "$DISTRO" == "windows" ]; then
docker pull ubuntu:22.04
fi
fi

function docker_build_and_push() {
local image="$1"
local dockerfile="$2"
local build_args="--build-arg OVS_VERSION=$OVS_VERSION"
local cache_args=""
if $PUSH; then
cache_args="$cache_args --cache-to type=registry,ref=$image-cache:$BUILD_TAG,mode=max"
fi
if $NO_CACHE; then
cache_args="$cache_args --no-cache"
else
cache_args="$cache_args --cache-from type=registry,ref=$image-cache:$BUILD_TAG,mode=max"
fi
cache_args=$(get_cache_args $image $BUILD_TAG $PUSH $NO_CACHE)
docker buildx build $PLATFORM_ARG -o type=docker -t $image:$BUILD_TAG $cache_args $build_args -f $dockerfile .

if $PUSH; then
Expand All @@ -147,11 +141,10 @@ if [ "$DISTRO" == "ubuntu" ]; then
elif [ "$DISTRO" == "ubi" ]; then
docker_build_and_push "antrea/openvswitch-ubi" "Dockerfile.ubi"
elif [ "$DISTRO" == "windows" ]; then
local_file=$(echo "${image}" | awk -F'/' '{print $NF}')
if $PUSH; then
local_file=""
fi
docker_build_and_push_windows "antrea/windows-ovs" "Dockerfile.windows" "--build-arg OVS_VERSION=$OVS_VERSION" "${local_file}" "${BUILD_TAG}"
image="antrea/windows-ovs"
cache_args=$(get_cache_args $image $BUILD_TAG $PUSH $NO_CACHE)
build_args="--build-arg OVS_VERSION=$OVS_VERSION"
docker_build_and_push_windows "${image}" "Dockerfile.windows" "${cache_args}" "${build_args}" "${BUILD_TAG}" $PUSH
fi

popd > /dev/null
25 changes: 23 additions & 2 deletions build/yamls/antrea-windows-with-ovs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data:
$ErrorActionPreference = "Stop"
$mountPath = $env:CONTAINER_SANDBOX_MOUNT_POINT
$mountPath = ($mountPath.Replace('\', '/')).TrimEnd('/')
$env:PATH = $env:PATH + ";$mountPath/Windows/System32;$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$env:PATH = $env:PATH + ";$mountPath/openvswitch/usr/bin;$mountPath/openvswitch/usr/sbin"
$OVSDriverDir="$mountPath\openvswitch\driver"
# Check if OVSExt driver is already installed
Expand All @@ -54,6 +54,27 @@ data:
netcfg -l $OVSDriverDir/ovsext.inf -c s -i OVSExt
}
# Check if redist is already installed
$OVSRedistDir="$mountPath\openvswitch\redist"
if (!$(Test-Path $OVSRedistDir)) {
$dllFound = $false
$paths = $env:PATH -split ';'
foreach ($path in $paths) {
$dllFiles = Get-ChildItem -Path $path -Filter "vcruntime*.dll" -File -ErrorAction SilentlyContinue
if ($dllFiles.Count -gt 0) {
$dllFound = $true
break
}
}
# vcruntime dlls are not installed on the host, then install the binaries.
if (-not $dllFound) {
Get-ChildItem $OVSRedistDir -Filter *.exe | ForEach-Object {
Start-Process -FilePath $_.FullName -Args '/install /passive /norestart' -Verb RunAs -Wait
}
}
}
# Configure OVS processes
$OVS_DB_SCHEMA_PATH = "$mountPath/openvswitch/usr/share/openvswitch/vswitch.ovsschema"
$OVS_DB_PATH = "C:\openvswitch\etc\openvswitch\conf.db"
Expand Down Expand Up @@ -293,7 +314,7 @@ spec:
template:
metadata:
annotations:
checksum/agent-windows: bb43d8d5840ffd71ff946d44052fefc5bd88ca5ad58ac5048d85a5cf26a7ef13
checksum/agent-windows: 50c7c6199862a3e650802a43ecdc9e6bc9118f3faa24e0dcf959434c0526f0f3
checksum/windows-config: 6ff4f8bd0b310ebe4d4612bdd9697ffb3d79e0e0eab3936420417dd5a8fc128d
microsoft.com/hostprocess-inherit-user: "true"
labels:
Expand Down
Loading

0 comments on commit 26230c7

Please sign in to comment.