forked from sapcc/helm-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (106 loc) · 3.45 KB
/
docker-push-input.yaml
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
114
115
116
117
118
119
120
121
122
123
124
name: Build, push, and scan Docker image with input
on:
workflow_dispatch:
inputs:
Dockerfile:
description: 'Dockerfile path to build'
required: true
type: string
ImageName:
description: 'Name of the image to build'
required: true
type: string
ImageTag:
description: 'Tag of the image to build'
required: true
type: string
dry-run:
description: 'Run the workflow without pushing the Docker image to the registry'
type: boolean
required: false
env:
REGISTRY: ghcr.io
jobs:
build:
name: Build
runs-on: [ ubuntu-latest ]
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Print inputs
run: |
echo "Dockerfile: ${{ inputs.Dockerfile }}"
echo "ImageName: ${{ inputs.ImageName }}"
echo "ImageTag: ${{ inputs.ImageTag }}"
echo "dry-run: ${{ inputs.dry-run }}"
- name: Checkout repository
uses: actions/checkout@v4
- name: Change directory to Dockerfile location
run: cd $(dirname ${{ inputs.Dockerfile }})
- name: Install cosign
uses: sigstore/cosign-installer@v3.7.0
with:
cosign-release: 'v2.2.3'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:latest
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.ImageName }}
tags: |
type=sha
type=raw,value=${{ inputs.ImageTag }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
file: ${{ inputs.Dockerfile }}
push: ${{ !inputs.dry-run }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
provenance: false
#platforms: |
# linux/amd64
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
vulnerability-scan:
permissions:
contents: read
packages: read
security-events: write
name: Vulnerability Scan
needs: build
runs-on: [ ubuntu-latest ]
steps:
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@0.29.0
if: success()
with:
image-ref: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.ImageName }}:${{ inputs.ImageTag }}
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: trivy-results.sarif