Skip to content

Commit

Permalink
Use github container registry
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <jstur@microsoft.com>
  • Loading branch information
jsturtevant committed Jan 11, 2022
1 parent 47009bf commit f3e9a34
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
- published
- edited

permissions:
contents: read
packages: write

jobs:
test:
runs-on: windows-2019
Expand All @@ -34,7 +38,7 @@ jobs:
run: make e2e-test

lint:
runs-on: windows-2019
runs-on: windows-2022
steps:
# `gofmt` linter run by golangci-lint fails on CRLF line endings (the default for Windows)
- name: Set git to use LF
Expand Down Expand Up @@ -73,7 +77,7 @@ jobs:
ignore_words_list: calle

build:
runs-on: windows-2019
runs-on: windows-2022
needs:
- test
- lint
Expand All @@ -90,6 +94,7 @@ jobs:

- name: Install Build deps
run: |
dotnet tool install --global GitVersion.Tool --version 5.*
go get -u github.com/prometheus/promu@v0.11.1
go get -u github.com/josephspurrier/goversioninfo/cmd/goversioninfo@v1.2.0
# GOPATH\bin dir must be added to PATH else the `promu` and `goversioninfo` commands won't be found
Expand All @@ -106,6 +111,7 @@ jobs:
goversioninfo.exe -ver-major $VersionParts[0] -ver-minor $VersionParts[1] -ver-patch $VersionParts[2] -product-version $Version -platform-specific
make crossbuild
make build-all
# GH requires all files to have different names, so add version/arch to differentiate
foreach($Arch in "amd64","386") {
Move-Item output\$Arch\windows_exporter.exe output\windows_exporter-$Version-$Arch.exe
Expand Down Expand Up @@ -133,10 +139,19 @@ jobs:
promu checksum output\
- name: Login to GitHub container registry
if: startsWith(github.ref, 'refs/tags/')
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Release
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$TagName = $env:GITHUB_REF -replace 'refs/tags/', ''
Get-ChildItem -Path output\* -Include @('windows_exporter*.msi', 'windows_exporter*.exe', 'sha256sums.txt') | Foreach-Object {gh release upload $TagName $_}
make push
11 changes: 1 addition & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@
# the files in the image are copied to $env:CONTAINER_SANDBOX_MOUNT_POINT on the host
# but the file system is the Host NOT the container
ARG BASE="mcr.microsoft.com/windows/nanoserver:1809"

FROM --platform=linux/amd64 golang:1.17 as build

RUN go get -u github.com/prometheus/promu
WORKDIR /go/src/app
COPY . .
ENV GOOS=windows
RUN promu build -v

FROM $BASE

ENV PATH="C:\Windows\system32;C:\Windows;"
COPY --from=build /go/src/app/windows_exporter.exe /windows_exporter.exe
COPY output/amd64/windows_exporter.exe /windows_exporter.exe
ENTRYPOINT ["windows_exporter.exe"]
13 changes: 6 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export GOOS=windows
export DOCKER_IMAGE_NAME ?= windows-exporter
export DOCKER_REPO ?= prom
export DOCKER_REPO ?= ghcr.io/prometheus-community

VERSION=$(shell cat VERSION)

Expand Down Expand Up @@ -37,23 +37,22 @@ crossbuild:
GOARCH=amd64 promu build --prefix=output/amd64
GOARCH=386 promu build --prefix=output/386

build-image:
docker buildx create --name img-builder --use --platform windows/amd64; \
trap 'docker buildx rm img-builder' EXIT; \
docker buildx build --platform windows/amd64 --output=type=registry --pull --build-arg=BASE=$(BASE_IMAGE):$(OS) -f Dockerfile -t $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)-$(OS) . \
build-image: crossbuild
docker build --build-arg=BASE=$(BASE_IMAGE):$(OS) -f Dockerfile -t $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)-$(OS) .

sub-build-%:
$(MAKE) OS=$* build-image

build-all: $(addprefix sub-build-,$(ALL_OS))

push-manifest:
push:
set -x; \
for osversion in ${ALL_OS}; do \
docker push $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion} \
docker manifest create --amend $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION) $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
full_version=`docker manifest inspect $(BASE_IMAGE):$${osversion} | grep "os.version" | head -n 1 | awk -F\" '{print $$4}'` || true; \
docker manifest annotate --os windows --arch amd64 --os-version $${full_version} $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION) $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)-$${osversion}; \
done
docker manifest push --purge $(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(VERSION)

push-all: build-all push-manifest
push-all: build-all push
4 changes: 2 additions & 2 deletions kubernetes/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ With Kubernetes supporting HostProcess containers on Windows nodes (as of [v1.22

Requirements:

- Kuberentes 1.22+
- Kubernetes 1.22+
- containerd 1.6 Beta+
- WindowsHostProcessContainers feature-gate turned on for `kube-apiserver` and `kubelet`

> IMPORTANT: This does not work unless you are specifically targeting Host Process Containers with Containerd (Docker doesn't have support). The image will build but will **not** be able to access the host.
## Container Image

The image is built using docker buildx on Linux and requires a registry to successfully create an image. Building the image:
The image is multi arch image (WS 2019, WS 2022) built on Windows. To build the images:

```
DOCKER_REPO=<your repo> make push-all
Expand Down

0 comments on commit f3e9a34

Please sign in to comment.