-
Notifications
You must be signed in to change notification settings - Fork 5
84 lines (70 loc) · 2.69 KB
/
publish.yml
File metadata and controls
84 lines (70 loc) · 2.69 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
name: Build and Publish Docker Image
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: 'Tag for the Docker image (default: latest)'
required: false
default: 'latest'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v4
- name: Set up Go
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5
with:
go-version-file: 'go.mod'
- name: Compute version number
id: version-string
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
# For tags, use the tag as is
TAG="${{ github.ref_name }}"
else
# Fallback to using the input tag
TAG="${{ github.event.inputs.tag }}"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Using tag: $TAG"
- name: Log in to the Container registry
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup ko
uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
- name: Install Cosign
uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0
- name: Build and Push Image to GHCR
run: |
BASE_REPO=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
TAGS="-t $TAG"
# Add latest tag only if building from a tag
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
TAGS="$TAGS -t latest"
fi
KO_DOCKER_REPO=$BASE_REPO ko build --platform=linux/amd64,linux/arm64 --bare $TAGS ./ \
--image-label=org.opencontainers.image.source=https://github.com/stacklok/frizbee-action,org.opencontainers.image.title="frizbee-action",org.opencontainers.image.vendor=Stacklok
- name: Sign Image with Cosign
run: |
BASE_REPO=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
# Sign the ko image
cosign sign -y $BASE_REPO:$TAG
# Sign the latest tag if building from a tag
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
cosign sign -y $BASE_REPO:latest
fi