Skip to content

Commit 84c2380

Browse files
authored
Merge pull request #8 from chaptersix/alex/docker-pr-feedback
Address PR temporalio#877 Feedback: Simplify Dockerfile and Workflows
2 parents 90d4238 + 21f02c6 commit 84c2380

File tree

7 files changed

+131
-150
lines changed

7 files changed

+131
-150
lines changed

.github/docker/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/docker/cli.Dockerfile

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

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

Lines changed: 88 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ jobs:
3838
runs-on: ubuntu-latest
3939
steps:
4040
- name: Checkout
41-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
41+
uses: actions/checkout@v3
4242
with:
4343
fetch-depth: 0
4444

4545
- name: Set up Go
46-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
46+
uses: actions/setup-go@v4
4747
with:
4848
go-version-file: "go.mod"
4949
check-latest: true
@@ -69,6 +69,25 @@ jobs:
6969
id: go
7070
run: echo "go=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT
7171

72+
- name: Check if release is latest
73+
if: inputs.publish
74+
id: check_latest_release
75+
uses: actions/github-script@v7
76+
with:
77+
script: |
78+
const releaseTag = '${{ inputs.version }}';
79+
const { data: release } = await github.rest.repos.getReleaseByTag({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
tag: releaseTag
83+
});
84+
85+
const isLatest = !release.prerelease && !release.draft;
86+
core.setOutput('is_latest', isLatest);
87+
console.log(`Release: ${release.tag_name}`);
88+
console.log(`Prerelease: ${release.prerelease}, Draft: ${release.draft}`);
89+
console.log(`Should tag as latest: ${isLatest}`);
90+
7291
- name: Run GoReleaser (release)
7392
if: inputs.publish
7493
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
@@ -108,60 +127,70 @@ jobs:
108127
INPUT_REGISTRY_NAMESPACE: ${{ inputs.registry_namespace }}
109128
INPUT_IMAGE_NAME: ${{ inputs.image_name }}
110129
REPO_OWNER: ${{ github.repository_owner }}
111-
run: |
112-
echo "cli_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
113-
echo "image_sha_tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
114-
echo "image_branch_tag=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
115-
116-
if [[ "$INPUT_PUBLISH" == "true" ]]; then
117-
# Get version from input, strip 'v' prefix
118-
VERSION="$INPUT_VERSION"
119-
VERSION="${VERSION#v}"
120-
echo "version=$VERSION" >> $GITHUB_OUTPUT
121-
else
122-
echo "version=snapshot" >> $GITHUB_OUTPUT
123-
fi
124-
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
140-
else
141-
echo "registry_type=other" >> $GITHUB_OUTPUT
142-
fi
143-
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
130+
uses: actions/github-script@v7
131+
with:
132+
script: |
133+
const inputVersion = process.env.INPUT_VERSION;
134+
const inputPublish = process.env.INPUT_PUBLISH;
135+
const inputRegistry = process.env.INPUT_REGISTRY;
136+
const inputRegistryNamespace = process.env.INPUT_REGISTRY_NAMESPACE;
137+
const inputImageName = process.env.INPUT_IMAGE_NAME;
138+
const repoOwner = process.env.REPO_OWNER;
139+
140+
// Get git information
141+
const { execSync } = require('child_process');
142+
const cliSha = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
143+
const imageShaTag = execSync('git rev-parse --short HEAD', { encoding: 'utf8' }).trim();
144+
const imageBranchTag = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
145+
146+
core.setOutput('cli_sha', cliSha);
147+
core.setOutput('image_sha_tag', imageShaTag);
148+
core.setOutput('image_branch_tag', imageBranchTag);
149+
150+
// Determine version
151+
let version;
152+
if (inputPublish === 'true') {
153+
// Get version from input, strip 'v' prefix
154+
version = inputVersion.startsWith('v') ? inputVersion.slice(1) : inputVersion;
155+
} else {
156+
version = 'snapshot';
157+
}
158+
core.setOutput('version', version);
159+
160+
// Determine registry (with auto-detection for temporalio vs forks)
161+
let registry = inputRegistry;
162+
if (!registry) {
163+
if (repoOwner === 'temporalio') {
164+
registry = 'docker.io';
165+
} else {
166+
registry = 'ghcr.io';
167+
}
168+
}
169+
170+
// Determine registry type for authentication
171+
let registryType;
172+
if (registry === 'ghcr.io') {
173+
registryType = 'ghcr';
174+
} else if (registry === 'docker.io') {
175+
registryType = 'dockerhub';
176+
} else {
177+
registryType = 'other';
178+
}
179+
core.setOutput('registry_type', registryType);
180+
181+
// Set namespace (defaults to repository owner)
182+
const namespace = inputRegistryNamespace || repoOwner;
183+
core.setOutput('image_namespace', namespace);
184+
185+
// Set image name (defaults to 'temporal')
186+
const imageName = inputImageName || 'temporal';
187+
core.setOutput('image_name', imageName);
188+
189+
// For Docker Hub, use empty string as registry (special case)
190+
const imageRepo = registry === 'docker.io' ? '' : registry;
191+
core.setOutput('image_repo', imageRepo);
192+
193+
console.log(`Registry: ${registry}, Type: ${registryType}, Namespace: ${namespace}, Image: ${imageName}`);
165194
166195
- name: Log in to GitHub Container Registry
167196
if: inputs.publish && steps.meta.outputs.registry_type == 'ghcr'
@@ -182,15 +211,15 @@ jobs:
182211
if: inputs.publish
183212
run: |
184213
docker buildx bake \
185-
--file .github/docker/docker-bake.hcl \
214+
--file docker-bake.hcl \
186215
--push \
187216
cli
188217
env:
189218
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
190219
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
191220
IMAGE_BRANCH_TAG: ${{ steps.meta.outputs.image_branch_tag }}
192221
VERSION: ${{ steps.meta.outputs.version }}
193-
TAG_LATEST: false
222+
TAG_LATEST: ${{ steps.check_latest_release.outputs.is_latest == 'true' }}
194223
IMAGE_REPO: ${{ steps.meta.outputs.image_repo }}
195224
IMAGE_NAMESPACE: ${{ steps.meta.outputs.image_namespace }}
196225
IMAGE_NAME: ${{ steps.meta.outputs.image_name }}
@@ -200,7 +229,7 @@ jobs:
200229
if: ${{ !inputs.publish }}
201230
run: |
202231
docker buildx bake \
203-
--file .github/docker/docker-bake.hcl \
232+
--file docker-bake.hcl \
204233
cli
205234
env:
206235
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}

.github/workflows/update-latest-tag.yml

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout
19-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
19+
uses: actions/checkout@v3
2020
with:
2121
ref: ${{ github.event.release.tag_name }}
2222

@@ -47,22 +47,29 @@ jobs:
4747
- name: Get registry configuration
4848
if: steps.check_latest.outputs.is_latest == 'true'
4949
id: registry
50-
run: |
51-
REPO_OWNER="${{ github.repository_owner }}"
52-
53-
# Auto-detect registry based on repository owner
54-
if [[ "$REPO_OWNER" == "temporalio" ]]; then
55-
REGISTRY="docker.io"
56-
echo "type=dockerhub" >> $GITHUB_OUTPUT
57-
echo "repo=" >> $GITHUB_OUTPUT
58-
else
59-
REGISTRY="ghcr.io"
60-
echo "type=ghcr" >> $GITHUB_OUTPUT
61-
echo "repo=${REGISTRY}" >> $GITHUB_OUTPUT
62-
fi
63-
64-
echo "namespace=${REPO_OWNER}" >> $GITHUB_OUTPUT
65-
echo "image=temporal" >> $GITHUB_OUTPUT
50+
uses: actions/github-script@v7
51+
with:
52+
script: |
53+
const repoOwner = context.repo.owner;
54+
55+
// Auto-detect registry based on repository owner
56+
let registry, type, repo;
57+
if (repoOwner === 'temporalio') {
58+
registry = 'docker.io';
59+
type = 'dockerhub';
60+
repo = '';
61+
} else {
62+
registry = 'ghcr.io';
63+
type = 'ghcr';
64+
repo = registry;
65+
}
66+
67+
core.setOutput('type', type);
68+
core.setOutput('repo', repo);
69+
core.setOutput('namespace', repoOwner);
70+
core.setOutput('image', 'temporal');
71+
72+
console.log(`Registry: ${registry}, Type: ${type}, Namespace: ${repoOwner}`);
6673
6774
- name: Log in to GitHub Container Registry
6875
if: steps.check_latest.outputs.is_latest == 'true' && steps.registry.outputs.type == 'ghcr'

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Intermediate stage to normalize goreleaser output paths
2+
# This copies both architecture binaries and renames them to clean paths,
3+
# allowing the final stage to select the correct binary using TARGETARCH
4+
FROM scratch AS dist
5+
COPY dist/nix_linux_amd64_v1/temporal /dist/amd64/temporal
6+
COPY dist/nix_linux_arm64_v8.0/temporal /dist/arm64/temporal
7+
8+
FROM alpine:3.22@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412
9+
10+
ARG TARGETARCH
11+
12+
RUN apk add --no-cache ca-certificates
13+
COPY --chmod=755 --from=dist /dist/${TARGETARCH}/temporal /usr/local/bin/temporal
14+
RUN adduser -u 1000 -D temporal
15+
USER temporal
16+
17+
ENTRYPOINT ["temporal"]

Makefile

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,17 @@ variable "TAG_LATEST" {
3030
default = false
3131
}
3232

33-
# Alpine base image with digest for reproducible builds
34-
variable "ALPINE_IMAGE" {
35-
default = "alpine:3.22@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412"
36-
}
33+
3734

3835
target "cli" {
39-
dockerfile = ".github/docker/cli.Dockerfile"
36+
dockerfile = "Dockerfile"
4037
context = "."
4138
tags = compact([
4239
IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:${IMAGE_SHA_TAG}" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${IMAGE_SHA_TAG}",
4340
IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}",
4441
TAG_LATEST ? (IMAGE_REPO == "" ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest" : "${IMAGE_REPO}/${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest") : "",
4542
])
4643
platforms = ["linux/amd64", "linux/arm64"]
47-
args = {
48-
ALPINE_IMAGE = "${ALPINE_IMAGE}"
49-
}
5044
labels = {
5145
"org.opencontainers.image.title" = "temporal"
5246
"org.opencontainers.image.description" = "Temporal CLI"

0 commit comments

Comments
 (0)