-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (93 loc) · 3.42 KB
/
docker.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
86
87
88
89
90
91
92
93
94
95
96
name: Docker Release
on:
workflow_dispatch:
inputs:
release:
description: 'Release version'
required: true
permissions: # added using https://github.com/step-security/secure-repo
contents: read
jobs:
build-docker-images:
name: Build Docker Images
runs-on: ubuntu-latest
permissions:
# Required to stop running workflows
actions: write
packages: write
steps:
-
uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142
with:
egress-policy: audit
disable-telemetry: true
-
name: Cancel previous workflows
uses: styfle/cancel-workflow-action@01ce38bf961b4e243a6342cbade0dbc8ba3f0432 # 0.12.0
with:
access_token: ${{ secrets.GITHUB_TOKEN }}
-
name: Checkout
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
-
name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
-
name: Install Cosign
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
-
name: Login to GHCR
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Docker meta
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
with:
images: |
ghcr.io/elastic/harp
-
id: build-and-push
name: Build and push
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
build-args: VERSION=${{ github.event.inputs.release }}
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:v${{ github.event.inputs.release }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Create SBOM
uses: anchore/sbom-action@ab5d7b5f48981941c4c5d6bf33aeb98fe3bae38c # v0.15.10
with:
image: ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }}
registry-username: ${{ github.actor }}
registry-password: ${{ github.token }}
artifact-name: sbom.spdx
format: spdx
-
name: Sign image and add attestations
run: |
echo -n "${COSIGN_PASSWORD}" | \
cosign sign --key <(echo -n "${COSIGN_KEY}") \
-a "repo=${{ github.repository }}" \
-a "workflow=${{ github.workflow }}" \
-a "ref=${{ github.sha }}" \
ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }}
cosign attach sbom --sbom sbom.spdx ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }}
env:
COSIGN_KEY: ${{ secrets.COSIGN_KEY }}
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
-
name: Verify the signature
run: |
cosign verify --key build/artifact/cosign.pub ghcr.io/${{ github.repository }}@${{ steps.build-and-push.outputs.digest }}