Skip to content

Commit

Permalink
Docker: fix Windows container (#135)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rfratto authored Apr 5, 2024
1 parent 862dbfa commit a524386
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 70 deletions.
12 changes: 9 additions & 3 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -559,6 +565,6 @@ kind: secret
name: updater_private_key
---
kind: signature
hmac: 21df6cb02f24c4eab41dc3425f43c865141d400b2ad00571bde9a1803577e77c
hmac: 33ad6940aa3d0615eb3be75bbeee0a90910b5b03280c1a80cc664abeb0de2932

...
4 changes: 2 additions & 2 deletions .drone/pipelines/check_containers.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
];

(
Expand Down Expand Up @@ -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: [{
Expand Down
17 changes: 9 additions & 8 deletions .drone/pipelines/publish.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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: [{
Expand Down Expand Up @@ -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: {
Expand All @@ -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: [{
Expand Down
2 changes: 2 additions & 0 deletions .drone/util/pipelines.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
version: '1809',
},
},

windows_command(command):: '& "C:/Program Files/git/bin/bash.exe" -c "%s"' % command,
}
117 changes: 64 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
##
Expand All @@ -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
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/get-started/install/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ To run {{< param "PRODUCT_NAME" >}} as a Windows Docker container, run the follo
docker run \
-v "<CONFIG_FILE_PATH>: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"
```
Expand Down
6 changes: 3 additions & 3 deletions tools/ci/docker-containers-windows
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a524386

Please sign in to comment.