-
Notifications
You must be signed in to change notification settings - Fork 1
161 lines (144 loc) · 5.42 KB
/
ci.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
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
name: ci
on:
push:
branches: [master]
release:
types: [created]
pull_request:
branches: [master]
# Declare default permissions as read only.
permissions: read-all
jobs:
build:
name: build
runs-on: ubuntu-22.04
permissions:
packages: write
outputs:
image-tags: ${{ steps.container_meta.outputs.tags }}
image-digest: ${{ steps.build.outputs.digest }}
steps:
- name: Docker meta
id: container_meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5
with:
images: |
ghcr.io/${{ github.repository }}
docker.io/${{ github.repository }}
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3
- name: Login to DockerHub
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
if: github.event_name != 'pull_request'
with:
username: chgl
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: build
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5
with:
cache-from: type=gha
cache-to: type=gha,mode=max
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.container_meta.outputs.tags }}
labels: ${{ steps.container_meta.outputs.labels }}
release:
if: ${{ github.event_name != 'pull_request' }}
needs: build
name: Release
runs-on: ubuntu-22.04
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
with:
# via <https://stackoverflow.com/questions/74744498/github-pushing-to-protected-branches-with-fine-grained-token/76550826#76550826>
persist-credentials: false
# Only required temporary: https://github.com/cycjimmy/semantic-release-action/issues/159
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: 14
- name: Semantic Release
uses: cycjimmy/semantic-release-action@61680d0e9b02ff86f5648ade99e01be17f0260a4 # v4.0.0
with:
extra_plugins: |
@semantic-release/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.CI_SEMANTIC_RELEASE_TOKEN }}
sign-images:
if: ${{ github.event_name != 'pull_request' }}
name: sign images
runs-on: ubuntu-22.04
needs:
- build
permissions:
id-token: write
packages: write
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3
if: github.event_name != 'pull_request'
with:
registry: docker.io
username: chgl
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Install Cosign
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # tag=v3
- name: Sign image
env:
# <https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable>
TAGS: ${{ needs.build.outputs.image-tags }}
DIGEST: ${{ needs.build.outputs.image-digest }}
run: |
echo "${TAGS}" | xargs -I {} cosign sign --yes {}@"${DIGEST}"
ghcr-io-provenance:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs:
- build
permissions:
actions: read # for detecting the Github Actions environment.
# kics-scan ignore-line
id-token: write # for creating OIDC tokens for signing.
packages: write # for uploading attestations.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: "ghcr.io/${{ github.repository }}"
digest: ${{ needs.build.outputs.image-digest }}
registry-username: ${{ github.actor }}
secrets:
registry-password: "${{ secrets.GITHUB_TOKEN }}"
docker-io-provenance:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs:
- build
permissions:
actions: read # for detecting the Github Actions environment.
# kics-scan ignore-line
id-token: write # for creating OIDC tokens for signing.
packages: write # for uploading attestations.
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
image: "docker.io/${{ github.repository }}"
digest: ${{ needs.build.outputs.image-digest }}
registry-username: chgl
secrets:
registry-password: "${{ secrets.DOCKERHUB_TOKEN }}"