Skip to content

Commit d13d726

Browse files
authored
chore: Switch to hostprocess base image and add support for Windows Server 2025 on Kubernetes (click PR number for more information) (#1731)
Signed-off-by: Jan-Otto Kröpke <[email protected]>
1 parent 31bcf42 commit d13d726

File tree

4 files changed

+75
-104
lines changed

4 files changed

+75
-104
lines changed

.github/workflows/release.yml

+58-57
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
branches:
77
- master
88
pull_request:
9+
workflow_dispatch:
910
release:
1011
types:
1112
- published
@@ -16,10 +17,7 @@ permissions:
1617
packages: write
1718

1819
env:
19-
VERSION_PROMU: '0.14.0'
20-
VERSION_CONTAINERD: '1.7.21'
21-
VERSION_BUILDKIT: '0.15.2'
22-
VERSION_BUILDX: '0.16.2'
20+
VERSION_PROMU: '0.17.0'
2321

2422
jobs:
2523
build:
@@ -33,27 +31,6 @@ jobs:
3331
with:
3432
go-version-file: 'go.mod'
3533

36-
# https://github.com/pl4nty/Windows-Containers/blob/Main/helpful_tools/Install-BuildKit-GitHubActions/workflow.yaml
37-
- name: Setup containerd
38-
run: |
39-
curl.exe -L https://github.com/containerd/containerd/releases/download/v${{ env.VERSION_CONTAINERD }}/containerd-${{ env.VERSION_CONTAINERD }}-windows-amd64.tar.gz -o containerd.tar.gz
40-
tar.exe xvf containerd.tar.gz
41-
.\bin\containerd.exe --register-service
42-
Start-Service containerd
43-
- name: Setup BuildKit
44-
run: |
45-
curl.exe -L https://github.com/moby/buildkit/releases/download/v${{ env.VERSION_BUILDKIT }}/buildkit-v${{ env.VERSION_BUILDKIT }}.windows-amd64.tar.gz -o buildkit.tar.gz
46-
tar.exe xvf buildkit.tar.gz
47-
48-
.\bin\buildkitd.exe --register-service
49-
Start-Service buildkitd
50-
- name: Setup Docker Buildx
51-
run: |
52-
curl.exe -L https://github.com/docker/buildx/releases/download/v${{ env.VERSION_BUILDX }}/buildx-v${{ env.VERSION_BUILDX }}.windows-amd64.exe -o $env:ProgramData\Docker\cli-plugins\docker-buildx.exe
53-
- uses: docker/setup-buildx-action@v3
54-
with:
55-
driver: remote
56-
endpoint: npipe:////./pipe/buildkitd
5734
- name: Install WiX
5835
run: dotnet tool install --global wix
5936

@@ -114,16 +91,27 @@ jobs:
11491
output\windows_exporter-*.exe
11592
output\windows_exporter-*.msi
11693
117-
- name: Build Docker Artifacts
118-
run: make build-all
94+
- name: Release
95+
if: startsWith(github.ref, 'refs/tags/')
11996
env:
120-
VERSION: >-
121-
${{
122-
startsWith(github.ref, 'refs/tags/') && 'latest' ||
123-
(
124-
github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref_name
125-
)
126-
}}
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
run: |
99+
$TagName = $env:GITHUB_REF -replace 'refs/tags/', ''
100+
Get-ChildItem -Path output\* -Include @('windows_exporter*.msi', 'windows_exporter*.exe', 'sha256sums.txt') | Foreach-Object {gh release upload $TagName $_}
101+
docker:
102+
name: Build docker images
103+
runs-on: ubuntu-latest
104+
needs:
105+
- build
106+
steps:
107+
- uses: actions/checkout@v4
108+
with:
109+
fetch-depth: '0'
110+
111+
- name: Download Artifacts
112+
uses: actions/download-artifact@v4
113+
with:
114+
name: windows_exporter_binaries
127115

128116
- name: Login to Docker Hub
129117
if: ${{ github.event_name != 'pull_request' }}
@@ -132,13 +120,13 @@ jobs:
132120
username: ${{ secrets.DOCKER_HUB_LOGIN }}
133121
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
134122

135-
#- name: Login to quay.io
136-
# if: ${{ github.event_name != 'pull_request' }}
137-
# uses: docker/login-action@v3
138-
# with:
139-
# registry: quay.io
140-
# username: 'robot'
141-
# password: ${{ secrets.QUAY_IO_API_TOKEN }}
123+
- name: Login to quay.io
124+
if: ${{ github.event_name != 'pull_request' }}
125+
uses: docker/login-action@v3
126+
with:
127+
registry: quay.io
128+
username: ${{ secrets.QUAY_USER }}
129+
password: ${{ secrets.QUAY_PASS }}
142130

143131
- name: Login to GitHub container registry
144132
if: ${{ github.event_name != 'pull_request' }}
@@ -148,19 +136,32 @@ jobs:
148136
username: ${{ github.repository_owner }}
149137
password: ${{ secrets.GITHUB_TOKEN }}
150138

151-
- name: Push Latest image
152-
if: ${{ github.event_name != 'pull_request' }}
153-
env:
154-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155-
VERSION: ${{ startsWith(github.ref, 'refs/tags/') && 'latest' || github.ref_name }}
156-
run: |
157-
make push-all
158-
159-
- name: Release
160-
if: startsWith(github.ref, 'refs/tags/')
161-
env:
162-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
163-
run: |
164-
$TagName = $env:GITHUB_REF -replace 'refs/tags/', ''
165-
Get-ChildItem -Path output\* -Include @('windows_exporter*.msi', 'windows_exporter*.exe', 'sha256sums.txt') | Foreach-Object {gh release upload $TagName $_}
166-
make push-all
139+
- name: Docker meta
140+
id: meta
141+
uses: docker/metadata-action@v5
142+
with:
143+
images: |
144+
ghcr.io/prometheus-community/windows-exporter
145+
quay.io/prometheuscommunity/windows-exporter
146+
docker.io/prometheuscommunity/windows-exporter
147+
tags: |
148+
type=semver,pattern={{version}}
149+
type=ref,event=branch
150+
type=ref,event=pr
151+
labels: |
152+
org.opencontainers.image.title=windows_exporter
153+
org.opencontainers.image.description=A Prometheus exporter for Windows machines.
154+
org.opencontainers.image.vendor=The Prometheus Community
155+
org.opencontainers.image.licenses=MIT
156+
157+
- name: Set up Docker Buildx
158+
uses: docker/setup-buildx-action@v3
159+
160+
- name: Build and push
161+
uses: docker/build-push-action@v6
162+
with:
163+
context: .
164+
push: ${{ github.event_name != 'pull_request' }}
165+
tags: ${{ steps.meta.outputs.tags }}
166+
labels: ${{ steps.meta.outputs.labels }}
167+
platforms: windows/amd64

Dockerfile

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Note this image doesn't really matter for hostprocess but it is good to build per OS version
2-
# the files in the image are copied to $env:CONTAINER_SANDBOX_MOUNT_POINT on the host
3-
# but the file system is the Host NOT the container
4-
ARG BASE="mcr.microsoft.com/windows/nanoserver:ltsc2022"
1+
# mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0
2+
# Using this image as a base for HostProcess containers has a few advantages over using other base images for Windows containers including:
3+
# - Smaller image size
4+
# - OS compatibility (works on any Windows version that supports containers)
5+
6+
# This image MUST be built with docker buildx build (buildx) command on a Linux system.
7+
# Ref: https://github.com/microsoft/windows-host-process-containers-base-image
8+
9+
ARG BASE="mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0"
510
FROM $BASE
611

7-
ENV PATH="C:\Windows\system32;C:\Windows;"
8-
COPY output/amd64/windows_exporter.exe /windows_exporter.exe
12+
COPY windows_exporter*-amd64.exe /windows_exporter.exe
913
ENTRYPOINT ["windows_exporter.exe"]

Dockerfile.cross

-22
This file was deleted.

Makefile

+7-19
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,19 @@ build-hostprocess:
6464
sub-build-%:
6565
$(MAKE) OS=$* build-image
6666

67-
build-all: $(addprefix sub-build-,$(ALL_OS)) build-hostprocess
68-
69-
push:
70-
set -x; \
71-
for docker_repo in ${DOCKER_REPO}; do \
72-
for osversion in ${ALL_OS}; do \
73-
$(DOCKER) tag local/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion} $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
74-
$(DOCKER) push $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
75-
$(DOCKER) manifest create --amend $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
76-
full_version=`$(DOCKER) manifest inspect $(BASE_IMAGE):$${osversion} | grep "os.version" | head -n 1 | awk -F\" '{print $$4}'` || true; \
77-
$(DOCKER) manifest annotate --os windows --arch amd64 --os-version $${full_version} $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
78-
done; \
79-
$(DOCKER) manifest push --purge $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION); \
67+
build-all: crossbuild
68+
@for docker_repo in ${DOCKER_REPO}; do \
69+
echo $(DOCKER) buildx build -f Dockerfile -t $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) .; \
8070
done
8171

82-
# We can't load the image into the local docker store, so we have to build and push it in one go
83-
push-hostprocess:
84-
set -x; \
85-
for docker_repo in ${DOCKER_REPO}; do \
86-
$(DOCKER) buildx build --push --build-arg=BASE=mcr.microsoft.com/oss/kubernetes/windows-host-process-containers-base-image:v1.0.0 -f Dockerfile -t $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION)-hostprocess .; \
72+
push:
73+
@for docker_repo in ${DOCKER_REPO}; do \
74+
echo $(DOCKER) buildx build --push -f Dockerfile -t $${docker_repo}/$(DOCKER_IMAGE_NAME):$(VERSION) .; \
8775
done
8876

8977
.PHONY: push-all
9078
push-all: build-all
91-
$(MAKE) DOCKER_REPO="$(ALL_DOCKER_REPOS)" push # push-hostprocess - disabled until it works on Windows
79+
$(MAKE) DOCKER_REPO="$(ALL_DOCKER_REPOS)" push
9280

9381
# Mandatory target for container description sync action
9482
.PHONY: docker-repo-name

0 commit comments

Comments
 (0)