Skip to content

Commit da6d754

Browse files
authored
Automate Docker Image Build and Publish (#877)
## What was changed * added GHA to build and publish docker images * Updated go releaser to v2 * Minor tweaks to other GHA ## Why? Make is easier to publish docker images on release.
1 parent 19449ab commit da6d754

File tree

7 files changed

+214
-72
lines changed

7 files changed

+214
-72
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version tag for the Docker image (e.g., 1.2.3 or v1.2.3)'
8+
required: true
9+
type: string
10+
publish:
11+
description: 'Push the image to Docker Hub'
12+
required: false
13+
type: boolean
14+
default: true
15+
tag_latest:
16+
description: 'Also tag this image as latest'
17+
required: false
18+
type: boolean
19+
default: false
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
build-and-publish:
26+
name: Build and Publish Docker Image
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v6
31+
with:
32+
persist-credentials: false
33+
34+
- name: Get build metadata from release
35+
id: meta
36+
env:
37+
INPUT_VERSION: ${{ inputs.version }}
38+
INPUT_TAG_LATEST: ${{ inputs.tag_latest }}
39+
uses: actions/github-script@v8
40+
with:
41+
script: |
42+
const inputVersion = process.env.INPUT_VERSION;
43+
const inputTagLatest = process.env.INPUT_TAG_LATEST;
44+
45+
const version = inputVersion.startsWith('v') ? inputVersion.slice(1) : inputVersion;
46+
const releaseTag = inputVersion.startsWith('v') ? inputVersion : `v${inputVersion}`;
47+
48+
const { data: release } = await github.rest.repos.getReleaseByTag({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
tag: releaseTag
52+
});
53+
54+
const cliSha = release.target_commitish;
55+
const imageShaTag = cliSha.substring(0, 7);
56+
57+
core.setOutput('cli_sha', cliSha);
58+
core.setOutput('image_sha_tag', imageShaTag);
59+
core.setOutput('version', version);
60+
core.setOutput('release_tag', releaseTag);
61+
core.setOutput('tag_latest', inputTagLatest === 'true');
62+
63+
- name: Download release assets
64+
env:
65+
GH_TOKEN: ${{ github.token }}
66+
RELEASE_TAG: ${{ steps.meta.outputs.release_tag }}
67+
run: |
68+
echo "Downloading assets from release ${RELEASE_TAG}..."
69+
gh release download "${RELEASE_TAG}" --pattern "temporal_*_linux_*.tar.gz"
70+
71+
echo "Extracting and organizing binaries..."
72+
mkdir -p dist/amd64 dist/arm64
73+
74+
tar -xzf temporal_*_linux_amd64.tar.gz
75+
mv temporal dist/amd64/temporal
76+
77+
tar -xzf temporal_*_linux_arm64.tar.gz
78+
mv temporal dist/arm64/temporal
79+
80+
echo "Verifying binaries..."
81+
ls -lh dist/amd64/temporal
82+
ls -lh dist/arm64/temporal
83+
84+
- name: Set up Docker Buildx
85+
uses: docker/setup-buildx-action@v3
86+
87+
- name: Log in to Docker Hub
88+
if: inputs.publish
89+
uses: docker/login-action@v3
90+
with:
91+
username: ${{ secrets.DOCKER_USERNAME }}
92+
password: ${{ secrets.DOCKER_PASSWORD }}
93+
94+
- name: Build and push Docker image
95+
if: inputs.publish
96+
run: |
97+
docker buildx bake \
98+
--file docker-bake.hcl \
99+
--push \
100+
cli
101+
env:
102+
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
103+
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
104+
VERSION: ${{ steps.meta.outputs.version }}
105+
TAG_LATEST: ${{ steps.meta.outputs.tag_latest }}
106+
IMAGE_NAMESPACE: temporalio
107+
IMAGE_NAME: temporal
108+
GITHUB_REPOSITORY: ${{ github.repository }}
109+
110+
- name: Build Docker image (no push)
111+
if: ${{ !inputs.publish }}
112+
run: |
113+
docker buildx bake \
114+
--file docker-bake.hcl \
115+
cli
116+
env:
117+
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
118+
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
119+
VERSION: ${{ steps.meta.outputs.version }}
120+
TAG_LATEST: ${{ steps.meta.outputs.tag_latest }}
121+
IMAGE_NAMESPACE: temporalio
122+
IMAGE_NAME: temporal
123+
GITHUB_REPOSITORY: ${{ github.repository }}
Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
1-
name: goreleaser
1+
name: Release
22

33
on:
44
workflow_dispatch:
55
release:
66
types:
77
- published
88

9+
permissions:
10+
contents: write
11+
912
jobs:
10-
goreleaser:
13+
release:
14+
name: Release
1115
runs-on: ubuntu-latest
1216
steps:
1317
- name: Checkout
14-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
18+
uses: actions/checkout@v6
1519
with:
1620
fetch-depth: 0
1721

1822
- name: Set up Go
19-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
23+
uses: actions/setup-go@v6
2024
with:
2125
go-version-file: "go.mod"
2226
check-latest: true
27+
cache: true
2328

2429
- name: Get build date
2530
id: date
26-
run: echo "::set-output name=date::$(date '+%F-%T')"
31+
run: echo "date=$(date '+%F-%T')" >> "$GITHUB_OUTPUT"
2732

2833
- name: Get build unix timestamp
2934
id: timestamp
30-
run: echo "::set-output name=timestamp::$(date '+%s')"
35+
run: echo "timestamp=$(date '+%s')" >> "$GITHUB_OUTPUT"
3136

3237
- name: Get git branch
3338
id: branch
34-
run: echo "::set-output name=branch::$(git rev-parse --abbrev-ref HEAD)"
39+
run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> "$GITHUB_OUTPUT"
3540

3641
- name: Get build platform
3742
id: platform
38-
run: echo "::set-output name=platform::$(go version | cut -d ' ' -f 4)"
43+
run: echo "platform=$(go version | cut -d ' ' -f 4)" >> "$GITHUB_OUTPUT"
3944

4045
- name: Get Go version
4146
id: go
42-
run: echo "::set-output name=go::$(go version | cut -d ' ' -f 3)"
47+
run: echo "go=$(go version | cut -d ' ' -f 3)" >> "$GITHUB_OUTPUT"
4348

4449
- name: Run GoReleaser
45-
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
50+
uses: goreleaser/goreleaser-action@v6
4651
with:
47-
version: v1.26.2
52+
version: v2.12.7
4853
args: release
4954
env:
5055
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/trigger-docs.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@ on:
33
workflow_dispatch:
44
release:
55
types: [published]
6+
7+
permissions:
8+
contents: read
9+
610
jobs:
711
update:
12+
if: github.repository == 'temporalio/cli'
813
runs-on: ubuntu-latest
914
defaults:
1015
run:
1116
shell: bash
1217
steps:
1318
- name: Get user info from GitHub API
1419
id: get_user
20+
env:
21+
GITHUB_ACTOR: ${{ github.actor }}
1522
run: |
16-
echo "GitHub actor: ${{ github.actor }}"
23+
echo "GitHub actor: ${GITHUB_ACTOR}"
1724
# Query the GitHub API for the user's details.
1825
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
19-
https://api.github.com/users/${{ github.actor }} > user.json
20-
26+
"https://api.github.com/users/${GITHUB_ACTOR}" > user.json
27+
2128
# Extract the user's full name if available, default to the username otherwise.
2229
git_name=$(jq -r '.name // empty' user.json)
2330
if [ -z "$git_name" ]; then
24-
git_name="${{ github.actor }}"
31+
git_name="${GITHUB_ACTOR}"
2532
fi
26-
27-
git_email="${{ github.actor }}@users.noreply.github.com"
28-
33+
34+
git_email="${GITHUB_ACTOR}@users.noreply.github.com"
35+
2936
# Set the outputs for subsequent steps.
30-
echo "GIT_NAME=$git_name" >> $GITHUB_OUTPUT
31-
echo "GIT_EMAIL=$git_email" >> $GITHUB_OUTPUT
37+
echo "GIT_NAME=$git_name" >> "$GITHUB_OUTPUT"
38+
echo "GIT_EMAIL=$git_email" >> "$GITHUB_OUTPUT"
3239
3340
- name: Generate token
3441
id: generate_token

.github/workflows/trigger-publish.yml

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

.goreleaser.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: 2
2+
13
before:
24
hooks:
35
- go mod download
@@ -11,24 +13,26 @@ archives:
1113
- <<: &archive_defaults
1214
name_template: "temporal_cli_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
1315
id: nix
14-
builds:
16+
ids:
1517
- nix
16-
format: tar.gz
18+
formats:
19+
- tar.gz
1720
files:
1821
- LICENSE
1922

2023
- <<: *archive_defaults
2124
id: windows-zip
22-
builds:
25+
ids:
2326
- windows
24-
format: zip
27+
formats:
28+
- zip
2529
files:
2630
- LICENSE
2731

2832
# used by SDKs as zip cannot be used by rust https://github.com/zip-rs/zip/issues/108
2933
- <<: *archive_defaults
3034
id: windows-targz
31-
builds:
35+
ids:
3236
- windows
3337
files:
3438
- LICENSE
@@ -61,7 +65,7 @@ checksum:
6165
algorithm: sha256
6266

6367
changelog:
64-
skip: true
68+
disable: true
6569

6670
announce:
6771
skip: "true"

Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
FROM --platform=$BUILDARCH scratch AS dist
2-
COPY ./dist/nix_linux_amd64_v1/temporal /dist/amd64/temporal
3-
COPY ./dist/nix_linux_arm64/temporal /dist/arm64/temporal
1+
FROM alpine:3.22@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412
42

5-
FROM alpine:3.22
63
ARG TARGETARCH
7-
RUN apk add --no-cache ca-certificates
8-
COPY --from=dist /dist/$TARGETARCH/temporal /usr/local/bin/temporal
4+
5+
RUN apk add --no-cache ca-certificates tzdata
6+
COPY dist/${TARGETARCH}/temporal /usr/local/bin/temporal
97
RUN adduser -u 1000 -D temporal
108
USER temporal
119

docker-bake.hcl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
variable "IMAGE_NAMESPACE" {
2+
default = ""
3+
}
4+
5+
variable "IMAGE_NAME" {
6+
default = "temporal"
7+
}
8+
9+
variable "GITHUB_REPOSITORY" {
10+
default = "temporalio/cli"
11+
}
12+
13+
variable "IMAGE_SHA_TAG" {}
14+
15+
variable "CLI_SHA" {
16+
default = ""
17+
}
18+
19+
variable "VERSION" {
20+
default = "dev"
21+
}
22+
23+
variable "TAG_LATEST" {
24+
default = false
25+
}
26+
27+
target "cli" {
28+
dockerfile = "Dockerfile"
29+
context = "."
30+
tags = compact([
31+
"${IMAGE_NAMESPACE}/${IMAGE_NAME}:${IMAGE_SHA_TAG}",
32+
"${IMAGE_NAMESPACE}/${IMAGE_NAME}:${VERSION}",
33+
TAG_LATEST ? "${IMAGE_NAMESPACE}/${IMAGE_NAME}:latest" : "",
34+
])
35+
platforms = ["linux/amd64", "linux/arm64"]
36+
labels = {
37+
"org.opencontainers.image.title" = "temporal"
38+
"org.opencontainers.image.description" = "Temporal CLI"
39+
"org.opencontainers.image.url" = "https://github.com/${GITHUB_REPOSITORY}"
40+
"org.opencontainers.image.source" = "https://github.com/${GITHUB_REPOSITORY}"
41+
"org.opencontainers.image.licenses" = "MIT"
42+
"org.opencontainers.image.revision" = "${CLI_SHA}"
43+
"org.opencontainers.image.created" = timestamp()
44+
}
45+
}

0 commit comments

Comments
 (0)