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 13, 2024
1 parent b6f4a97 commit ded05d0
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 87 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: 6 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ 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 +36,14 @@ 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)

WINDOWS_BUILD_ARGS :=
ifneq ($(WINDOWS_PUSH),)
WINDOWS_BUILD_ARGS = --push
endif

export CGO_ENABLED

Expand Down Expand Up @@ -380,13 +379,7 @@ 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)
build/images/base-windows/build.sh --target agent --agent-tag $(DOCKER_IMG_VERSION) $(WINDOWS_BUILD_ARGS)

.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;"
5 changes: 4 additions & 1 deletion build/images/base-windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ can run the following:

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

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
8 changes: 6 additions & 2 deletions build/images/base-windows/build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

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

_usage="Usage: $0 [--pull] [--local-file] [--target base|agent] [--agent-tag]
_usage="Usage: $0 [--push] [--local-file] [--target base|agent] [--agent-tag]
Build the antrea base image.
--push Push the built image to the registry
--target Target container image to build.
Expand Down Expand Up @@ -91,7 +91,11 @@ 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}"
image_name="antrea-windows"
BUILD_TAG="${AGENT_TAG}"
if $PUSH ; then
BUILD_TAG="${AGENT_TAG}"
else
BUILD_TAG="latest"
fi
popd > /dev/null
ANTREA_DIR=${THIS_DIR}/../../../
pushd $ANTREA_DIR > /dev/null
Expand Down
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 @@ -53,6 +53,27 @@ data:
# Install OVS Driver
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"
Expand Down Expand Up @@ -293,7 +314,7 @@ spec:
template:
metadata:
annotations:
checksum/agent-windows: bb43d8d5840ffd71ff946d44052fefc5bd88ca5ad58ac5048d85a5cf26a7ef13
checksum/agent-windows: 7c6d6d016033d2889e356a471b03bee3474d88501c964a0e12d34b2a548fc4fa
checksum/windows-config: 6ff4f8bd0b310ebe4d4612bdd9697ffb3d79e0e0eab3936420417dd5a8fc128d
microsoft.com/hostprocess-inherit-user: "true"
labels:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$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 @@ -11,6 +11,28 @@ if ($driverStatus -like '*not installed*') {
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
16 changes: 2 additions & 14 deletions ci/jenkins/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,9 @@ function deliver_antrea_linux_containerd {
}

function deliver_antrea_windows_containerd {
echo "===== Build Antrea Windows on Windows Jumper Node ====="
echo "==== Reverting Windows VM ${WIN_IMAGE_NODE} ====="
revert_snapshot_windows ${WIN_IMAGE_NODE}
echo "===== Build Antrea Windows ====="
rm -f antrea-windows.tar.gz
# Compress antrea repo and copy it to a Windows node
mkdir -p jenkins
tar --exclude='./jenkins' -czf jenkins/antrea_repo.tar.gz -C "$(pwd)" .
for i in `seq 2`; do
timeout 2m scp -o StrictHostKeyChecking=no -T jenkins/antrea_repo.tar.gz Administrator@${IP}: && break
done
ssh -o StrictHostKeyChecking=no -n Administrator@${IP} "docker pull ${DOCKER_REGISTRY}/antrea/golang:${GO_VERSION}-nanoserver && docker tag ${DOCKER_REGISTRY}/antrea/golang:${GO_VERSION}-nanoserver golang:${GO_VERSION}-nanoserver"
ssh -o StrictHostKeyChecking=no -n Administrator@${IP} "rm -rf antrea && mkdir antrea && cd antrea && tar -xzf ../antrea_repo.tar.gz > /dev/null && NO_PULL=${NO_PULL}; DOCKER_NETWORK=host make build-windows && docker save -o antrea-windows.tar antrea/antrea-windows:latest && gzip -f antrea-windows.tar" || true
for i in `seq 2`; do
timeout 2m scp -o StrictHostKeyChecking=no -T Administrator@${IP}:antrea/antrea-windows.tar.gz . && break
done
make build-windows

echo "===== Deliver Antrea Windows to Windows worker nodes and pull necessary images on Windows worker nodes ====="
sed -i 's/if (!(Test-Path $AntreaAgentConfigPath))/if ($true)/' hack/windows/Helper.psm1
Expand Down
81 changes: 32 additions & 49 deletions hack/build-antrea-windows-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,64 +66,47 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

pushd "$THIS_DIR/.." > /dev/null

NANOSERVER_VERSION=$(head -n 1 build/images/deps/nanoserver-version)
source "build/images/build-utils.sh"
source "build/images/build-tag.sh"
BUILD_TAG=$(build/images/build-tag.sh)

CNI_BINARIES_VERSION=$(head -n 1 build/images/deps/cni-binaries-version)
GO_VERSION=$(head -n 1 build/images/deps/go-version)
WIN_OVS_VERSION=$(head -n 1 build/images/deps/ovs-version-windows)
WIN_BUILD_OVS_TAG=$(echo $NANOSERVER_VERSION-$WIN_OVS_VERSION)
WIN_BUILD_TAG=$(echo $GO_VERSION $CNI_BINARIES_VERSION $NANOSERVER_VERSION| md5sum| head -c 10)

echo "WIN_BUILD_TAG=$WIN_BUILD_TAG"
OVS_VERSION=$(head -n 1 build/images/deps/ovs-version-windows)

if $PULL; then
docker pull mcr.microsoft.com/windows/servercore:$NANOSERVER_VERSION
docker pull golang:$GO_VERSION-nanoserver
docker pull mcr.microsoft.com/windows/nanoserver:$NANOSERVER_VERSION
docker pull mcr.microsoft.com/powershell:lts-nanoserver-$NANOSERVER_VERSION
docker pull antrea/windows-utility-base:$WIN_BUILD_TAG || true
docker pull antrea/windows-golang:$WIN_BUILD_TAG || true
docker pull antrea/base-windows:$WIN_BUILD_TAG || true
docker pull antrea/windows-ovs:$WIN_BUILD_OVS_TAG || true
docker pull alpine:3.14 || true
docker pull golang:$GO_VERSION || true
fi

cd build/images/base-windows
docker build --target windows-utility-base \
--cache-from antrea/windows-utility-base:$WIN_BUILD_TAG \
-t antrea/windows-utility-base:$WIN_BUILD_TAG \
--build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \
--build-arg NANOSERVER_VERSION=$NANOSERVER_VERSION .
docker build --target windows-golang \
--cache-from antrea/windows-golang:$WIN_BUILD_TAG \
-t antrea/windows-golang:$WIN_BUILD_TAG \
--build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \
--build-arg GO_VERSION=$GO_VERSION \
--build-arg NANOSERVER_VERSION=$NANOSERVER_VERSION .
docker build \
--cache-from antrea/windows-utility-base:$WIN_BUILD_TAG \
--cache-from antrea/windows-golang:$WIN_BUILD_TAG \
--cache-from antrea/base-windows:$WIN_BUILD_TAG \
-t antrea/base-windows:$WIN_BUILD_TAG \
--build-arg CNI_BINARIES_VERSION=$CNI_BINARIES_VERSION \
--build-arg GO_VERSION=$GO_VERSION \
--build-arg NANOSERVER_VERSION=$NANOSERVER_VERSION .
cd -

cd build/images/ovs

docker build --target windows-ovs -f Dockerfile.windows \
-t antrea/windows-ovs:$WIN_BUILD_OVS_TAG \
--build-arg WIN_OVS_VERSION=$WIN_OVS_VERSION \
--build-arg NANOSERVER_VERSION=$NANOSERVER_VERSION .
cd -

if $PUSH; then
docker push antrea/windows-utility-base:$WIN_BUILD_TAG
docker push antrea/windows-golang:$WIN_BUILD_TAG
docker push antrea/base-windows:$WIN_BUILD_TAG
docker push antrea/windows-ovs:$WIN_BUILD_OVS_TAG
image_output_type="type=registry"
base_image_output=${image_output_type}
ovs_image_output=${image_output_type}
export WINDOWS_PUSH=1
else
image_output_type="type=docker"
base_image_output="${image_output_type},dest=./base-windows.tar"
ovs_image_output="${image_output_type},dest=./ovs-windows.tar"
fi

export NO_PULL=1
repository="antrea"

switch_windows_buildx

pushd build/images/base-windows
docker buildx build --platform windows/amd64 \
-o ${base_image_output} \
-t "${repository}/base-windows":${BUILD_TAG} \
--build-arg CNI_BINARIES_VERSION=${CNI_BINARIES_VERSION} -f Dockerfile .
popd

pushd build/images/ovs
docker buildx build --platform windows/amd64 \
-o ${ovs_image_output} \
-t "${repository}/windows-ovs":${BUILD_TAG} \
--build-arg OVS_VERSION=${OVS_VERSION} -f Dockerfile.windows .
popd

make build-windows

Expand Down

0 comments on commit ded05d0

Please sign in to comment.