Skip to content

Commit df5d4e8

Browse files
authored
Release artifacts (#107)
Builds and pushes docker images to GHCR. Part of #11.
1 parent 12bbc60 commit df5d4e8

File tree

7 files changed

+282
-1
lines changed

7 files changed

+282
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: publish-latest-image
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
publish-latest-image:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
24+
with:
25+
go-version-file: "go.mod"
26+
check-latest: true
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
30+
31+
- name: Login to GitHub Container Registry
32+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Run GoReleaser
39+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
40+
with:
41+
version: v2.11.2
42+
args: release --config .goreleaser.latest.yml --snapshot --clean
43+
44+
- name: Push snapshot images
45+
run: |
46+
docker push "ghcr.io/${GITHUB_REPOSITORY}:latest-amd64"
47+
docker push "ghcr.io/${GITHUB_REPOSITORY}:latest-arm64"
48+
49+
- name: Create and push manifest for :latest tag
50+
run: |
51+
docker manifest create "ghcr.io/${GITHUB_REPOSITORY}:latest" "ghcr.io/${GITHUB_REPOSITORY}:latest-amd64" "ghcr.io/${GITHUB_REPOSITORY}:latest-arm64"
52+
docker manifest push "ghcr.io/${GITHUB_REPOSITORY}:latest"

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: write
10+
packages: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
23+
with:
24+
go-version-file: "go.mod"
25+
check-latest: true
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
29+
30+
- name: Login to GitHub Container Registry
31+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
32+
with:
33+
registry: ghcr.io
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Run GoReleaser
38+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
39+
with:
40+
version: v2.11.2
41+
args: release
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22

33
bin
4+
dist
45

56
secret.env
67
certs

.goreleaser.latest.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: 2
2+
3+
env:
4+
- GITHUB_REPOSITORY={{ if index .Env "GITHUB_REPOSITORY" }}{{ .Env.GITHUB_REPOSITORY }}{{ else }}temporalio/temporal-worker-controller{{ end }}
5+
6+
before:
7+
hooks:
8+
- go mod download
9+
10+
announce:
11+
skip: true
12+
13+
changelog:
14+
disable: true
15+
16+
release:
17+
disable: true
18+
19+
builds:
20+
- id: nix
21+
dir: cmd
22+
binary: temporal-worker-controller
23+
ldflags:
24+
- -s -w -X github.com/temporalio/temporal-worker-controller/internal/controller.Version={{.Version}}
25+
goarch:
26+
- amd64
27+
- arm64
28+
goos:
29+
- linux
30+
env:
31+
- CGO_ENABLED=0
32+
33+
checksum:
34+
disable: true
35+
36+
# Only build Docker images with 'latest' tag
37+
dockers:
38+
- image_templates:
39+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest-amd64"
40+
dockerfile: Dockerfile.goreleaser
41+
use: buildx
42+
build_flag_templates:
43+
- --platform=linux/amd64
44+
- --label=org.opencontainers.image.title={{ .ProjectName }}
45+
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
46+
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
47+
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
48+
- --label=org.opencontainers.image.version=latest
49+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
50+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
51+
- --label=org.opencontainers.image.licenses=MIT
52+
extra_files:
53+
- LICENSE
54+
55+
- image_templates:
56+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest-arm64"
57+
dockerfile: Dockerfile.goreleaser
58+
use: buildx
59+
build_flag_templates:
60+
- --platform=linux/arm64
61+
- --label=org.opencontainers.image.title={{ .ProjectName }}
62+
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
63+
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
64+
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
65+
- --label=org.opencontainers.image.version=latest
66+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
67+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
68+
- --label=org.opencontainers.image.licenses=MIT
69+
extra_files:
70+
- LICENSE
71+
72+
docker_manifests:
73+
- name_template: "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest"
74+
image_templates:
75+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest-amd64"
76+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest-arm64"

.goreleaser.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
version: 2
2+
3+
env:
4+
- GITHUB_REPOSITORY={{ if index .Env "GITHUB_REPOSITORY" }}{{ .Env.GITHUB_REPOSITORY }}{{ else }}temporalio/temporal-worker-controller{{ end }}
5+
6+
before:
7+
hooks:
8+
- go mod download
9+
10+
announce:
11+
skip: true
12+
13+
changelog:
14+
disable: true
15+
16+
release:
17+
prerelease: auto
18+
draft: false
19+
20+
builds:
21+
- id: nix
22+
dir: cmd
23+
binary: temporal-worker-controller
24+
ldflags:
25+
- -s -w -X github.com/temporalio/temporal-worker-controller/internal/controller.Version={{.Version}}
26+
goarch:
27+
- amd64
28+
- arm64
29+
goos:
30+
- linux
31+
- darwin
32+
env:
33+
- CGO_ENABLED=0
34+
35+
archives:
36+
- id: default
37+
name_template: "temporal-worker-controller_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
38+
files:
39+
- LICENSE
40+
41+
checksum:
42+
name_template: "checksums.txt"
43+
algorithm: sha256
44+
45+
dockers:
46+
- image_templates:
47+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
48+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:v{{ .Major }}.{{ .Minor }}-amd64"
49+
dockerfile: Dockerfile.goreleaser
50+
use: buildx
51+
build_flag_templates:
52+
- --platform=linux/amd64
53+
- --label=org.opencontainers.image.title={{ .ProjectName }}
54+
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
55+
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
56+
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
57+
- --label=org.opencontainers.image.version={{ .Version }}
58+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
59+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
60+
- --label=org.opencontainers.image.licenses=MIT
61+
extra_files:
62+
- LICENSE
63+
64+
- image_templates:
65+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"
66+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:v{{ .Major }}.{{ .Minor }}-arm64"
67+
dockerfile: Dockerfile.goreleaser
68+
use: buildx
69+
build_flag_templates:
70+
- --platform=linux/arm64
71+
- --label=org.opencontainers.image.title={{ .ProjectName }}
72+
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
73+
- --label=org.opencontainers.image.url=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
74+
- --label=org.opencontainers.image.source=https://github.com/{{ .Env.GITHUB_REPOSITORY }}
75+
- --label=org.opencontainers.image.version={{ .Version }}
76+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
77+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
78+
- --label=org.opencontainers.image.licenses=MIT
79+
extra_files:
80+
- LICENSE
81+
82+
docker_manifests:
83+
- name_template: "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}"
84+
image_templates:
85+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
86+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"
87+
88+
- name_template: "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:v{{ .Major }}.{{ .Minor }}"
89+
image_templates:
90+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:v{{ .Major }}.{{ .Minor }}-amd64"
91+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:v{{ .Major }}.{{ .Minor }}-arm64"
92+
93+
- name_template: "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:latest"
94+
image_templates:
95+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-amd64"
96+
- "ghcr.io/{{ .Env.GITHUB_REPOSITORY }}:{{ .Tag }}-arm64"

Dockerfile.goreleaser

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM gcr.io/distroless/static-debian12:nonroot
2+
3+
COPY temporal-worker-controller /usr/local/bin/temporal-worker-controller
4+
5+
ENTRYPOINT ["temporal-worker-controller"]

internal/controller/util.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ const (
1414
defaultControllerIdentity = "temporal-worker-controller"
1515
)
1616

17-
// getControllerVersion returns the version from environment variable (set by Helm from image.tag)
17+
// Version is set by goreleaser via ldflags at build time
18+
var Version = "unknown"
19+
20+
// getControllerVersion returns the version, preferring build-time injection over environment variable
1821
func getControllerVersion() string {
22+
// First check if version was injected at build time
23+
if Version != "" && Version != "unknown" {
24+
return Version
25+
}
26+
// Fall back to environment variable (set by Helm from image.tag)
1927
if version := os.Getenv("CONTROLLER_VERSION"); version != "" {
2028
return version
2129
}

0 commit comments

Comments
 (0)