From 79488f8f2329470e90f1d1b939f837ad826324f4 Mon Sep 17 00:00:00 2001 From: David Lu <45726258+Lu-David@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:30:54 -0700 Subject: [PATCH] added windows 2022 support (#1057) Co-authored-by: Lu-David --- .github/workflows/build-and-test.yaml | 16 +++++++--- .github/workflows/release.yaml | 9 ++++-- Makefile | 46 +++++++++++++++++++++------ scripts/build-binaries | 4 +-- scripts/build-docker-images | 9 ++++-- scripts/push-docker-images | 15 +++++++-- 6 files changed, 75 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 1d02c282..7bb817f6 100755 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -124,7 +124,10 @@ jobs: buildWindows: name: Build Windows Binaries - runs-on: windows-2019 + strategy: + matrix: + version: [2019, 2022] + runs-on: windows-${{matrix.version}} steps: - name: Set up Go 1.x uses: actions/setup-go@v2 @@ -149,11 +152,14 @@ jobs: Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" refreshenv - choco install make && choco install zip && make build-binaries-windows + choco install make && choco install zip && make build-binaries-windows-${{matrix.version}} buildWindowsDocker: name: Build Windows Docker Images - runs-on: windows-2019 + strategy: + matrix: + version: [2019, 2022] + runs-on: windows-${{matrix.version}} steps: - name: Set up Go 1.x uses: actions/setup-go@v2 @@ -178,7 +184,7 @@ jobs: Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" refreshenv - choco install make && make build-docker-images-windows + choco install make && make build-docker-images-windows-${{matrix.version}} e2e: name: E2E Tests @@ -205,4 +211,4 @@ jobs: key: gocache - name: E2E Tests - run: test/k8s-local-cluster-test/run-test -v ${{ matrix.k8sVersion }} + run: test/k8s-local-cluster-test/run-test -v ${{ matrix.k8sVersion }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 7516ca58..14fb1346 100755 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -36,8 +36,11 @@ jobs: releaseWindows: name: Release Windows - runs-on: windows-2019 needs: [releaseLinux] + strategy: + matrix: + version: [2019, 2022] + runs-on: windows-${{matrix.version}} steps: - name: Set up Go 1.x uses: actions/setup-go@v2 @@ -53,7 +56,7 @@ jobs: Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" refreshenv - choco install make && choco install zip && make release-windows + choco install make && choco install zip && make release-windows-${{matrix.version}} env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -91,4 +94,4 @@ jobs: env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} + AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} \ No newline at end of file diff --git a/Makefile b/Makefile index 6aa588df..8dd557f2 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,16 @@ MAKEFILE_PATH = $(dir $(realpath -s $(firstword $(MAKEFILE_LIST)))) BUILD_DIR_PATH = ${MAKEFILE_PATH}/build BIN_DIR = ${MAKEFILE_PATH}/bin SUPPORTED_PLATFORMS_LINUX ?= "linux/amd64,linux/arm64" -SUPPORTED_PLATFORMS_WINDOWS ?= "windows/amd64" + +# Each windows version needs a separate make target because each build +# needs to happen on a separate GitHub runner +# A windows version is specified by major-minor-build-revision. +# The build number of the OS must match the build number of the container image +# The revision does not matter for windows 2019 and 2022. +# Reference: https://learn.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/version-compatibility +WINDOWS_2019 ?= "windows-10.0.17763.6189/amd64" +WINDOWS_2022 ?= "windows-10.0.20348.2582/amd64" + BINARY_NAME ?= "node-termination-handler" THIRD_PARTY_LICENSES = "${MAKEFILE_PATH}/THIRD_PARTY_LICENSES.md" GOLICENSES = $(BIN_DIR)/go-licenses @@ -48,18 +57,32 @@ docker-run: build-docker-images: ${MAKEFILE_PATH}/scripts/build-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${IMG} -v ${VERSION} -build-docker-images-windows: - ${MAKEFILE_PATH}/scripts/build-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${IMG} -v ${VERSION} +build-docker-images-windows-2019: + ${MAKEFILE_PATH}/scripts/build-docker-images -p ${WINDOWS_2019} -r ${IMG} -v ${VERSION} + +build-docker-images-windows-2022: + ${MAKEFILE_PATH}/scripts/build-docker-images -p ${WINDOWS_2022} -r ${IMG} -v ${VERSION} + +ecr-public-login: + @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login push-docker-images: ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/ecr-public-login ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_LINUX} -r ${ECR_REPO} -v ${VERSION} -m -push-docker-images-windows: - ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} +amazon-ecr-credential-helper: bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION) - ${MAKEFILE_PATH}/scripts/push-docker-images -p ${SUPPORTED_PLATFORMS_WINDOWS} -r ${ECR_REPO} -v ${VERSION} -m + +push-docker-images-windows-2019: + ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${WINDOWS_2019} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} + bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION) + ${MAKEFILE_PATH}/scripts/push-docker-images -p ${WINDOWS_2019} -r ${ECR_REPO} -v ${VERSION} -m + +push-docker-images-windows-2022: + ${MAKEFILE_PATH}/scripts/retag-docker-images -p ${WINDOWS_2022} -v ${VERSION} -o ${IMG} -n ${ECR_REPO} + bash ${MAKEFILE_PATH}/scripts/install-amazon-ecr-credential-helper $(AMAZON_ECR_CREDENTIAL_HELPER_VERSION) + ${MAKEFILE_PATH}/scripts/push-docker-images -p ${WINDOWS_2022} -r ${ECR_REPO} -v ${VERSION} -m push-helm-chart: @ECR_REGISTRY=${ECR_REGISTRY} ${MAKEFILE_PATH}/scripts/helm-login @@ -122,8 +145,11 @@ helm-validate-chart-versions: build-binaries: ${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS_LINUX} -v ${VERSION} -build-binaries-windows: - ${MAKEFILE_PATH}/scripts/build-binaries -p ${SUPPORTED_PLATFORMS_WINDOWS} -v ${VERSION} +build-binaries-windows-2019: + ${MAKEFILE_PATH}/scripts/build-binaries -p ${WINDOWS_2019} -v ${VERSION} + +build-binaries-windows-2022: + ${MAKEFILE_PATH}/scripts/build-binaries -p ${WINDOWS_2022} -v ${VERSION} upload-resources-to-github: ${MAKEFILE_PATH}/scripts/upload-resources-to-github @@ -165,7 +191,9 @@ eks-cluster-test: release: build-binaries build-docker-images push-docker-images generate-k8s-yaml upload-resources-to-github -release-windows: build-binaries-windows build-docker-images-windows push-docker-images-windows +release-windows-2019: build-binaries-windows-2019 build-docker-images-windows-2019 push-docker-images-windows-2019 + +release-windows-2022: build-binaries-windows-2022 build-docker-images-windows-2022 push-docker-images-windows-2022 test: spellcheck shellcheck unit-test e2e-test compatibility-test license-test go-linter helm-version-sync-test helm-lint diff --git a/scripts/build-binaries b/scripts/build-binaries index cbb7ca53..3d6325ed 100755 --- a/scripts/build-binaries +++ b/scripts/build-binaries @@ -49,7 +49,7 @@ for os_arch in "${PLATFORMS[@]}"; do container_name="build-$BASE_BIN_NAME-$os-$arch" repo_name="bin-build" - if [[ $os == "windows" ]]; then + if [[ $os == "windows"* ]]; then bin_name="$BASE_BIN_NAME-$os-$arch.exe" else bin_name="$BASE_BIN_NAME-$os-$arch" @@ -60,7 +60,7 @@ for os_arch in "${PLATFORMS[@]}"; do docker container create --rm --name $container_name "$repo_name:$VERSION-$os-$arch" docker container cp $container_name:/${BASE_BIN_NAME} $BIN_DIR/$bin_name - if [[ $os == "windows" ]]; then + if [[ $os == "windows"* ]]; then ## Create zip archive with binary taking into account windows .exe cp ${BIN_DIR}/${bin_name} ${BIN_DIR}/${BASE_BIN_NAME}.exe ## Can't reuse bin_name below because it includes .exe diff --git a/scripts/build-docker-images b/scripts/build-docker-images index 5078daa3..86a3e959 100755 --- a/scripts/build-docker-images +++ b/scripts/build-docker-images @@ -48,20 +48,23 @@ for os_arch in "${PLATFORMS[@]}"; do os=$(echo $os_arch | cut -d'/' -f1) arch=$(echo $os_arch | cut -d'/' -f2) - img_tag="$IMAGE_REPO:$VERSION-$os-$arch" - dockerfile="$DOCKERFILE_PATH" - if [[ $os = "windows" ]]; then + if [[ $os == "windows"* ]]; then + windows_version=$(echo $os | cut -d'-' -f2) + os=$(echo $os | cut -d'-' -f1) + img_tag="$IMAGE_REPO:$VERSION-$os-$windows_version-$arch" dockerfile="${dockerfile}.windows" docker build \ --file "${dockerfile}" \ --build-arg GOOS=${os} \ --build-arg GOARCH=${arch} \ + --build-arg WINDOWS_VERSION=${windows_version} \ --build-arg GOPROXY=${GOPROXY} \ --tag ${img_tag} \ ${REPO_ROOT_PATH} else # Launch a docker buildx instance and save its name so we can terminate it later + img_tag="$IMAGE_REPO:$VERSION-$os-$arch" buildx_instance_name=$(docker buildx create --use) docker buildx build \ --load \ diff --git a/scripts/push-docker-images b/scripts/push-docker-images index 6080d061..f0bf7474 100755 --- a/scripts/push-docker-images +++ b/scripts/push-docker-images @@ -68,9 +68,17 @@ if [[ $MANIFEST == "true" ]]; then if [[ manifest_exists -eq 0 ]]; then echo "manifest already exists" EXISTING_IMAGES=() + + # Run while loop to collect images with no OS version (typically linux) + while IFS='' read -r line; do + EXISTING_IMAGES+=("$line"); + done < <(docker manifest inspect $IMAGE_REPO:$VERSION | jq -r '.manifests[] | select(.platform."os.version" == null) | "\(.platform.os)-\(.platform.architecture)"') + + # Run while loop to collect images with OS version (typically windows) while IFS='' read -r line; do EXISTING_IMAGES+=("$line"); - done < <(docker manifest inspect $IMAGE_REPO:$VERSION | jq -r '.manifests[] | "\(.platform.os)-\(.platform.architecture)"') + done < <(docker manifest inspect $IMAGE_REPO:$VERSION | jq -r '.manifests[] | select(.platform."os.version" != null) | "\(.platform.os)-\(.platform."os.version")-\(.platform.architecture)"') + # treat separate from PLATFORMS because existing images don't need to be tagged and pushed for os_arch in "${EXISTING_IMAGES[@]}"; do img_tag="$IMAGE_REPO:$VERSION-$os_arch" @@ -117,7 +125,10 @@ if [[ $MANIFEST == "true" ]]; then # However, our builds in the past required this explicit annotation, and it doesn't hurt to keep it for now. os_arch=$(echo ${updated_img//$IMAGE_REPO:$VERSION-/}) os=$(echo $os_arch | cut -d'-' -f1) - arch=$(echo $os_arch | cut -d'-' -f2) + + # os_arch may be linux-amd64 or windows-10.0.17763.6189-amd64. To get the proper architecture, the bash command + # will extract the last element after the hyphen (-). + arch=${os_arch##*-} echo "annotating manifest" docker manifest annotate $IMAGE_REPO:$VERSION $updated_img --arch $arch --os $os