Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
34 changes: 34 additions & 0 deletions .github/docker/cli.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# syntax=docker/dockerfile:1

ARG ALPINE_IMAGE
ARG BUILDARCH

# Build stage - copy binaries from goreleaser output
FROM --platform=$BUILDARCH scratch AS dist
COPY dist/nix_linux_amd64_v1/temporal /dist/amd64/temporal
COPY dist/nix_linux_arm64_v8.0/temporal /dist/arm64/temporal

# Stage to extract CA certificates and create user files
FROM ${ALPINE_IMAGE} AS certs
RUN apk add --no-cache ca-certificates && \
adduser -u 1000 -D temporal

# Final stage - minimal scratch-based image
FROM scratch

ARG TARGETARCH

# Copy CA certificates from certs stage
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy passwd and group files for non-root user
COPY --from=certs /etc/passwd /etc/passwd
COPY --from=certs /etc/group /etc/group

# Copy the appropriate binary for target architecture
COPY --from=dist /dist/$TARGETARCH/temporal /temporal

# Run as non-root user temporal (uid 1000)
USER 1000:1000

ENTRYPOINT ["/temporal"]
47 changes: 47 additions & 0 deletions .github/docker/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
variable "IMAGE_REPO" {
default = "temporalio"
}

variable "IMAGE_SHA_TAG" {}

variable "IMAGE_BRANCH_TAG" {}

variable "CLI_SHA" {
default = ""
}

variable "VERSION" {
default = "dev"
}

variable "TAG_LATEST" {
default = false
}

# Alpine base image with digest for reproducible builds
variable "ALPINE_IMAGE" {
default = "alpine:3.22@sha256:4b7ce07002c69e8f3d704a9c5d6fd3053be500b7f1c69fc0d80990c2ad8dd412"
}

target "cli" {
dockerfile = ".github/docker/cli.Dockerfile"
context = "."
tags = compact([
"${IMAGE_REPO}/temporal:${IMAGE_SHA_TAG}",
"${IMAGE_REPO}/temporal:${VERSION}",
TAG_LATEST ? "${IMAGE_REPO}/temporal:latest" : "",
])
platforms = ["linux/amd64", "linux/arm64"]
args = {
ALPINE_IMAGE = "${ALPINE_IMAGE}"
}
labels = {
"org.opencontainers.image.title" = "temporal"
"org.opencontainers.image.description" = "Temporal CLI"
"org.opencontainers.image.url" = "https://github.com/temporalio/cli"
"org.opencontainers.image.source" = "https://github.com/temporalio/cli"
"org.opencontainers.image.licenses" = "MIT"
"org.opencontainers.image.revision" = "${CLI_SHA}"
"org.opencontainers.image.created" = timestamp()
}
}
171 changes: 171 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Build and Publish (Reusable)

on:
workflow_call:
inputs:
publish:
description: "Whether to publish the release and Docker image"
required: true
type: boolean
version:
description: "Version tag for the release (required if publish is true)"
required: false
type: string
secrets:
DOCKER_USERNAME:
required: false
DOCKER_PASSWORD:
required: false

jobs:
build:
name: Build and Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: "go.mod"
check-latest: true
cache: true

- name: Get build date
id: date
run: echo "date=$(date '+%F-%T')" >> $GITHUB_OUTPUT

- name: Get build unix timestamp
id: timestamp
run: echo "timestamp=$(date '+%s')" >> $GITHUB_OUTPUT

- name: Get git branch
id: branch
run: echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT

- name: Get build platform
id: platform
run: echo "platform=$(go version | cut -d ' ' -f 4)" >> $GITHUB_OUTPUT

- name: Get Go version
id: go
run: echo "go=$(go version | cut -d ' ' -f 3)" >> $GITHUB_OUTPUT

- name: Run GoReleaser (release)
if: inputs.publish
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
version: v2.12.7
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_DATE: ${{ steps.date.outputs.date }}
BUILD_TS_UNIX: ${{ steps.timestamp.outputs.timestamp }}
GIT_BRANCH: ${{ steps.branch.outputs.branch }}
BUILD_PLATFORM: ${{ steps.platform.outputs.platform }}
GO_VERSION: ${{ steps.go.outputs.go }}

- name: Run GoReleaser (snapshot)
if: ${{ !inputs.publish }}
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
with:
version: v2.12.7
args: release --snapshot --clean
env:
BUILD_DATE: ${{ steps.date.outputs.date }}
BUILD_TS_UNIX: ${{ steps.timestamp.outputs.timestamp }}
GIT_BRANCH: ${{ steps.branch.outputs.branch }}
BUILD_PLATFORM: ${{ steps.platform.outputs.platform }}
GO_VERSION: ${{ steps.go.outputs.go }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
if: inputs.publish && github.repository_owner == 'temporalio'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get build metadata
id: meta
env:
INPUT_VERSION: ${{ inputs.version }}
INPUT_PUBLISH: ${{ inputs.publish }}
REPO_OWNER: ${{ github.repository_owner }}
run: |
echo "cli_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
echo "image_sha_tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "image_branch_tag=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT

if [[ "$INPUT_PUBLISH" == "true" ]]; then
# Get version from input, strip 'v' prefix
VERSION="$INPUT_VERSION"
VERSION="${VERSION#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "version=snapshot" >> $GITHUB_OUTPUT
fi

# Determine image repo based on repository owner
if [[ "$REPO_OWNER" == "temporalio" ]]; then
echo "image_repo=temporalio" >> $GITHUB_OUTPUT
else
echo "image_repo=$REPO_OWNER" >> $GITHUB_OUTPUT
fi

- name: Check if release is latest
if: inputs.publish
id: check_latest
uses: actions/github-script@v7
with:
script: |
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.ref.replace('refs/tags/', '')
});
// Tag as latest only if release is marked as latest (not pre-release)
core.setOutput('tag_latest', release.prerelease ? 'false' : 'true');
console.log(`Release prerelease: ${release.prerelease}, tag_latest: ${!release.prerelease}`)

- name: Build and push Docker image
if: inputs.publish && github.repository_owner == 'temporalio'
run: |
docker buildx bake \
--file .github/docker/docker-bake.hcl \
--push \
cli
env:
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
IMAGE_BRANCH_TAG: ${{ steps.meta.outputs.image_branch_tag }}
VERSION: ${{ steps.meta.outputs.version }}
TAG_LATEST: ${{ steps.check_latest.outputs.tag_latest }}
IMAGE_REPO: temporalio

- name: Build Docker image
if: ${{ !inputs.publish }}
run: |
docker buildx bake \
--file .github/docker/docker-bake.hcl \
cli
env:
CLI_SHA: ${{ steps.meta.outputs.cli_sha }}
IMAGE_SHA_TAG: ${{ steps.meta.outputs.image_sha_tag }}
IMAGE_BRANCH_TAG: ${{ steps.meta.outputs.image_branch_tag }}
VERSION: ${{ steps.meta.outputs.version }}
TAG_LATEST: false
IMAGE_REPO: temporalio

- name: Upload build artifacts
if: ${{ !inputs.publish }}
uses: actions/upload-artifact@v4
with:
name: temporal-cli-dist
path: dist/
retention-days: 7
15 changes: 15 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build Docker Image

on:
pull_request:
push:
branches:
- main

jobs:
build:
permissions:
contents: read
uses: ./.github/workflows/build-and-publish.yml
with:
publish: false
59 changes: 12 additions & 47 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,20 @@
name: goreleaser
name: Release

on:
workflow_dispatch:
release:
types:
- published

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
with:
go-version-file: "go.mod"
check-latest: true

- name: Get build date
id: date
run: echo "::set-output name=date::$(date '+%F-%T')"

- name: Get build unix timestamp
id: timestamp
run: echo "::set-output name=timestamp::$(date '+%s')"

- name: Get git branch
id: branch
run: echo "::set-output name=branch::$(git rev-parse --abbrev-ref HEAD)"
permissions:
contents: write

- name: Get build platform
id: platform
run: echo "::set-output name=platform::$(go version | cut -d ' ' -f 4)"

- name: Get Go version
id: go
run: echo "::set-output name=go::$(go version | cut -d ' ' -f 3)"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7 # v4.3.0
with:
version: v1.26.2
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_DATE: ${{ steps.date.outputs.date }}
BUILD_TS_UNIX: ${{ steps.timestamp.outputs.timestamp }}
GIT_BRANCH: ${{ steps.branch.outputs.branch }}
BUILD_PLATFORM: ${{ steps.platform.outputs.platform }}
GO_VERSION: ${{ steps.go.outputs.go }}
jobs:
release:
uses: ./.github/workflows/build-and-publish.yml
with:
publish: true
version: ${{ github.ref_name }}
secrets:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
40 changes: 0 additions & 40 deletions .github/workflows/trigger-publish.yml

This file was deleted.

Loading
Loading