-
Notifications
You must be signed in to change notification settings - Fork 7
259 lines (256 loc) · 10.5 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
---
name: "Commit"
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
python_version: "3.10"
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- 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@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v3
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
pipenv install --python ${{ env.python_version }} --deploy --ignore-pipfile --dev
- 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@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v3
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
pipenv install --python ${{ env.python_version }} --deploy --ignore-pipfile --dev
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: Build the image
run: pipenv run invoke build --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Generate the SBOM
run: pipenv run invoke sbom --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Upload the SBOM
uses: actions/upload-artifact@v3
with:
name: SBOM_${{ matrix.tool }}_${{ matrix.environment }}
path: sbom.*.json
if-no-files-found: error
- name: Generate Vuln scan results
run: pipenv run invoke vulnscan --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Upload Vuln scan result
uses: actions/upload-artifact@v3
with:
name: Vulns_${{ matrix.tool }}_${{ matrix.environment }}
path: vulns.*.json
if-no-files-found: error
- name: Run tests
run: |
find tests -mindepth 1 -type d -exec chmod o+w {} \;
pipenv run invoke test --tool=${{ matrix.tool }} --environment=${{ matrix.environment }} --user=${{ matrix.user }} --debug
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@v3
with:
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v3
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
pipenv install --python ${{ env.python_version }} --deploy --ignore-pipfile --dev
- name: Bump the version
id: bump-version
run: |
git config --global user.name 'Seiso Automation'
git config --global user.email '[email protected]'
pipenv run invoke 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@v3
with:
fetch-depth: 0
ref: "${{ needs.bump-version.outputs.git_tag }}"
- uses: actions/setup-python@v4
with:
python-version: ${{ env.python_version }}
- uses: actions/cache@v3
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
pipenv install --python ${{ env.python_version }} --deploy --ignore-pipfile --dev
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: Build the image
run: pipenv run invoke build --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Generate the SBOM
run: pipenv run invoke sbom --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Upload the SBOM
uses: actions/upload-artifact@v3
with:
name: SBOM_${{ matrix.tool }}_${{ matrix.environment }}
path: sbom.*.json
if-no-files-found: error
- name: Generate Vuln scan results
run: pipenv run invoke vulnscan --tool=${{ matrix.tool }} --environment=${{ matrix.environment }}
- name: Upload Vuln scan result
uses: actions/upload-artifact@v3
with:
name: Vulns_${{ matrix.tool }}_${{ matrix.environment }}
path: vulns.*.json
if-no-files-found: error
- name: Run tests
run: |
find tests -mindepth 1 -type d -exec chmod o+w {} \;
pipenv run invoke test --tool=${{ matrix.tool }} --environment=${{ matrix.environment }} --user=${{ matrix.user }} --debug
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Publish the image to Docker Hub
run: pipenv run invoke publish --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@v3
with:
fetch-depth: 0
ref: "${{ needs.bump-version.outputs.git_tag }}"
- name: Download the SBOMs and Vuln scan results
uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}
- name: Publish the release to GitHub
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: ${{ steps.bump-version.outputs.git_tag }}
tag_name: ${{ steps.bump-version.outputs.git_tag }}
generate_release_notes: true
files: |
Vulns_*/vulns.*.json
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@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: seiso/easy_infra