From c90557a37ece449cfbd04d63ecc57d45c4cfd39c Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Fri, 5 Apr 2024 14:36:23 -0400 Subject: [PATCH] Docker: fix Windows container * Fix CI job to check Windows container builds properly * Ensures Windows containers end in `-nanoserver-1809` as is our new convention * Add `make alloy-image-windows` target to Makefile * Apply previous fixes to dev container --- .drone/drone.yml | 12 ++- .drone/pipelines/check_containers.jsonnet | 4 +- .drone/pipelines/publish.jsonnet | 17 +-- .drone/util/pipelines.jsonnet | 2 + Makefile | 117 +++++++++++---------- docs/sources/get-started/install/docker.md | 2 +- tools/ci/docker-containers-windows | 6 +- 7 files changed, 90 insertions(+), 70 deletions(-) diff --git a/.drone/drone.yml b/.drone/drone.yml index ee7d7e773f..1481accf81 100644 --- a/.drone/drone.yml +++ b/.drone/drone.yml @@ -101,7 +101,7 @@ platform: version: "1809" steps: - commands: - - '& "C:/Program Files/git/bin/bash.exe" ./tools/ci/docker-containers-windows alloy' + - '& "C:/Program Files/git/bin/bash.exe" -c "make alloy-image-windows"' image: grafana/agent-build-image:0.40.2-windows name: Build container volumes: @@ -302,12 +302,18 @@ platform: version: "1809" steps: - commands: - - '& "C:/Program Files/git/bin/bash.exe" ./tools/ci/docker-containers-windows alloy-devel' + - '& "C:/Program Files/git/bin/bash.exe" -c "mkdir -p $HOME/.docker"' + - '& "C:/Program Files/git/bin/bash.exe" -c "printenv GCR_CREDS > $HOME/.docker/config.json"' + - '& "C:/Program Files/git/bin/bash.exe" -c "docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD"' + - '& "C:/Program Files/git/bin/bash.exe" -c "./tools/ci/docker-containers-windows + alloy-devel"' environment: DOCKER_LOGIN: from_secret: docker_login DOCKER_PASSWORD: from_secret: docker_password + GCR_CREDS: + from_secret: gcr_admin image: grafana/agent-build-image:0.40.2-windows name: Build containers volumes: @@ -559,6 +565,6 @@ kind: secret name: updater_private_key --- kind: signature -hmac: 21df6cb02f24c4eab41dc3425f43c865141d400b2ad00571bde9a1803577e77c +hmac: 33ad6940aa3d0615eb3be75bbeee0a90910b5b03280c1a80cc664abeb0de2932 ... diff --git a/.drone/pipelines/check_containers.jsonnet b/.drone/pipelines/check_containers.jsonnet index 29ee6e957b..864a25a692 100644 --- a/.drone/pipelines/check_containers.jsonnet +++ b/.drone/pipelines/check_containers.jsonnet @@ -6,7 +6,7 @@ local linux_containers = [ ]; local windows_containers = [ - { name: 'grafana/alloy', argument: 'alloy', path: 'Dockerfile.windows' }, + { name: 'grafana/alloy', make: 'make alloy-image-windows', path: 'Dockerfile.windows' }, ]; ( @@ -45,7 +45,7 @@ local windows_containers = [ path: '//./pipe/docker_engine/', }], commands: [ - '& "C:/Program Files/git/bin/bash.exe" ./tools/ci/docker-containers-windows %s' % container.argument, + '& "C:/Program Files/git/bin/bash.exe" -c "%s"' % container.make, ], }], volumes: [{ diff --git a/.drone/pipelines/publish.jsonnet b/.drone/pipelines/publish.jsonnet index cc035e76ba..8cbf491359 100644 --- a/.drone/pipelines/publish.jsonnet +++ b/.drone/pipelines/publish.jsonnet @@ -74,9 +74,13 @@ local windows_containers_dev_jobs = std.map(function(container) ( environment: { DOCKER_LOGIN: secrets.docker_login.fromSecret, DOCKER_PASSWORD: secrets.docker_password.fromSecret, + GCR_CREDS: secrets.gcr_admin.fromSecret, }, commands: [ - '& "C:/Program Files/git/bin/bash.exe" ./tools/ci/docker-containers-windows %s-devel' % container, + pipelines.windows_command('mkdir -p $HOME/.docker'), + pipelines.windows_command('printenv GCR_CREDS > $HOME/.docker/config.json'), + pipelines.windows_command('docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD'), + pipelines.windows_command('./tools/ci/docker-containers-windows %s-devel' % container), ], }], volumes: [{ @@ -137,9 +141,6 @@ local linux_containers_jobs = std.map(function(container) ( ), linux_containers); -local windows_bash_command = function(command) - '& "C:/Program Files/git/bin/bash.exe" -c "%s"' % command; - local windows_containers_jobs = std.map(function(container) ( pipelines.windows('Publish Windows %s container' % container) { trigger: { @@ -158,10 +159,10 @@ local windows_containers_jobs = std.map(function(container) ( GCR_CREDS: secrets.gcr_admin.fromSecret, }, commands: [ - windows_bash_command('mkdir -p $HOME/.docker'), - windows_bash_command('printenv GCR_CREDS > $HOME/.docker/config.json'), - windows_bash_command('docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD'), - windows_bash_command('./tools/ci/docker-containers-windows %s' % container), + pipelines.windows_command('mkdir -p $HOME/.docker'), + pipelines.windows_command('printenv GCR_CREDS > $HOME/.docker/config.json'), + pipelines.windows_command('docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD'), + pipelines.windows_command('./tools/ci/docker-containers-windows %s' % container), ], }], volumes: [{ diff --git a/.drone/util/pipelines.jsonnet b/.drone/util/pipelines.jsonnet index 83a140c7ef..4bfbd29fa1 100644 --- a/.drone/util/pipelines.jsonnet +++ b/.drone/util/pipelines.jsonnet @@ -19,4 +19,6 @@ version: '1809', }, }, + + windows_command(command):: '& "C:/Program Files/git/bin/bash.exe" -c "%s"' % command, } diff --git a/Makefile b/Makefile index cb93dc4069..de40637efe 100644 --- a/Makefile +++ b/Makefile @@ -17,34 +17,36 @@ ## ## test Run tests ## lint Lint code -## integration-test Run integration tests +## integration-test Run integration tests ## ## Targets for building binaries: ## -## binaries Compiles all binaries. -## alloy Compiles Alloy to $(ALLOY_BINARY) -## alloy-service Compiles internal/cmd/alloy-service to $(SERVICE_BINARY) +## binaries Compiles all binaries. +## alloy Compiles Alloy to $(ALLOY_BINARY) +## alloy-service Compiles internal/cmd/alloy-service to $(SERVICE_BINARY) ## ## Targets for building Docker images: ## -## images Builds all Docker images. -## alloy-image Builds alloy Docker image. +## images Builds all (Linux) Docker images. +## images-windows Builds all (Windows) Docker images. +## alloy-image Builds alloy Docker image. +## alloy-image-windows Builds alloy Docker image for Windows. ## ## Targets for packaging: ## -## dist Produce release assets for everything. -## dist-alloy-binaries Produce release-ready Alloy binaries. -## dist-packages Produce release-ready DEB and RPM packages. -## dist-alloy-installer Produce a Windows installer for Alloy. +## dist Produce release assets for everything. +## dist-alloy-binaries Produce release-ready Alloy binaries. +## dist-packages Produce release-ready DEB and RPM packages. +## dist-alloy-installer Produce a Windows installer for Alloy. ## ## Targets for generating assets: ## -## generate Generate everything. -## generate-drone Generate the Drone YAML from Jsonnet. -## generate-helm-docs Generate Helm chart documentation. -## generate-helm-tests Generate Helm chart tests. -## generate-ui Generate the UI assets. -## generate-versioned-files Generate versioned files. +## generate Generate everything. +## generate-drone Generate the Drone YAML from Jsonnet. +## generate-helm-docs Generate Helm chart documentation. +## generate-helm-tests Generate Helm chart tests. +## generate-ui Generate the UI assets. +## generate-versioned-files Generate versioned files. ## ## Other targets: ## @@ -57,38 +59,40 @@ ## ## Environment variables: ## -## USE_CONTAINER Set to 1 to enable proxying commands to build container -## ALLOY_IMAGE Image name:tag built by `make alloy-image` -## BUILD_IMAGE Image name:tag used by USE_CONTAINER=1 -## ALLOY_BINARY Output path of `make alloy` (default build/alloy) -## SERVICE_BINARY Output path of `make alloy-service` (default build/alloy-service) -## GOOS Override OS to build binaries for -## GOARCH Override target architecture to build binaries for -## GOARM Override ARM version (6 or 7) when GOARCH=arm -## CGO_ENABLED Set to 0 to disable Cgo for binaries. -## RELEASE_BUILD Set to 1 to build release binaries. -## VERSION Version to inject into built binaries. -## GO_TAGS Extra tags to use when building. -## DOCKER_PLATFORM Overrides platform to build Docker images for (defaults to host platform). -## GOEXPERIMENT Used to enable Go features behind feature flags. +## USE_CONTAINER Set to 1 to enable proxying commands to build container +## ALLOY_IMAGE Image name:tag built by `make alloy-image` +## ALLOY_IMAGE_WINDOWS Image name:tag built by `make alloy-image-windows` +## BUILD_IMAGE Image name:tag used by USE_CONTAINER=1 +## ALLOY_BINARY Output path of `make alloy` (default build/alloy) +## SERVICE_BINARY Output path of `make alloy-service` (default build/alloy-service) +## GOOS Override OS to build binaries for +## GOARCH Override target architecture to build binaries for +## GOARM Override ARM version (6 or 7) when GOARCH=arm +## CGO_ENABLED Set to 0 to disable Cgo for binaries. +## RELEASE_BUILD Set to 1 to build release binaries. +## VERSION Version to inject into built binaries. +## GO_TAGS Extra tags to use when building. +## DOCKER_PLATFORM Overrides platform to build Docker images for (defaults to host platform). +## GOEXPERIMENT Used to enable Go features behind feature flags. include tools/make/*.mk -ALLOY_IMAGE ?= grafana/alloy:latest -ALLOY_BINARY ?= build/alloy -SERVICE_BINARY ?= build/alloy-service -ALLOYLINT_BINARY ?= build/alloylint -GOOS ?= $(shell go env GOOS) -GOARCH ?= $(shell go env GOARCH) -GOARM ?= $(shell go env GOARM) -CGO_ENABLED ?= 1 -RELEASE_BUILD ?= 0 -GOEXPERIMENT ?= $(shell go env GOEXPERIMENT) +ALLOY_IMAGE ?= grafana/alloy:latest +ALLOY_IMAGE_WINDOWS ?= grafana/alloy:latest-nanoserver-1809 +ALLOY_BINARY ?= build/alloy +SERVICE_BINARY ?= build/alloy-service +ALLOYLINT_BINARY ?= build/alloylint +GOOS ?= $(shell go env GOOS) +GOARCH ?= $(shell go env GOARCH) +GOARM ?= $(shell go env GOARM) +CGO_ENABLED ?= 1 +RELEASE_BUILD ?= 0 +GOEXPERIMENT ?= $(shell go env GOEXPERIMENT) # List of all environment variables which will propagate to the build # container. USE_CONTAINER must _not_ be included to avoid infinite recursion. PROPAGATE_VARS := \ - ALLOY_IMAGE \ + ALLOY_IMAGE ALLOY_IMAGE_WINDOWS \ BUILD_IMAGE GOOS GOARCH GOARM CGO_ENABLED RELEASE_BUILD \ ALLOY_BINARY \ VERSION GO_TAGS GOEXPERIMENT @@ -196,6 +200,12 @@ images: alloy-image alloy-image: DOCKER_BUILDKIT=1 docker build $(DOCKER_FLAGS) -t $(ALLOY_IMAGE) -f Dockerfile . +.PHONY: images-windows alloy-image-windows +images: alloy-image-windows + +alloy-image-windows: + docker build $(DOCKER_FLAGS) -t $(ALLOY_IMAGE_WINDOWS) -f Dockerfile.windows . + # # Targets for generating assets # @@ -261,18 +271,19 @@ clean: clean-dist clean-build-container-cache .PHONY: info info: - @printf "USE_CONTAINER = $(USE_CONTAINER)\n" - @printf "ALLOY_IMAGE = $(ALLOY_IMAGE)\n" - @printf "BUILD_IMAGE = $(BUILD_IMAGE)\n" - @printf "ALLOY_BINARY = $(ALLOY_BINARY)\n" - @printf "GOOS = $(GOOS)\n" - @printf "GOARCH = $(GOARCH)\n" - @printf "GOARM = $(GOARM)\n" - @printf "CGO_ENABLED = $(CGO_ENABLED)\n" - @printf "RELEASE_BUILD = $(RELEASE_BUILD)\n" - @printf "VERSION = $(VERSION)\n" - @printf "GO_TAGS = $(GO_TAGS)\n" - @printf "GOEXPERIMENT = $(GOEXPERIMENT)\n" + @printf "USE_CONTAINER = $(USE_CONTAINER)\n" + @printf "ALLOY_IMAGE = $(ALLOY_IMAGE)\n" + @printf "ALLOY_IMAGE_WINDOWS = $(ALLOY_IMAGE_WINDOWS)\n" + @printf "BUILD_IMAGE = $(BUILD_IMAGE)\n" + @printf "ALLOY_BINARY = $(ALLOY_BINARY)\n" + @printf "GOOS = $(GOOS)\n" + @printf "GOARCH = $(GOARCH)\n" + @printf "GOARM = $(GOARM)\n" + @printf "CGO_ENABLED = $(CGO_ENABLED)\n" + @printf "RELEASE_BUILD = $(RELEASE_BUILD)\n" + @printf "VERSION = $(VERSION)\n" + @printf "GO_TAGS = $(GO_TAGS)\n" + @printf "GOEXPERIMENT = $(GOEXPERIMENT)\n" # awk magic to print out the comment block at the top of this file. .PHONY: help diff --git a/docs/sources/get-started/install/docker.md b/docs/sources/get-started/install/docker.md index 5426797088..7dacd47b0c 100644 --- a/docs/sources/get-started/install/docker.md +++ b/docs/sources/get-started/install/docker.md @@ -58,7 +58,7 @@ To run {{< param "PRODUCT_NAME" >}} as a Windows Docker container, run the follo docker run \ -v ":C:\Program Files\GrafanaLabs\Alloy\config.alloy" \ -p 12345:12345 \ - grafana/alloy:latest-windows \ + grafana/alloy:latest-nanoserver-1809 \ run --server.http.listen-addr=0.0.0.0:12345 "--storage.path=C:\ProgramData\GrafanaLabs\Alloy\data" \ "C:\Program Files\GrafanaLabs\Alloy\config.alloy" ``` diff --git a/tools/ci/docker-containers-windows b/tools/ci/docker-containers-windows index 0d757655fe..2be86e6541 100644 --- a/tools/ci/docker-containers-windows +++ b/tools/ci/docker-containers-windows @@ -34,7 +34,7 @@ fi # The VERSION_TAG is the version to use for the Docker tag. It is sanitized to # force it to be a valid tag name; ./tools/image-tag can emit characters that # are valid for semver but invalid for Docker tags, such as +. -VERSION_TAG=${VERSION//+/-}-windows +VERSION_TAG=${VERSION//+/-}-nanoserver-1809 # We also need to know which "branch tag" to update. Branch tags are used as a # secondary tag for Docker containers. The branch tag is "latest" when being @@ -45,9 +45,9 @@ VERSION_TAG=${VERSION//+/-}-windows # version. This effectively acts as a no-op because it will tag the same Docker # image twice. if [ -n "$DRONE_TAG" ] && [[ "$DRONE_TAG" != *"-rc."* ]]; then - BRANCH_TAG=latest-windows + BRANCH_TAG=latest-nanoserver-1809 elif [ -n "$DRONE_BRANCH" ]; then - BRANCH_TAG=$DRONE_BRANCH-windows + BRANCH_TAG=$DRONE_BRANCH-nanoserver-1809 else BRANCH_TAG=$VERSION_TAG fi