-
Notifications
You must be signed in to change notification settings - Fork 7
96 lines (85 loc) · 3.08 KB
/
docker.yaml
File metadata and controls
96 lines (85 loc) · 3.08 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
name: Build and Publish Docker Image
permissions:
contents: read
on:
push:
branches:
- main
release:
types: [published, prereleased]
workflow_dispatch:
inputs:
commit:
description: "Commit sha"
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref || inputs.commit || 'main' }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PAT }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
check-latest: true
- name: Set image names
id: image-names
env:
EVENT_NAME: ${{ github.event_name }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
echo "images=temporaliotest/s2s-proxy,temporalio/s2s-proxy" >> "$GITHUB_OUTPUT"
else
echo "images=temporaliotest/s2s-proxy" >> "$GITHUB_OUTPUT"
fi
- name: Compute version
id: version
# Produces the VERSION passed to `make bins` and used as the image tag.
# Three cases:
# local: "dev" local build (Makefile default, no VERSION arg).
# dispatch: "dev-<sha>" CI build on main push; set by docker.yaml. Or manual dispatch with a commit SHA.
# release: "v1.2.3" GitHub release; set to the release tag by docker.yaml.
env:
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
INPUT_COMMIT: ${{ inputs.commit }}
run: |
if [[ "$EVENT_NAME" == "release" ]]; then
echo "value=$REF_NAME" >> "$GITHUB_OUTPUT"
elif [[ "$EVENT_NAME" == "workflow_dispatch" ]]; then
SHA=$(echo "$INPUT_COMMIT" | cut -c1-7)
echo "value=dev-${SHA}" >> "$GITHUB_OUTPUT"
else
echo "value=dev-$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
fi
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.image-names.outputs.images }}
# Don't set latest label if it is a prerelease.
tags: |
type=raw,value=${{ steps.version.outputs.value }}
${{ github.event_name == 'release' && github.event.release.prerelease != true && 'type=raw,value=latest' || '' }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: VERSION=${{ steps.version.outputs.value }}
cache-from: type=gha
cache-to: type=gha,mode=max