Skip to content

Commit 2c95596

Browse files
committed
Improve repository and registry parameterization
This change makes Docker image publishing fully configurable while maintaining backward compatibility with both temporalio (Docker Hub) and forks (GHCR). Changes: - Add workflow inputs: registry, registry_namespace, and image_name - Smart defaults: temporalio uses Docker Hub, forks use GHCR - Conditional authentication for multiple registries - Standardize image name to "temporal" everywhere - Proper handling of Docker Hub's no-prefix format Workflow inputs (all optional with smart defaults): - registry: Container registry (docker.io, ghcr.io, etc.) - registry_namespace: Organization/user (defaults to repository_owner) - image_name: Image name (defaults to "temporal") Default behavior: - temporalio/cli → docker.io/temporalio/temporal - forks → ghcr.io/{owner}/temporal This design is PR-able to upstream while working for forks out of the box.
1 parent 305e867 commit 2c95596

3 files changed

Lines changed: 95 additions & 17 deletions

File tree

.github/docker/docker-bake.hcl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
variable "IMAGE_REPO" {
2-
default = "ghcr.io/chaptersix"
2+
default = "ghcr.io"
3+
}
4+
5+
variable "IMAGE_NAMESPACE" {
6+
default = ""
7+
}
8+
9+
variable "IMAGE_NAME" {
10+
default = "temporal"
311
}
412

513
variable "IMAGE_SHA_TAG" {}
@@ -27,9 +35,9 @@ target "cli" {
2735
dockerfile = ".github/docker/cli.Dockerfile"
2836
context = "."
2937
tags = compact([
30-
"${IMAGE_REPO}/temporal-cli:${IMAGE_SHA_TAG}",
31-
"${IMAGE_REPO}/temporal-cli:${VERSION}",
32-
TAG_LATEST ? "${IMAGE_REPO}/temporal-cli:latest" : "",
38+
IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:${IMAGE_SHA_TAG}" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${IMAGE_SHA_TAG}",
39+
IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}",
40+
TAG_LATEST ? (IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest") : "",
3341
])
3442
platforms = ["linux/amd64", "linux/arm64"]
3543
args = {

.github/workflows/build-and-publish.yml

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,26 @@ on:
1111
description: "Version tag for the release (required if publish is true)"
1212
required: false
1313
type: string
14-
secrets: {}
14+
registry:
15+
description: "Container registry (docker.io, ghcr.io, etc.)"
16+
required: false
17+
type: string
18+
default: ""
19+
registry_namespace:
20+
description: "Registry namespace/organization"
21+
required: false
22+
type: string
23+
default: ""
24+
image_name:
25+
description: "Image name"
26+
required: false
27+
type: string
28+
default: "temporal"
29+
secrets:
30+
DOCKER_USERNAME:
31+
required: false
32+
DOCKER_PASSWORD:
33+
required: false
1534

1635
jobs:
1736
build:
@@ -80,19 +99,14 @@ jobs:
8099
- name: Set up Docker Buildx
81100
uses: docker/setup-buildx-action@v3
82101

83-
- name: Log in to GitHub Container Registry
84-
if: inputs.publish
85-
uses: docker/login-action@v3
86-
with:
87-
registry: ghcr.io
88-
username: ${{ github.actor }}
89-
password: ${{ secrets.GITHUB_TOKEN }}
90-
91102
- name: Get build metadata
92103
id: meta
93104
env:
94105
INPUT_VERSION: ${{ inputs.version }}
95106
INPUT_PUBLISH: ${{ inputs.publish }}
107+
INPUT_REGISTRY: ${{ inputs.registry }}
108+
INPUT_REGISTRY_NAMESPACE: ${{ inputs.registry_namespace }}
109+
INPUT_IMAGE_NAME: ${{ inputs.image_name }}
96110
REPO_OWNER: ${{ github.repository_owner }}
97111
run: |
98112
echo "cli_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
@@ -108,13 +122,62 @@ jobs:
108122
echo "version=snapshot" >> $GITHUB_OUTPUT
109123
fi
110124
111-
# Determine image repo based on repository owner
112-
if [[ "$REPO_OWNER" == "temporalio" ]]; then
113-
echo "image_repo=temporalio" >> $GITHUB_OUTPUT
125+
# Determine registry (with auto-detection for temporalio vs forks)
126+
REGISTRY="$INPUT_REGISTRY"
127+
if [[ -z "$REGISTRY" ]]; then
128+
if [[ "$REPO_OWNER" == "temporalio" ]]; then
129+
REGISTRY="docker.io"
130+
else
131+
REGISTRY="ghcr.io"
132+
fi
133+
fi
134+
135+
# Determine registry type for authentication
136+
if [[ "$REGISTRY" == "ghcr.io" ]]; then
137+
echo "registry_type=ghcr" >> $GITHUB_OUTPUT
138+
elif [[ "$REGISTRY" == "docker.io" ]]; then
139+
echo "registry_type=dockerhub" >> $GITHUB_OUTPUT
114140
else
115-
echo "image_repo=ghcr.io/$REPO_OWNER" >> $GITHUB_OUTPUT
141+
echo "registry_type=other" >> $GITHUB_OUTPUT
116142
fi
117143
144+
# Set namespace (defaults to repository owner)
145+
NAMESPACE="$INPUT_REGISTRY_NAMESPACE"
146+
if [[ -z "$NAMESPACE" ]]; then
147+
NAMESPACE="$REPO_OWNER"
148+
fi
149+
150+
# Set image name (defaults to 'temporal')
151+
IMAGE_NAME="$INPUT_IMAGE_NAME"
152+
if [[ -z "$IMAGE_NAME" ]]; then
153+
IMAGE_NAME="temporal"
154+
fi
155+
156+
# For Docker Hub, use empty string as registry (special case)
157+
if [[ "$REGISTRY" == "docker.io" ]]; then
158+
echo "image_repo=" >> $GITHUB_OUTPUT
159+
else
160+
echo "image_repo=${REGISTRY}" >> $GITHUB_OUTPUT
161+
fi
162+
163+
echo "image_namespace=${NAMESPACE}" >> $GITHUB_OUTPUT
164+
echo "image_name=${IMAGE_NAME}" >> $GITHUB_OUTPUT
165+
166+
- name: Log in to GitHub Container Registry
167+
if: inputs.publish && steps.meta.outputs.registry_type == 'ghcr'
168+
uses: docker/login-action@v3
169+
with:
170+
registry: ghcr.io
171+
username: ${{ github.actor }}
172+
password: ${{ secrets.GITHUB_TOKEN }}
173+
174+
- name: Log in to Docker Hub
175+
if: inputs.publish && steps.meta.outputs.registry_type == 'dockerhub'
176+
uses: docker/login-action@v3
177+
with:
178+
username: ${{ secrets.DOCKER_USERNAME }}
179+
password: ${{ secrets.DOCKER_PASSWORD }}
180+
118181
- name: Check if release is latest
119182
if: inputs.publish
120183
id: check_latest
@@ -144,6 +207,8 @@ jobs:
144207
VERSION: ${{ steps.meta.outputs.version }}
145208
TAG_LATEST: ${{ steps.check_latest.outputs.tag_latest }}
146209
IMAGE_REPO: ${{ steps.meta.outputs.image_repo }}
210+
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
211+
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
147212

148213
- name: Build Docker image
149214
if: ${{ !inputs.publish }}
@@ -158,6 +223,8 @@ jobs:
158223
VERSION: ${{ steps.meta.outputs.version }}
159224
TAG_LATEST: false
160225
IMAGE_REPO: ${{ steps.meta.outputs.image_repo }}
226+
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
227+
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
161228

162229
- name: Upload build artifacts
163230
if: ${{ !inputs.publish }}

.github/workflows/goreleaser.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ jobs:
1515
with:
1616
publish: true
1717
version: ${{ github.ref_name }}
18+
secrets:
19+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
20+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

0 commit comments

Comments
 (0)