Skip to content

Commit

Permalink
added windows 2022 support (#1057)
Browse files Browse the repository at this point in the history
Co-authored-by: Lu-David <[email protected]>
  • Loading branch information
Lu-David and Lu-David authored Sep 3, 2024
1 parent eb3c7d0 commit 79488f8
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 24 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
9 changes: 6 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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 }}
46 changes: 37 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions scripts/build-binaries
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions scripts/build-docker-images
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
15 changes: 13 additions & 2 deletions scripts/push-docker-images
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 79488f8

Please sign in to comment.