-
Notifications
You must be signed in to change notification settings - Fork 1
210 lines (192 loc) · 8.44 KB
/
image-and-helm-publish-check-deploy-on-push-scheduled.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
# Scan & Publish image and helm chart on push, deployment on push, delete deployment on branch deletion, scheduled trivy scanner
name: "Dev Pipeline"
# All triggers have to be in one file, so that the trivy results can be compared to identify introduced vulnerabilities
# See DBP-340
on:
push:
branches:
- "**"
schedule:
- cron: '0 2 * * *'
delete:
concurrency:
group: dbildungs-iam-server-${{ github.event.ref }}
cancel-in-progress: true
jobs:
codeql_analyze:
name: "CodeQL"
if: ${{ github.event_name == 'push' }}
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/check-codeql.yaml@5
permissions:
actions: read
contents: read
security-events: write
nest_lint:
name: "Linting"
if: ${{ github.event_name == 'push' }}
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/check-nest-lint.yaml@5
with:
node_version: '18'
permissions:
contents: read
tests_and_sonarcloud:
name: "Tests and Sonarcloud"
if: ${{ github.event_name == 'push' }}
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/check-nest-test-sonarcloud.yaml@5
with:
node_version: '18'
deploy_stage: 'dev'
timeout_minutes: 20
permissions:
contents: read
secrets: inherit
determine_image_tag_and_chart_version:
name: "Determine image tag and chart version from branch name"
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.create_image_tag.outputs.image_tag }}
chart_version: ${{ steps.create_image_tag.outputs.chart_version }}
steps:
- id: create_image_tag
run: |
timestamp=`echo $(date +'%Y%m%d-%H%M')`
regex_long='^([[:alpha:]]+?-[[:digit:]]+-[[:digit:]]+)'
regex_short='^([[:alpha:]]+?-[[:digit:]]+)'
if [[ $GITHUB_REF_NAME =~ $regex_long ]]; then
tag="${BASH_REMATCH[1]}"
chart_version="0.0.0-$(echo ${tag} | tr [A-Z] [a-z])-${timestamp}"
elif [[ $GITHUB_REF_NAME =~ $regex_short ]]; then
tag="${BASH_REMATCH[1]}"
chart_version="0.0.0-$(echo ${tag} | tr [A-Z] [a-z])-${timestamp}"
elif [[ "${{ github.ref_name }}" != 'main' ]]; then
tag=""
chart_version=""
else
echo "::error::Couldn't extract ticket from branch $GITHUB_REF_NAME. If not main the branch name should begin alpha-digit or alpha-digit-digit blocks (e.g. SPSH-1234-test-name or release-1-1-optional-text)"
exit 1
fi
echo "image_tag=${tag}" >> "$GITHUB_OUTPUT"
echo "chart_version=${chart_version}" >> "$GITHUB_OUTPUT"
build_image_on_push:
needs:
- determine_image_tag_and_chart_version
name: "Publish image and scan with trivy"
if: ${{ github.event_name == 'push' }}
permissions:
packages: write
security-events: write
contents: read
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/image-publish-trivy.yaml@DBP-1179-spsh-image-tag-generation # todo: change to new version
with:
image_name: "dbildungs-iam-server"
run_trivy_scan: true
image_tag_generation: ${{ github.ref_name == 'main' && 'commit_hash' || 'specified' }}
image_tag: ${{ github.ref_name == 'main' && '' || needs.determine_image_tag_and_chart_version.outputs.image_tag }}
add_latest_tag: ${{ github.ref_name == 'main' }}
container_registry: "ghcr.io"
fail_on_vulnerabilites: false
report_location: "Dockerfile"
scan_helm:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/check-helm-kics.yaml@5
permissions:
contents: read
select_helm_version_generation_and_image_tag_generation:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
runs-on: ubuntu-latest
outputs:
SELECT_HELM_VERSION_GENERATION: ${{ steps.select_generation.outputs.SELECT_HELM_VERSION_GENERATION }}
SELECT_IMAGE_TAG_GENERATION: ${{ steps.select_generation.outputs.SELECT_IMAGE_TAG_GENERATION }}
steps:
- id: select_generation
shell: bash
run: |
if ${{ github.ref_name == 'main' }}; then
echo "SELECT_HELM_VERSION_GENERATION=timestamp" >> "$GITHUB_OUTPUT"
echo "SELECT_IMAGE_TAG_GENERATION=commit_hash" >> "$GITHUB_OUTPUT"
else
echo "SELECT_HELM_VERSION_GENERATION=specified" >> "$GITHUB_OUTPUT"
echo "SELECT_IMAGE_TAG_GENERATION=specified" >> "$GITHUB_OUTPUT"
fi
release_helm:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
needs:
- determine_image_tag_and_chart_version
- select_helm_version_generation_and_image_tag_generation
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/chart-release.yaml@7
secrets: inherit
with:
chart_name: dbildungs-iam-server
image_tag_generation: ${{ needs.select_helm_version_generation_and_image_tag_generation.outputs.SELECT_IMAGE_TAG_GENERATION }}
image_tag: ${{ github.ref_name == 'main' && '' || needs.determine_image_tag_and_chart_version.outputs.image_tag }}
helm_chart_version_generation: ${{ needs.select_helm_version_generation_and_image_tag_generation.outputs.SELECT_HELM_VERSION_GENERATION }}
helm_chart_version: ${{ github.ref_name == 'main' && '' || needs.determine_image_tag_and_chart_version.outputs.chart_version }}
wait_for_helm_chart_to_get_published:
needs:
- release_helm
runs-on: ubuntu-latest
steps:
- shell: bash
run: sleep 1m
branch_meta:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
uses: dBildungsplattform/spsh-app-deploy/.github/workflows/get-branch-meta.yml@3
create_branch_identifier:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
needs:
- branch_meta
uses: dBildungsplattform/spsh-app-deploy/.github/workflows/convert-branch-name.yml@6
with:
branch: ${{ needs.branch_meta.outputs.branch }}
deploy:
if: ${{ github.event_name == 'push' && !startsWith(github.ref_name,'dependabot/') }}
needs:
- branch_meta
- create_branch_identifier
- wait_for_helm_chart_to_get_published
- build_image_on_push
uses: dBildungsplattform/spsh-app-deploy/.github/workflows/deploy.yml@6
with:
dbildungs_iam_server_branch: ${{ needs.branch_meta.outputs.ticket }}
schulportal_client_branch: ${{ needs.branch_meta.outputs.ticket }}
dbildungs_iam_keycloak_branch: ${{ needs.branch_meta.outputs.ticket }}
dbildungs_iam_ldap_branch: ${{ needs.branch_meta.outputs.ticket }}
namespace: ${{ needs.create_branch_identifier.outputs.namespace_from_branch }}
database_recreation: ${{ github.ref_name == 'main' && 'true' || 'false' }}
# database_recreation: "true" # to force database recreation this has be set to true
secrets: inherit
# On Delete
create_branch_identifier_for_deletion:
if: ${{ github.event_name == 'delete' && github.event.ref_type == 'branch' }}
uses: dBildungsplattform/spsh-app-deploy/.github/workflows/convert-branch-name.yml@6
with:
branch: ${{ github.event.ref }}
delete_namespace:
if: ${{ github.event_name == 'delete' && github.event.ref_type == 'branch'}}
needs:
- create_branch_identifier_for_deletion
uses: dBildungsplattform/spsh-app-deploy/.github/workflows/delete-namespace.yml@5
with:
namespace: ${{ needs.create_branch_identifier_for_deletion.outputs.namespace_from_branch }}
secrets:
SPSH_DEV_KUBECONFIG: ${{ secrets.SPSH_DEV_KUBECONFIG }}
delete_successful:
if: ${{ github.event_name == 'delete' && github.event.ref_type == 'branch' }}
needs:
- delete_namespace
- create_branch_identifier_for_deletion
runs-on: ubuntu-latest
steps:
- run: echo "Deletion workflow of namespace" ${{ needs.create_branch_identifier_for_deletion.outputs.namespace_from_branch }} "done"
# Scheduled
scheduled_trivy_scan:
name: "Scheduled trivy scan of latest image"
if: ${{ github.event_name == 'schedule' }}
permissions:
packages: read
security-events: write
uses: dBildungsplattform/dbp-github-workflows/.github/workflows/check-trivy.yaml@7
with:
image_ref: 'ghcr.io/${{ github.repository_owner }}/dbildungs-iam-server:latest'
fail_on_vulnerabilites: false
report_location: "Dockerfile"