-
Notifications
You must be signed in to change notification settings - Fork 5
113 lines (107 loc) · 3.87 KB
/
Copy pathcalculator-svc.yml
File metadata and controls
113 lines (107 loc) · 3.87 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
name: calculator-svc
on:
push:
workflow_dispatch:
permissions: {}
env:
IMAGE_REF: "ghcr.io/${{ github.repository }}/calculator-svc"
jobs:
build-calculator-image:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
outputs:
digest: ${{ steps.build-container-image.outputs.Digest }}
steps:
- name: Check out repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: |
${{ env.IMAGE_REF }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=
type=sha,format=long,prefix=
type=semver,pattern={{version}}
type=semver,pattern=v{{version}}
type=ref,event=branch
- name: Log in to ghcr.io
id: docker-login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push container image
id: build-container-image
uses: docker/build-push-action@ca052bb54ab0790a636c9b5f226502c73d547a25 # v5.4.0
with:
context: .
file: cmd/calculator-svc/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
sign-calculator-image:
runs-on: ubuntu-22.04
needs:
- build-calculator-image
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Cosign CLI
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
- name: Log in to ghcr.io
id: docker-login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Sign calculator-image
run: |
cosign sign -y \
${{ env.IMAGE_REF }}@${{ needs.build-calculator-image.outputs.digest }}
cosign verify \
--certificate-identity-regexp https://github.com/datosh-org/most-secure-calculator/.github/workflows/calculator-svc.yml.* \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
${{ env.IMAGE_REF }}@${{ needs.build-calculator-image.outputs.digest }}
sbom-image:
runs-on: ubuntu-22.04
needs:
- build-calculator-image
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Log in to ghcr.io
id: docker-login
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Install syft & grype
uses: ./.github/actions/install_syft_grype
with:
syftVersion: "0.98.0"
grypeVersion: "0.73.3"
- name: Install Cosign CLI
uses: sigstore/cosign-installer@e1523de7571e31dbe865fd2e80c5c7c23ae71eb4 # v3.4.0
- name: Generate and sign SBOM
run: |
syft attest -o cyclonedx-json \
${{ env.IMAGE_REF }}@${{ needs.build-calculator-image.outputs.digest }} > calculator.att.json
- name: Check for known vulnerabilities
run: |
grype ${{ env.IMAGE_REF }}@${{ needs.build-calculator-image.outputs.digest }} \
--fail-on critical --only-fixed