-
Notifications
You must be signed in to change notification settings - Fork 7
302 lines (298 loc) · 10.8 KB
/
commit.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
---
name: "Commit"
on:
push:
branches:
- main
pull_request:
branches:
- main
defaults:
run:
shell: 'bash --noprofile --norc -Eeuo pipefail {0}'
env:
python_version: "3.11"
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- uses: seisollc/goat@main
with:
exclude: (.*tests/(ansible|terraform|cloudformation)/.*|.*build/Dockerfile\.j2$)
disable_mypy: true
generate-matrixes:
name: Generate matrixes for future use in pipelines
runs-on: ubuntu-22.04
outputs:
image-matrix: ${{ steps.set-image-outputs.outputs.image-matrix }}
test-matrix: ${{ steps.set-testing-outputs.outputs.test-matrix }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
- name: Install the dependencies
run: python -m pip install --upgrade pipenv
- name: Install Task
uses: arduino/setup-task@v2
- name: Initialize the repo
run: task -v init
- name: Gather the image matrix
id: set-image-outputs
run: |
pipenv run python -c \
'from easy_infra import utils; \
print(utils.get_github_actions_matrix())' >> "${GITHUB_OUTPUT}"
- name: Gather the testing matrix
id: set-testing-outputs
run: |
pipenv run python -c \
'from easy_infra import utils; \
print(utils.get_github_actions_matrix(testing=True))' >> "${GITHUB_OUTPUT}"
test:
name: Test
needs: [generate-matrixes]
if: github.event_name == 'pull_request'
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate-matrixes.outputs.test-matrix) }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
- name: Install the dependencies
run: |
python -m pip install --upgrade pipenv
mkdir "${RUNNER_TEMP}/bin"
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
chmod +x "${RUNNER_TEMP}/bin/syft"
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
chmod +x "${RUNNER_TEMP}/bin/grype"
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
- name: Install Task
uses: arduino/setup-task@v2
- name: Initialize the repo
run: task -v init
- name: Build the image
run: task -v build
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Generate the SBOM
run: task -v sbom
if: matrix.user == 'root'
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Upload the SBOM
uses: actions/upload-artifact@v4
if: matrix.user == 'root'
with:
name: SBOM_${{ matrix.tool }}_${{ matrix.environment }}
path: sbom.2*.json
if-no-files-found: error
- name: Generate Vuln scan results
run: task -v vulnscan
if: matrix.user == 'root'
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Upload Vuln scan result
uses: actions/upload-artifact@v4
if: matrix.user == 'root'
with:
name: Vulns_${{ matrix.tool }}_${{ matrix.environment }}
path: vulns.2*.json
if-no-files-found: error
- name: Run tests
run: task -v test
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
USER: ${{ matrix.user }}
DEBUG: "True"
bump-version:
name: Bump version
needs: [lint]
if: "${{ github.event_name == 'push' && !startsWith(github.event.head_commit.message, 'Bump version: 2') }}"
permissions:
contents: write
runs-on: ubuntu-22.04
outputs:
git_tag: ${{ steps.bump-version.outputs.git_tag }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
token: ${{ secrets.SEISO_AUTOMATION_PAT }}
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
- name: Install the dependencies
run: python -m pip install --upgrade pipenv
- name: Install Task
uses: arduino/setup-task@v2
- name: Initialize the repo
run: task -v init
- name: Bump the version
id: bump-version
run: |
task -v release
GIT_TAG="$(git describe --tags)"
BRANCH="$(git branch --show-current)"
git push --atomic origin "${BRANCH}" "${GIT_TAG}"
echo "git_tag=${GIT_TAG}" >> "${GITHUB_OUTPUT}"
distribute:
name: Distribute
needs: [generate-matrixes, bump-version]
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.generate-matrixes.outputs.image-matrix) }}
if: "${{ github.event_name == 'push' && !startsWith(github.event.head_commit.message, 'Bump version: 2') }}"
environment: "${{ needs.bump-version.outputs.git_tag }}"
runs-on: ubuntu-22.04
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: "${{ needs.bump-version.outputs.git_tag }}"
- uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v4
with:
path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ env.python_version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
- name: Install the dependencies
run: |
python -m pip install --upgrade pipenv
mkdir "${RUNNER_TEMP}/bin"
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
chmod +x "${RUNNER_TEMP}/bin/syft"
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
chmod +x "${RUNNER_TEMP}/bin/grype"
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
- name: Install Task
uses: arduino/setup-task@v2
- name: Initialize the repo
run: task -v init
- name: Build the image
run: task -v build
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Generate the SBOM
run: task -v sbom
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Upload the SBOM
uses: actions/upload-artifact@v4
with:
name: SBOM_${{ matrix.tool }}_${{ matrix.environment }}
path: sbom.2*.json
if-no-files-found: error
- name: Generate Vuln scan results
run: task -v vulnscan
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Upload Vuln scan result
uses: actions/upload-artifact@v4
with:
name: Vulns_${{ matrix.tool }}_${{ matrix.environment }}
path: vulns.2*.json
if-no-files-found: error
- name: Run tests
run: task -v test
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
USER: ${{ matrix.user }}
DEBUG: "True"
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish the image to Docker Hub
run: task -v publish
env:
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
- name: Install cosign
uses: sigstore/cosign-installer@main
- name: Sign the image
run: |
image_and_versioned_tag=$(pipenv run python -c \
"from easy_infra.utils import get_image_and_tag; \
print(get_image_and_tag(tool='${TOOL}', environment='${ENVIRONMENT}'))")
versioned_tag="${image_and_versioned_tag#*:}"
# Requires that the image is available in the local daemon and was pushed to the remote repo
image_and_digest=$(docker inspect --format='{{index .RepoDigests 0}}' \
"${image_and_versioned_tag}" )
echo -n "${COSIGN_PASSWORD}" |
cosign sign --yes --key cosign.key \
-a git_sha="${GITHUB_SHA}" \
-a tag="${versioned_tag}" \
"${image_and_digest}"
env:
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
TOOL: ${{ matrix.tool }}
ENVIRONMENT: ${{ matrix.environment }}
finalize-the-release:
name: Finalize the release
needs: [bump-version, distribute]
if: "${{ github.event_name == 'push' && !startsWith(github.event.head_commit.message, 'Bump version: 2') }}"
runs-on: ubuntu-22.04
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: "${{ needs.bump-version.outputs.git_tag }}"
- name: Download the SBOMs and Vuln scan results
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}
- name: Publish the release to GitHub
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ needs.bump-version.outputs.git_tag }}
tag_name: ${{ needs.bump-version.outputs.git_tag }}
generate_release_notes: true
files: |
${{ runner.temp }}/Vulns_*/vulns.*.json
${{ runner.temp }}/SBOM_*/sbom.*.json
fail_on_unmatched_files: true
draft: false
prerelease: false
- name: Publish the release README to Docker Hub
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: seiso/easy_infra