-
-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (142 loc) · 5.31 KB
/
ci.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: ci
on:
push:
paths:
- '**/Dockerfile'
- '**/.github/workflows/ci.yml'
- '**/docker-bake.hcl'
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
packages: write
pull-requests: write
env:
REGISTRY: ${{ (vars.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '') && 'docker.io' || 'ghcr.io' }}
REGISTRY_USER: ${{ (vars.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '') && vars.DOCKERHUB_USERNAME || github.repository_owner }}
GITHUB_SHA: ${{ github.event.pull_request.head.sha || github.event.after || github.sha }}
BUILDKIT_PROGRESS: plain
jobs:
test:
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.matrix.outputs.targets }}
steps:
- name: Checkout code
# kics-scan ignore-line
uses: actions/[email protected]
- name: Setup Docker Buildx
# kics-scan ignore-line
uses: docker/[email protected]
# get docker binary path to use it with env -i
- name: Get the docker binary path
id: docker-binary-path
run: echo "DOCKER_BINARY_PATH=$(which docker)" >> "$GITHUB_OUTPUT"
- name: Print the bake file with a empty env
id: bake-file-no-env
run: env -i ${{ steps.docker-binary-path.outputs.DOCKER_BINARY_PATH }} buildx bake --print
- name: Verify the tag ends on -local
run: |
BAKE_TAG="$(env -i ${{ steps.docker-binary-path.outputs.DOCKER_BINARY_PATH }} buildx bake --print | jq -r '[.target[].tags[]][0]')"
[[ "${BAKE_TAG}" == *"-local" ]] || exit 1
- name: Print the bake file with the runner env
run: docker buildx bake --print
- name: Validate tag ends on -${{ github.base_ref || github.ref_name }}
run: |
BAKE_TAG="$(docker buildx bake --print | jq -r '[.target[].tags[]][0]')"
[[ "${BAKE_TAG}" == *"-${{ github.base_ref || github.ref_name}}" ]] || exit 1
- name: Create matrix
id: matrix
run: printf "targets=%s\n" "$(docker buildx bake --print | jq -r '"\(.target | keys)"')" >>"${GITHUB_OUTPUT}"
- name: Show matrix
run: "echo '${{ steps.matrix.outputs.targets }}' | jq"
build:
needs: test
runs-on: ubuntu-latest
strategy:
matrix:
targets: ${{ fromJson(needs.test.outputs.targets) }}
steps:
- name: Checkout code
# kics-scan ignore-line
uses: actions/[email protected]
- name: Setup QEMU
# kics-scan ignore-line
uses: docker/[email protected]
# with:
# image: 'tonistiigi/binfmt:buildkit-latest'
- name: Setup Docker Buildx
# kics-scan ignore-line
uses: docker/[email protected]
# with:
# driver-opts: |
# image=moby/buildkit:latest
# # driver: ${{ github.event_name == 'pull_request' && 'docker' || 'docker-container' }}
# Login against a container registry
# https://github.com/docker/login-action
# kics-scan ignore-line
- uses: docker/[email protected]
name: Login to ${{ env.REGISTRY }}
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY == 'docker.io' && secrets.DOCKERHUB_TOKEN || secrets.GITHUB_TOKEN }}
logout: true
# Free up space on the runner since the image is huge
# kics-scan ignore-line
- uses: ./.github/actions/free-space
name: Free up disk space
with:
deleteDotnet: 'true'
deleteAndroid: 'true'
# Bake the image
# kics-scan ignore-line
- uses: docker/[email protected]
name: Build and Push
id: bake
with:
files: docker-bake.hcl
targets: ${{ matrix.targets }}
sbom: true
provenance: true
push: ${{ github.event_name != 'pull_request' }}
# # vulnerability scanning to verify PRs
# - name: Docker Scout
# id: docker-scout
# uses: docker/[email protected]
# if: github.event_name == 'pull_request'
# with:
# platform: ${{ matrix.platforms }}
# command: quickview
# image: ${{ env.FROM_IMAGE_PATH }}
# type: archive
# to: ${{ env.TO_TAG }}
# ignore-unchanged: true
# only-severities: critical
# write-comment: ${{ github.actor != 'nektos/act' }}
# summary: ${{ github.actor != 'nektos/act' }}
# github-token: ${{ secrets.GITHUB_TOKEN }}
# organization: ${{ vars.DOCKERHUB_USERNAME || github.repository_owner }}
approve-pr:
name: Approve PR
runs-on: ubuntu-latest
needs: [build]
if: >-
${{ github.actor != 'nektos/act' &&
contains(fromJson('["mauwii","dependabot[bot]"]'), github.triggering_actor) &&
github.event_name == 'pull_request' &&
needs.build.result == 'success' }}
permissions:
contents: read
pull-requests: write
actions: write
steps:
# approve the PR (there is still a code-owner review necessary)
- name: Approve PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}