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