Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: build windows containers #1467

Merged
merged 22 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1467.added.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: build windows containers
51 changes: 50 additions & 1 deletion .github/workflows/dev_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,60 @@ jobs:
PLATFORM=${{ matrix.arch_os }} \
BUILD_TYPE_SUFFIX="-ubi"

build-windows-container-images:
name: Build Windows container
runs-on: ${{ matrix.runs-on }}
needs:
- build
strategy:
matrix:
include:
- arch_os: windows_amd64
base_image_tag: ltsc2022
runs-on: windows-2022
- arch_os: windows_amd64
base_image_tag: ltsc2019
runs-on: windows-2019
steps:
- uses: actions/checkout@v4

- name: Extract tag
id: extract_tag
run: echo "tag=$(git rev-parse HEAD)" > $GITHUB_OUTPUT

- name: Print tag
run: echo "Running dev build for ${{ steps.extract_tag.outputs.tag }}"

- name: Login to Open Source ECR
run: |
USERNAME=$(powershell.exe "echo \$Env:UserName")
# remove wincred entry and fix json format by replacing }, with }
cat "C:\\Users\\${USERNAME}\\.docker\\config.json" | grep -v "wincred" | sed 's/},$/}/' > "C:\\Users\\${USERNAME}\\.docker\\config.json.tmp"
mv "C:\\Users\\${USERNAME}\\.docker\\config.json.tmp" "C:\\Users\\${USERNAME}\\.docker\\config.json"
make login
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_DEV }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }}

- name: Download binary action artifact from build phase
uses: actions/download-artifact@v4
with:
name: otelcol-sumo-${{matrix.arch_os}}.exe
path: artifacts/

- name: Build and push images to Open Source ECR
run: |
cp artifacts/otelcol-sumo-${{matrix.arch_os}}.exe otelcol-sumo.exe
make build-push-container-windows-dev \
BUILD_TAG=${{ steps.extract_tag.outputs.tag }} \
PLATFORM=${{ matrix.arch_os }}_${{ matrix.base_image_tag }}

push-docker-manifest:
name: Push joint container manifest
runs-on: ubuntu-20.04
needs:
- build-container-images
- build-windows-container-images
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -240,7 +289,7 @@ jobs:
run: |
make push-container-manifest-dev \
BUILD_TAG=${{ steps.extract_tag.outputs.tag }} \
PLATFORMS="linux/amd64 linux/arm64"
PLATFORMS="linux/amd64 linux/arm64 windows/amd64/ltsc2022 windows/amd64/ltsc2019"

- name: Push joint UBI-based container manifest for all platforms to Open Source ECR
run: |
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,54 @@ jobs:
- name: Test built FIPS image
if: steps.changed-files.outputs.any_changed == 'true' && matrix.arch_os == 'linux_amd64'
run: make test-built-image BUILD_TAG="latest-fips"

build-windows-container:
name: Build windows container
needs:
- build
runs-on: ${{ matrix.runs-on }}
strategy:
matrix:
include:
- arch_os: windows_amd64
base_image_tag: ltsc2022
runs-on: windows-2022
- arch_os: windows_amd64
base_image_tag: ltsc2019
runs-on: windows-2019
steps:
- uses: actions/checkout@v4

- name: Check if build related files changed
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: |
**/go.mod
**/go.sum
**/*.go
**/*.yaml
**/*.yml
**/Makefile
**/Makefile.common
**/Dockerfile*

- name: Download binary action artifact from build phase
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/download-artifact@v4
with:
name: otelcol-sumo-${{matrix.arch_os}}.exe
path: artifacts/

- name: Build the container image
if: steps.changed-files.outputs.any_changed == 'true'
run: |
cp artifacts/otelcol-sumo-${{matrix.arch_os}}.exe otelcol-sumo.exe
make build-container-windows \
PLATFORM=${{ matrix.arch_os }}_${{ matrix.base_image_tag }}

- name: Test built image
if: steps.changed-files.outputs.any_changed == 'true'
run: make test-built-image

# ToDo: build windows FIPS image
8 changes: 8 additions & 0 deletions Dockerfile_windows
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ARG BASE_IMAGE_TAG=ltsc2022
FROM mcr.microsoft.com/windows/servercore:${BASE_IMAGE_TAG}
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"]
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ OPENSOURCE_ECR_URL = public.ecr.aws/sumologic
OPENSOURCE_REPO_URL = $(OPENSOURCE_ECR_URL)/$(IMAGE_NAME)
OPENSOURCE_REPO_URL_DEV = $(OPENSOURCE_ECR_URL)/$(IMAGE_NAME_DEV)
REPO_URL = $(OPENSOURCE_REPO_URL)
BASE_IMAGE_TAG ?= ""

DOCKERFILE = Dockerfile

Expand Down Expand Up @@ -280,6 +281,10 @@ build-container-multiplatform-dev: build-container-multiplatform
build-push-container-multiplatform-dev: REPO_URL = "$(OPENSOURCE_REPO_URL_DEV)"
build-push-container-multiplatform-dev: build-push-container-multiplatform

.PHONY: build-push-container-windows-dev
build-push-container-windows-dev: DOCKERFILE = Dockerfile_windows
build-push-container-windows-dev: build-push-container-multiplatform-dev

.PHONY: push-container-manifest-dev
push-container-manifest-dev: REPO_URL = "$(OPENSOURCE_REPO_URL_DEV)"
push-container-manifest-dev: push-container-manifest
Expand All @@ -298,11 +303,26 @@ _build-container-multiplatform:
REPO_URL="$(REPO_URL)" \
DOCKERFILE="$(DOCKERFILE)" \
PLATFORM="$(PLATFORM)" \
BASE_IMAGE_TAG="${BASE_IMAGE_TAG}" \
./ci/build-push-multiplatform.sh $(PUSH)

.PHONY: build-container-multiplatform
build-container-multiplatform: _build-container-multiplatform

.PHONY: build-container-windows
build-container-windows:
$(MAKE) _build-container-multiplatform \
DOCKERFILE=Dockerfile_windows \
BASE_IMAGE_TAG=ltsc2022

$(MAKE) _build-container-multiplatform \
DOCKERFILE=Dockerfile_windows \
BASE_IMAGE_TAG=ltsc2019

.PHONY: build-push-container-windows
build-push-container-windows: PUSH = --push
build-push-container-windows: build-container-windows

.PHONY: build-push-container-multiplatform
build-push-container-multiplatform: PUSH = --push
build-push-container-multiplatform: _build-container-multiplatform
Expand Down
126 changes: 93 additions & 33 deletions ci/build-push-multiplatform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

set -eo pipefail

while ! docker buildx ls; do
echo "Cannot connect to docker daemon"
sleep 1
done
if echo "${PLATFORM}" | grep -v windows; then

DOCKER_BUILDX_LS_OUT=$(docker buildx ls <<-END
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
Expand All @@ -33,6 +31,10 @@ if [[ -z "${REPO_URL}" ]]; then
exit 1
fi

if [[ ! -z "${BASE_IMAGE_TAG}" ]]; then
BASE_IMAGE_TAG="-${BASE_IMAGE_TAG}"
fi

if [[ -z "${PLATFORM}" ]]; then
echo "No PLATFORM passed in"
exit 1
Expand All @@ -52,19 +54,44 @@ fi
# linux/arm/v7, linux/arm/v6
function build_push() {
local BUILD_ARCH
local BASE_IMAGE_TAG_SUFFIX
set -x

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 BASE_IMAGE_TAG_SUFFIX="windows"
PLATFORM="windows/amd64"
;;

"windows/amd64/ltsc2022"|"windows_amd64_ltsc2022")
readonly BUILD_ARCH="amd64"
readonly BUILD_PLATFORM="windows"
readonly BASE_IMAGE_TAG_SUFFIX="-ltsc2022"
readonly BASE_IMAGE_TAG="ltsc2022"
PLATFORM="windows/amd64"
;;

"windows/amd64/ltsc2019"|"windows_amd64_ltsc2019")
readonly BUILD_ARCH="amd64"
readonly BUILD_PLATFORM="windows"
readonly BASE_IMAGE_TAG_SUFFIX="-ltsc2019"
readonly BASE_IMAGE_TAG="ltsc2019"
PLATFORM="windows/amd64"
;;

# Can't really enable it for now because:
# !shopify/[email protected]/gssapi_kerberos.go:62:10: constant 4294967295 overflows int
# ref: https://github.com/SumoLogic/sumologic-otel-collector/runs/2805247906
Expand All @@ -82,33 +109,66 @@ 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}${BASE_IMAGE_TAG_SUFFIX}"
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}${BASE_IMAGE_TAG_SUFFIX}"

# --provenance=false for docker buildx ensures that we create manifest instead of manifest list
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 \
Copy link
Contributor

@rnishtala-sumo rnishtala-sumo Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we tried downloading the unattended installation of the buildx component from here?, looks like there are windows executables

https://github.com/docker/buildx?tab=readme-ov-file#manual-download

Binaries from the github release page
https://github.com/docker/buildx/releases/tag/v0.12.1

got the above from this comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nvm, looks like this is the root cause - docker/buildx#176, buildx on windows containers not supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe it is suppored, but I would prefer to have more control over what happening with windows image builds and also avoid experimenting support. I would feel more comfortable to switch to it when it will be fully supported, or maybe if we go for FIPS/arm64

--file "${DOCKERFILE}" \
--build-arg BUILD_TAG="${BUILD_TAG}" \
--build-arg BASE_IMAGE_TAG="${BASE_IMAGE_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 BASE_IMAGE_TAG="${BASE_IMAGE_TAG}" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--platform="${PLATFORM}" \
--tag "${LATEST_TAG}" \
--tag "${TAG}" \
--provenance=false \
sumo-drosiek marked this conversation as resolved.
Show resolved Hide resolved
.
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="latest${BUILD_TYPE_SUFFIX}" \
--build-arg BASE_IMAGE_TAG="${BASE_IMAGE_TAG}" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--platform="${PLATFORM}" \
--tag "${REPO_URL}:latest${BUILD_TYPE_SUFFIX}" \
.
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 BASE_IMAGE_TAG="${BASE_IMAGE_TAG}" \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--platform="${PLATFORM}" \
--load \
--tag "${REPO_URL}:latest${BUILD_TYPE_SUFFIX}" \
sumo-drosiek marked this conversation as resolved.
Show resolved Hide resolved
--provenance=false \
.
fi
fi
}

Expand Down
Loading