Skip to content

Commit d74a4c7

Browse files
authored
chore(gha): publish container images to GHCR (#24)
- chore(gha): switch from DockerHub to GHCR for container images - feat(gha): publish a linux container image on PRs and every merge to main - chore(deps): update `.goreleaser.yaml` for v2
1 parent d2474fd commit d74a4c7

File tree

3 files changed

+132
-50
lines changed

3 files changed

+132
-50
lines changed

.github/workflows/release.yaml

Lines changed: 91 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,81 @@ on:
22
push:
33
tags:
44
- v*
5+
branches: ['main']
6+
pull_request:
7+
branches: ['main']
8+
paths:
9+
- '**/**.go'
10+
- 'go.mod'
11+
- 'go.sum'
12+
- 'Dockerfile'
13+
- 'Dockerfile.windows'
14+
- '.github/workflows/release.yaml'
15+
workflow_dispatch:
16+
inputs:
17+
ref:
18+
description: 'Branch, commit, or tag to checkout'
19+
required: true
520

621
permissions:
722
contents: write
23+
packages: write
824

925
env:
10-
IMAGE: paskalmaksim/aks-node-termination-handler:${{github.ref_name}}
11-
IMAGE_LATEST: paskalmaksim/aks-node-termination-handler:latest
12-
# IMAGE: paskalmaksim/aks-node-termination-handler:test-${{ github.run_id }}
13-
# IMAGE_LATEST: paskalmaksim/aks-node-termination-handler:test-latest
26+
REGISTRY: ghcr.io
27+
IMAGE_NAME: ${{ github.repository }}
1428

1529
jobs:
1630
build:
1731
runs-on: ubuntu-latest
32+
outputs:
33+
VERSION: ${{ steps.version.outputs.VERSION }}
34+
IS_TAG: ${{ steps.version.outputs.IS_TAG }}
1835
steps:
1936
- name: Checkout
2037
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
2138
with:
22-
fetch-depth: 0
39+
ref: ${{ github.event.inputs.ref || github.ref }}
40+
fetch-depth: '0'
41+
- name: Get version from git describe
42+
id: version
43+
run: |
44+
VERSION=$(git describe --always --dirty --exclude 'helm-chart-*')
45+
TAG_PATTERN="^[0-9]+[.][0-9]+[0-9]+$"
46+
if [[ "$VERSION" =~ $TAG_PATTERN ]]; then
47+
IS_TAG="true"
48+
else
49+
IS_TAG="false"
50+
fi
51+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
52+
echo "IS_TAG=${IS_TAG}" >> $GITHUB_OUTPUT
53+
echo "Building version: ${VERSION} [is_tag=${IS_TAG}]"
2354
- name: Set up Go
2455
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6
2556
with:
2657
go-version-file: 'go.mod'
27-
- name: Remove Git Tags with Charts
28-
run: git tag -d $(git tag -l "helm-chart-*")
29-
- name: Run GoReleaser
58+
- name: GoReleaser Snapshot
59+
if: ${{ steps.version.outputs.IS_TAG != 'true' }}
60+
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
61+
with:
62+
distribution: goreleaser
63+
version: latest
64+
args: release --clean --snapshot
65+
env:
66+
RELEASE_VERSION: ${{ steps.version.outputs.VERSION }}
67+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68+
- name: GoReleaser Release
69+
if: ${{ steps.version.outputs.IS_TAG == 'true' }}
3070
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
3171
with:
3272
distribution: goreleaser
3373
version: latest
34-
# args: build --clean --skip=validate --snapshot
3574
args: release --clean
3675
env:
76+
RELEASE_VERSION: ${{ steps.version.outputs.VERSION }}
3777
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3878
- run: cp Dockerfile ./dist/aks-node-termination-handler_linux_amd64_v1/Dockerfile
39-
- run: cp Dockerfile ./dist/aks-node-termination-handler_linux_arm64/Dockerfile
79+
- run: cp Dockerfile ./dist/aks-node-termination-handler_linux_arm64_v8.0/Dockerfile
4080
- run: cp Dockerfile.windows ./dist/aks-node-termination-handler_windows_amd64_v1/Dockerfile
4181
- run: tar -cvf release.tar ./dist
4282
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
@@ -45,14 +85,35 @@ jobs:
4585
retention-days: 1
4686
path: release.tar
4787

88+
publish-dev-linux-amd64:
89+
runs-on: ubuntu-latest
90+
needs: build
91+
if: ${{ needs.build.outputs.IS_TAG != 'true' }}
92+
steps:
93+
- run: echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}" >> $GITHUB_ENV
94+
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
95+
with:
96+
registry: ${{ env.REGISTRY }}
97+
username: ${{ github.actor }}
98+
password: ${{ secrets.GITHUB_TOKEN }}
99+
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
100+
with:
101+
name: release
102+
- run: tar xvf release.tar
103+
- run: "docker build --pull --push --platform linux/amd64 -t ${{ env.IMAGE }} ."
104+
working-directory: ./dist/aks-node-termination-handler_linux_amd64_v1
105+
48106
publish-linux-amd64:
49107
runs-on: ubuntu-latest
50108
needs: build
109+
if: ${{ needs.build.outputs.IS_TAG == 'true' }}
51110
steps:
111+
- run: echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}" >> $GITHUB_ENV
52112
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
53113
with:
54-
username: ${{ secrets.DOCKER_USERNAME }}
55-
password: ${{ secrets.DOCKER_PASSWORD }}
114+
registry: ${{ env.REGISTRY }}
115+
username: ${{ github.actor }}
116+
password: ${{ secrets.GITHUB_TOKEN }}
56117
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
57118
- run: tar xvf ./release/release.tar
58119
- run: "docker build --pull --push --platform linux/amd64 -t ${{ env.IMAGE }}-linux-amd64 ."
@@ -61,29 +122,35 @@ jobs:
61122
publish-linux-arm64:
62123
runs-on: ubuntu-latest
63124
needs: build
125+
if: ${{ needs.build.outputs.IS_TAG == 'true' }}
64126
steps:
127+
- run: echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}" >> $GITHUB_ENV
65128
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
66129
with:
67-
username: ${{ secrets.DOCKER_USERNAME }}
68-
password: ${{ secrets.DOCKER_PASSWORD }}
130+
registry: ${{ env.REGISTRY }}
131+
username: ${{ github.actor }}
132+
password: ${{ secrets.GITHUB_TOKEN }}
69133
- uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
70134
- uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
71135
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
72136
- run: tar xvf ./release/release.tar
73137
- run: "docker build --pull --push --platform linux/arm64 -t ${{ env.IMAGE }}-linux-arm64 ."
74-
working-directory: ./dist/aks-node-termination-handler_linux_arm64
138+
working-directory: ./dist/aks-node-termination-handler_linux_arm64_v8.0
75139

76140
publish-windows-amd64:
77141
runs-on: windows-latest
78142
strategy:
79143
matrix:
80144
windows-version: ['ltsc2019', 'ltsc2022', 'ltsc2025']
81145
needs: build
146+
if: ${{ needs.build.outputs.IS_TAG == 'true' }}
82147
steps:
148+
- run: echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}" >> $GITHUB_ENV
83149
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
84150
with:
85-
username: ${{ secrets.DOCKER_USERNAME }}
86-
password: ${{ secrets.DOCKER_PASSWORD }}
151+
registry: ${{ env.REGISTRY }}
152+
username: ${{ github.actor }}
153+
password: ${{ secrets.GITHUB_TOKEN }}
87154
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
88155
- run: tar xvf ./release/release.tar
89156
- run: "docker build --build-arg WINDOWS_VERSION=${{ matrix.windows-version }} --pull --platform windows/amd64 -t ${{ env.IMAGE }}-windows-${{ matrix.windows-version }}-amd64 ."
@@ -92,12 +159,16 @@ jobs:
92159

93160
publish-manifest:
94161
runs-on: ubuntu-latest
95-
needs: [publish-linux-amd64, publish-linux-arm64, publish-windows-amd64]
162+
needs: [build, publish-linux-amd64, publish-linux-arm64, publish-windows-amd64]
163+
if: ${{ needs.build.outputs.IS_TAG == 'true' }}
96164
steps:
165+
- run: echo "IMAGE=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.build.outputs.VERSION }}" >> $GITHUB_ENV
166+
- run: echo "IMAGE_LATEST=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_ENV
97167
- uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3
98168
with:
99-
username: ${{ secrets.DOCKER_USERNAME }}
100-
password: ${{ secrets.DOCKER_PASSWORD }}
169+
registry: ${{ env.REGISTRY }}
170+
username: ${{ github.actor }}
171+
password: ${{ secrets.GITHUB_TOKEN }}
101172
- run: docker manifest create ${{ env.IMAGE }} ${{ env.IMAGE }}-linux-amd64 ${{ env.IMAGE }}-linux-arm64 ${{ env.IMAGE }}-windows-ltsc2025-amd64
102173
- run: docker manifest push ${{ env.IMAGE }}
103174
- run: docker manifest create ${{ env.IMAGE_LATEST }} ${{ env.IMAGE }}-linux-amd64 ${{ env.IMAGE }}-linux-arm64 ${{ env.IMAGE }}-windows-ltsc2025-amd64

.goreleaser.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
version: 2
3+
4+
project_name: aks-node-termination-handler
5+
6+
metadata:
7+
mod_timestamp: "{{ .CommitTimestamp }}"
8+
9+
before:
10+
hooks:
11+
- go mod tidy
12+
13+
release:
14+
footer: |
15+
## Docker Images
16+
- `{{ envOrDefault "REGISTRY" "gchcr.io" }}/{{ envOrDefault "IMAGE_NAME" "vince-riv/aks-node-termination-handler" }}:latest`
17+
- `{{ envOrDefault "REGISTRY" "gchcr.io" }}/{{ envOrDefault "IMAGE_NAME" "vince-riv/aks-node-termination-handler" }}:{{ envOrDefault "RELEASE_VERSION" "v0.0.0" }}`
18+
builds:
19+
- dir: ./cmd/
20+
env:
21+
- CGO_ENABLED=0
22+
flags:
23+
- -trimpath
24+
ldflags:
25+
- -s -w -X github.com/vince-riv/aks-node-termination-handler/pkg/config.gitVersion={{.Version}}-{{.ShortCommit}}-{{.Timestamp}}
26+
goos:
27+
- linux
28+
- windows
29+
goarch:
30+
- amd64
31+
- arm64
32+
33+
checksum:
34+
name_template: 'checksums.txt'
35+
36+
changelog:
37+
sort: asc
38+
filters:
39+
exclude:
40+
- '^docs:'
41+
- '^test:'

.goreleaser.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)