From 4e81aba1af6de3166433a815aba6cc041f18fa67 Mon Sep 17 00:00:00 2001 From: Dominik Rosiek Date: Tue, 27 Feb 2024 22:03:12 +0100 Subject: [PATCH] feat: support bulding windows image in ci/build-push-multiplatform.sh Signed-off-by: Dominik Rosiek --- .github/workflows/pull_requests.yml | 4 +- Dockerfile_windows | 6 +- Makefile | 11 +-- ci/build-push-multiplatform.sh | 115 ++++++++++++++++------- ci/push_docker_multiplatform_manifest.sh | 15 ++- 5 files changed, 101 insertions(+), 50 deletions(-) diff --git a/.github/workflows/pull_requests.yml b/.github/workflows/pull_requests.yml index 3c20d0b564..9366d6acb6 100644 --- a/.github/workflows/pull_requests.yml +++ b/.github/workflows/pull_requests.yml @@ -396,7 +396,9 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: | cp artifacts/otelcol-sumo-${{matrix.arch_os}}.exe otelcol-sumo.exe - make build-push-container-windows + make build-container-multiplatform \ + PLATFORM=${{ matrix.arch_os }} \ + DOCKERFILE=Dockerfile_windows - name: Test built image if: steps.changed-files.outputs.any_changed == 'true' diff --git a/Dockerfile_windows b/Dockerfile_windows index 4e722a38f4..2c25ca6a71 100644 --- a/Dockerfile_windows +++ b/Dockerfile_windows @@ -1,3 +1,7 @@ -FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 +FROM mcr.microsoft.com/windows/servercore:ltsc2019 +ARG BUILD_TAG=latest +ENV TAG $BUILD_TAG + ADD /otelcol-sumo.exe /otelcol-sumo.exe ENTRYPOINT ["/otelcol-sumo.exe"] +CMD ["--config", "/etc/otel/config.yaml"] diff --git a/Makefile b/Makefile index 4bff8d5635..c3186f0fa0 100644 --- a/Makefile +++ b/Makefile @@ -300,15 +300,6 @@ _build-container-multiplatform: PLATFORM="$(PLATFORM)" \ ./ci/build-push-multiplatform.sh $(PUSH) -.PHONY: _build-container-windows -_build-container-windows: - docker \ - build \ - -f $(DOCKERFILE) \ - . \ - -t ${REPO_URL}/${BUILD_TAG}-windows \ - --platform="$(PLATFORM)" - .PHONY: build-container-multiplatform build-container-multiplatform: _build-container-multiplatform @@ -324,7 +315,7 @@ build-push-container-ubi: _build-container-multiplatform .PHONY: build-push-container-windows build-push-container-windows: PUSH = --push build-push-container-windows: DOCKERFILE = Dockerfile_windows -build-push-container-windows: _build-container-windows +build-push-container-windows: _build-container-multiplatform .PHONY: test-built-image test-built-image: diff --git a/ci/build-push-multiplatform.sh b/ci/build-push-multiplatform.sh index f2844e23d0..d84395331a 100755 --- a/ci/build-push-multiplatform.sh +++ b/ci/build-push-multiplatform.sh @@ -2,21 +2,29 @@ set -eo pipefail -while ! docker buildx ls; do - echo "Cannot connect to docker daemon" - sleep 1 -done - -DOCKER_BUILDX_LS_OUT=$(docker buildx ls <<-END +if echo "${PLATFORM}" | grep windows; then + echo '' + # while ! docker images; do + # echo "Cannot connect to docker daemon" + # sleep 1 + # done +else + while ! docker buildx ls; do + echo "Cannot connect to docker daemon" + sleep 1 + done + + DOCKER_BUILDX_LS_OUT=$(docker buildx ls <<-END END -) -readonly DOCKER_BUILDX_LS_OUT + ) + readonly DOCKER_BUILDX_LS_OUT -# check for arm support only if we try to build it -if echo "${PLATFORM}" | grep -q arm && ! grep -q arm <<< "${DOCKER_BUILDX_LS_OUT}"; then - echo "Your Buildx seems to lack ARM architecture support" - echo "${DOCKER_BUILDX_LS_OUT}" - exit 1 + # check for arm support only if we try to build it + if echo "${PLATFORM}" | grep -q arm && ! grep -q arm <<< "${DOCKER_BUILDX_LS_OUT}"; then + echo "Your Buildx seems to lack ARM architecture support" + echo "${DOCKER_BUILDX_LS_OUT}" + exit 1 + fi fi if [[ -z "${BUILD_TAG}" ]]; then @@ -57,14 +65,22 @@ function build_push() { case "${PLATFORM}" in "linux/amd64"|"linux_amd64") readonly BUILD_ARCH="amd64" + readonly BUILD_PLATFORM="linux" PLATFORM="linux/amd64" ;; "linux/arm64"|"linux_arm64") readonly BUILD_ARCH="arm64" + readonly BUILD_PLATFORM="linux" PLATFORM="linux/arm64" ;; + "windows/amd64"|"windows_amd64") + readonly BUILD_ARCH="amd64" + readonly BUILD_PLATFORM="windows" + PLATFORM="windows/amd64" + ;; + # Can't really enable it for now because: # !shopify/sarama@v1.29.0/gssapi_kerberos.go:62:10: constant 4294967295 overflows int # ref: https://github.com/SumoLogic/sumologic-otel-collector/runs/2805247906 @@ -82,33 +98,64 @@ function build_push() { esac local TAG - readonly TAG="${REPO_URL}:${BUILD_TAG}${BUILD_TYPE_SUFFIX}-${BUILD_ARCH}" + readonly TAG="${REPO_URL}:${BUILD_TAG}${BUILD_TYPE_SUFFIX}-${BUILD_PLATFORM}-${BUILD_ARCH}" local LATEST_TAG - readonly LATEST_TAG="${REPO_URL}:latest${BUILD_TYPE_SUFFIX}-${BUILD_ARCH}" + readonly LATEST_TAG="${REPO_URL}:latest${BUILD_TYPE_SUFFIX}-${BUILD_PLATFORM}-${BUILD_ARCH}" if [[ "${PUSH}" == true ]]; then echo "Building tags: ${TAG}, ${LATEST_TAG}" - docker buildx build \ - --push \ - --file "${DOCKERFILE}" \ - --build-arg BUILD_TAG="${BUILD_TAG}" \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - --platform="${PLATFORM}" \ - --tag "${LATEST_TAG}" \ - --tag "${TAG}" \ - . + + if [[ "${BUILD_PLATFORM}" == "windows" ]]; then + docker build \ + --file "${DOCKERFILE}" \ + --build-arg BUILD_TAG="${BUILD_TAG}" \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + --platform="${PLATFORM}" \ + --tag "${LATEST_TAG}" \ + . + + docker tag "${LATEST_TAG}" "${TAG}" + + docker push "${LATEST_TAG}" + docker push "${TAG}" + else + docker buildx build \ + --push \ + --file "${DOCKERFILE}" \ + --build-arg BUILD_TAG="${BUILD_TAG}" \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + --platform="${PLATFORM}" \ + --tag "${LATEST_TAG}" \ + --tag "${TAG}" \ + . + fi else echo "Building tag: latest${BUILD_TYPE_SUFFIX}" - # load flag is needed so that docker loads this image - # for subsequent steps on github actions - docker buildx build \ - --file "${DOCKERFILE}" \ - --build-arg BUILD_TAG="latest${BUILD_TYPE_SUFFIX}" \ - --build-arg BUILDKIT_INLINE_CACHE=1 \ - --platform="${PLATFORM}" \ - --load \ - --tag "${REPO_URL}:latest${BUILD_TYPE_SUFFIX}" \ - . + if [[ "${BUILD_PLATFORM}" == "windows" ]]; then + docker build \ + --file "${DOCKERFILE}" \ + --build-arg BUILD_TAG="${BUILD_TAG}" \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + --platform="${PLATFORM}" \ + --tag "${REPO_URL}:latest${BUILD_TYPE_SUFFIX}" \ + . + + docker tag "${LATEST_TAG}" "${TAG}" + + docker push "${LATEST_TAG}" + docker push "${TAG}" + else + # load flag is needed so that docker loads this image + # for subsequent steps on github actions + docker buildx build \ + --file "${DOCKERFILE}" \ + --build-arg BUILD_TAG="latest${BUILD_TYPE_SUFFIX}" \ + --build-arg BUILDKIT_INLINE_CACHE=1 \ + --platform="${PLATFORM}" \ + --load \ + --tag "${REPO_URL}:latest${BUILD_TYPE_SUFFIX}" \ + . + fi fi } diff --git a/ci/push_docker_multiplatform_manifest.sh b/ci/push_docker_multiplatform_manifest.sh index 13003900d1..71868b9ea1 100755 --- a/ci/push_docker_multiplatform_manifest.sh +++ b/ci/push_docker_multiplatform_manifest.sh @@ -39,24 +39,31 @@ function push_manifest() { echo "${platform}" case "${platform}" in "linux/amd64") - BUILD_ARCH="amd64" + readonly BUILD_ARCH="amd64" + readonly BUILD_PLATFORM="linux" ;; "linux/arm64") - BUILD_ARCH="arm64" + readonly BUILD_ARCH="arm64" + readonly BUILD_PLATFORM="linux" ;; "linux/arm/v7") - BUILD_ARCH="arm_v7" + readonly BUILD_ARCH="arm_v7" + readonly BUILD_PLATFORM="linux" ;; + "windows/amd64") + readonly BUILD_ARCH="amd64" + readonly BUILD_PLATFORM="windows" + ;; *) echo "Unsupported platform ${platform}" exit 1 ;; esac - TAGS_IN_MANIFEST+=("${REPO_URL}:${BUILD_TAG}-${BUILD_ARCH}") + TAGS_IN_MANIFEST+=("${REPO_URL}:${BUILD_TAG}-${BUILD_PLATFORM}-${BUILD_ARCH}") done echo "Tags in the manifest:"