-
Notifications
You must be signed in to change notification settings - Fork 18
85 lines (84 loc) · 2.95 KB
/
reusable.yml
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
on:
workflow_call:
inputs:
image:
required: true
type: string
tag:
required: true
type: number
arg:
required: false
type: string
default: ${{ inputs.tag }}
multiplatform:
required: false
type: boolean
default: false
sign:
required: false
type: boolean
default: false
env:
# Use ghcr.io for GitHub Container Registry if empty
REGISTRY: ghcr.io
jobs:
build:
name: Add temporary packages for testing
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge with sigstore/fulcio.
# It isn't possible to use `${{ inputs.sign && write || none }}` here.
id-token: write
steps:
- uses: actions/checkout@v4
# Install the cosign tool
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: ${{ inputs.sign }}
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da #v3.7.0
with:
cosign-release: 'v2.4.1'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker,
# set environments required for signing.
# Automatically sanitize tags (lowercasing,
# replace spaces with '_', etc.)
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.image }}
tags: type=raw,value=${{ inputs.tag }}
- name: Build and push
uses: docker/build-push-action@v5
id: build-and-push
with:
file: ./CICD/Dockerfile_temp
tags: ${{ steps.meta.outputs.tags }}
build-args: I=${{ inputs.arg }}
push: true
platforms: ${{ inputs.multiplatform && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
# Disable automatic manifest list by disabling attestation facts generation
provenance: ${{ !inputs.sign }}
sbom: ${{ !inputs.sign }}
# Sign the resulting Docker image digest
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ inputs.sign }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}