Skip to content

Commit f394c51

Browse files
Shivs11claude
andauthored
Add manual branch image publish workflow (#224)
## Summary - add a manual GitHub Actions workflow to publish controller images from the current HEAD of a specified branch - document the workflow briefly in the development section of the README - I think this is important and a nice to have in this repo. As the number of contributions grow, I would love to have a way to test un-merged controller PR's against internal pipelines to validate if the changes are backwards compat or not. ## Testing - make lint-actions --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent eae7c39 commit f394c51

5 files changed

Lines changed: 107 additions & 61 deletions

File tree

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal/demo
3131
# CI/CD
3232
.github
3333
.goreleaser.yml
34-
.goreleaser.main.yml
34+
.goreleaser.publish-images.yml
3535

3636
# Go
3737
go.work
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: publish-image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
inputs:
9+
branch:
10+
description: >
11+
Branch to publish from (defaults to the branch selected in the UI).
12+
The image will be tagged "main" for main, or "branch-<name>" otherwise.
13+
required: false
14+
type: string
15+
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
concurrency:
21+
group: publish-image-${{ inputs.branch || github.ref_name }}
22+
cancel-in-progress: false
23+
24+
jobs:
25+
publish-image:
26+
runs-on: ubuntu-latest
27+
env:
28+
IMAGE_NAME: temporalio/temporal-worker-controller
29+
steps:
30+
- name: Determine ref and image tag
31+
id: meta
32+
shell: bash
33+
env:
34+
INPUT_BRANCH: ${{ inputs.branch }}
35+
run: |
36+
# Resolve the effective branch.
37+
# workflow_dispatch may supply an explicit branch; otherwise
38+
# fall back to the ref that triggered the workflow.
39+
branch="${INPUT_BRANCH:-$GITHUB_REF_NAME}"
40+
41+
if [[ "$branch" == "main" ]]; then
42+
echo "image_tag=main" >> "$GITHUB_OUTPUT"
43+
else
44+
sanitized="$(printf '%s' "$branch" | tr '[:upper:]' '[:lower:]' | sed -E 's#[^a-z0-9._-]+#-#g; s#(^-+|-+$)##g')"
45+
if [[ -z "$sanitized" ]]; then
46+
echo "Could not derive a Docker-compatible tag from branch '$branch'" >&2
47+
exit 1
48+
fi
49+
echo "image_tag=branch-${sanitized}" >> "$GITHUB_OUTPUT"
50+
fi
51+
52+
echo "ref=${branch}" >> "$GITHUB_OUTPUT"
53+
54+
- name: Checkout
55+
uses: actions/checkout@v4
56+
with:
57+
ref: ${{ steps.meta.outputs.ref }}
58+
fetch-depth: 0
59+
60+
- name: Set up Go
61+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
62+
with:
63+
go-version-file: "go.mod"
64+
check-latest: true
65+
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
68+
69+
- name: Login to Docker Hub
70+
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
71+
with:
72+
registry: docker.io
73+
username: ${{ secrets.DOCKER_USERNAME }}
74+
password: ${{ secrets.DOCKER_PAT }}
75+
76+
- name: Run GoReleaser
77+
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
78+
with:
79+
version: v2.11.2
80+
args: release --config .goreleaser.publish-images.yml --snapshot --clean
81+
env:
82+
IMAGE_TAG: ${{ steps.meta.outputs.image_tag }}
83+
84+
- name: Push snapshot images
85+
env:
86+
IMAGE_TAG: ${{ steps.meta.outputs.image_tag }}
87+
run: |
88+
docker push "${IMAGE_NAME}:${IMAGE_TAG}-amd64"
89+
docker push "${IMAGE_NAME}:${IMAGE_TAG}-arm64"
90+
91+
- name: Create and push manifest
92+
env:
93+
IMAGE_TAG: ${{ steps.meta.outputs.image_tag }}
94+
run: |
95+
docker manifest create "${IMAGE_NAME}:${IMAGE_TAG}" "${IMAGE_NAME}:${IMAGE_TAG}-amd64" "${IMAGE_NAME}:${IMAGE_TAG}-arm64"
96+
docker manifest push "${IMAGE_NAME}:${IMAGE_TAG}"

.github/workflows/publish-main-image.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ builds:
3030
checksum:
3131
disable: true
3232

33-
# Only build Docker images with 'main' tag
33+
# Build Docker images with the tag provided by IMAGE_TAG
3434
dockers:
3535
- ids:
3636
- nix
3737
goos: linux
3838
goarch: amd64
3939
image_templates:
40-
- "temporalio/temporal-worker-controller:main-amd64"
40+
- "temporalio/temporal-worker-controller:{{ .Env.IMAGE_TAG }}-amd64"
4141
dockerfile: Dockerfile.goreleaser
4242
use: buildx
4343
build_flag_templates:
@@ -48,7 +48,7 @@ dockers:
4848
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
4949
- --label=org.opencontainers.image.url=https://github.com/temporalio/temporal-worker-controller
5050
- --label=org.opencontainers.image.source=https://github.com/temporalio/temporal-worker-controller
51-
- --label=org.opencontainers.image.version=main
51+
- --label=org.opencontainers.image.version={{ .Env.IMAGE_TAG }}
5252
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
5353
- --label=org.opencontainers.image.revision={{ .FullCommit }}
5454
- --label=org.opencontainers.image.licenses=MIT
@@ -60,7 +60,7 @@ dockers:
6060
goos: linux
6161
goarch: arm64
6262
image_templates:
63-
- "temporalio/temporal-worker-controller:main-arm64"
63+
- "temporalio/temporal-worker-controller:{{ .Env.IMAGE_TAG }}-arm64"
6464
dockerfile: Dockerfile.goreleaser
6565
use: buildx
6666
build_flag_templates:
@@ -71,15 +71,15 @@ dockers:
7171
- --label=org.opencontainers.image.description=Temporal Worker Controller for Kubernetes
7272
- --label=org.opencontainers.image.url=https://github.com/temporalio/temporal-worker-controller
7373
- --label=org.opencontainers.image.source=https://github.com/temporalio/temporal-worker-controller
74-
- --label=org.opencontainers.image.version=main
74+
- --label=org.opencontainers.image.version={{ .Env.IMAGE_TAG }}
7575
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
7676
- --label=org.opencontainers.image.revision={{ .FullCommit }}
7777
- --label=org.opencontainers.image.licenses=MIT
7878
extra_files:
7979
- LICENSE
8080

8181
docker_manifests:
82-
- name_template: "temporalio/temporal-worker-controller:main"
82+
- name_template: "temporalio/temporal-worker-controller:{{ .Env.IMAGE_TAG }}"
8383
image_templates:
84-
- "temporalio/temporal-worker-controller:main-amd64"
85-
- "temporalio/temporal-worker-controller:main-arm64"
84+
- "temporalio/temporal-worker-controller:{{ .Env.IMAGE_TAG }}-amd64"
85+
- "temporalio/temporal-worker-controller:{{ .Env.IMAGE_TAG }}-arm64"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ We welcome all contributions! This includes:
164164

165165
Want to try the controller locally? Check out the [local demo guide](internal/demo/README.md) for development setup.
166166

167+
Need a test controller image from an unmerged branch? Run the `publish-branch-image` GitHub Actions workflow with the branch name.
168+
167169
## 📄 License
168170

169171
This project is licensed under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)