-
Notifications
You must be signed in to change notification settings - Fork 6
285 lines (254 loc) · 10.2 KB
/
build.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
name: Build
on: [ push ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 21
cache: maven
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: v18
cache: 'npm'
cache-dependency-path: |
shopping-ui/package-lock.json
- name: "[main] Set up Snyk CLI"
if: github.ref == 'refs/heads/main'
uses: snyk/actions/setup@master
- name: "[main] Synk monitor: maven"
if: github.ref == 'refs/heads/main'
run: snyk monitor --all-projects --prune-repeated-subdependencies --target-reference=${{ github.ref_name }} -- -s .github/workflows/maven-settings.xml
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
PAT_USERNAME: ${{ secrets.PAT_USERNAME }}
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
- name: Build
run: mvn -s .github/workflows/maven-settings.xml verify -B -V -U
- name: Upload JARs
uses: actions/upload-artifact@v4
with:
name: demo-jars
path: |
bestseller-fashion/target/*.jar
bestseller-fashion/target/licenses/
bestseller-toys/target/*.jar
bestseller-toys/target/licenses/
checkout/target/*.jar
checkout/target/licenses/
gateway/target/*.jar
gateway/target/licenses/
hot-deals/target/*.jar
hot-deals/target/licenses/
inventory-service-mock/target/*.jar
inventory-service-mock/target/licenses/
order/target/*.jar
order/target/licenses/
if-no-files-found: error
retention-days: 3
docker-image:
name: Docker Image steadybit/${{ matrix.image.name || matrix.image.folder }}
timeout-minutes: 20
runs-on: ubuntu-latest
needs: [ build ]
permissions:
contents: read
packages: write
strategy:
matrix:
image:
- {folder: bestseller-fashion}
- {folder: bestseller-toys}
- {folder: bestseller-toys-go}
- {folder: checkout}
- {folder: gateway}
- {folder: hot-deals}
- {folder: inventory-service-mock, name: inventory}
- {folder: inventory-service-mock-go, name: inventory-go}
- {folder: order, name: orders}
steps:
- uses: actions/checkout@v4
- name: Download JARs
uses: actions/download-artifact@v4
with:
name: demo-jars
path: .
- name: Log in to the Docker container registry
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=steadybit/${{ matrix.image.name || matrix.image.folder }}
flavor: |
latest=auto
prefix=
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha,format=long,prefix=
- name: Build Docker image
uses: docker/build-push-action@v6
id: image
with:
context: ${{ matrix.image.folder }}
file: ${{ matrix.image.folder }}/Dockerfile
push: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' }}
load: ${{ github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64${{ (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main') && ',linux/arm64' || '' }} #for branches we just do a load, and this supports no multi-arch
- name: "[main] Snyk monitor docker image"
if: ${{ github.ref == 'refs/heads/main' }}
uses: snyk/actions/docker@master
with:
image: "steadybit/${{ matrix.image.name || matrix.image.folder }}:${{ github.ref_name }}"
args: --file=${{ matrix.image.folder }}/Dockerfile --target-reference=${{ github.ref_name }} --username=${{ secrets.DOCKER_USERNAME }} --password=${{ secrets.DOCKER_PASSWORD }}
command: monitor
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
trigger-deployment:
name: Trigger Deployment
needs: [docker-image]
runs-on: ubuntu-latest
concurrency: deploy-to-demo
steps:
- name: Dispatch event to trigger deployment to DEV
if: github.ref == 'refs/heads/develop'
run: |
curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/steadybit/demo-infrastructure/dispatches --data '{"event_type": "deploy-to-dev-demo"}'
# curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/steadybit/demo-infrastructure/dispatches --data '{"event_type": "deploy-to-sandbox-demo"}'
- name: Dispatch event to trigger deployment to PROD
if: github.ref == 'refs/heads/main'
run: |
curl -XPOST -u "${{ secrets.PAT_USERNAME}}:${{secrets.PAT_TOKEN}}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/steadybit/demo-infrastructure/dispatches --data '{"event_type": "deploy-to-prod-demo"}'
build-fashion-lambda:
name: "Build and Upload fashion-bestseller Lambda"
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: v20
cache: 'npm'
cache-dependency-path: |
bestseller-fashion-lambda/package-lock.json
- run: npm install
working-directory: bestseller-fashion-lambda
- name: "[main] setup snyk"
if: github.ref == 'refs/heads/main'
uses: snyk/actions/setup@master
- name: "[main] snyk monitor"
if: github.ref == 'refs/heads/main'
working-directory: bestseller-fashion-lambda
run: snyk monitor --prune-repeated-subdependencies --target-reference=${{ github.ref_name }}
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
- name: Install zip
uses: montudor/action-zip@v1
- name: Zip lambda
run: mkdir -p ../dist && zip -r --exclude="*test*" ../dist/fashion-bestseller.zip .
working-directory: bestseller-fashion-lambda
- uses: actions/upload-artifact@v4
with:
name: fashion-bestseller.zip
path: dist/fashion-bestseller.zip
if-no-files-found: error
retention-days: 3
- name: Configure AWS credentials (eu-central-1)
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: 'eu-central-1'
# Deploy to shared account
role-to-assume: 'arn:aws:iam::292929100161:role/allow-auto-deploy-from-other-accounts'
role-duration-seconds: 1200
role-session-name: S3DeployLicense
- name: Push zips to S3 (eu-central-1)
working-directory: dist
run: |
aws s3 cp fashion-bestseller.zip s3://steadybit-lambdas/fashion-bestseller.zip
VERSION_ID=$(aws s3api list-object-versions --bucket steadybit-lambdas --prefix fashion-bestseller.zip --query 'Versions[?IsLatest].[VersionId]' --output text)
echo "::notice:: eu-central-1 -> fashion_bestseller_lambda_version = \"$VERSION_ID\""
- name: Configure AWS credentials (eu-west-1)
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: 'eu-west-1'
# Deploy to shared account
role-to-assume: 'arn:aws:iam::292929100161:role/allow-auto-deploy-from-other-accounts'
role-duration-seconds: 1200
role-session-name: S3DeployLicense
- name: Push zips to S3 (eu-west-1)
working-directory: dist
run: |
aws s3 cp fashion-bestseller.zip s3://steadybit-lambdas-region-eu-west-1/fashion-bestseller.zip
VERSION_ID=$(aws s3api list-object-versions --bucket steadybit-lambdas-region-eu-west-1 --prefix fashion-bestseller.zip --query 'Versions[?IsLatest].[VersionId]' --output text)
echo "::notice:: eu-west-1 -> fashion_bestseller_lambda_version = \"$VERSION_ID\""
test-helm-charts:
name: "Test Helm Charts"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.12.2
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Add unit testing plugin
run: |
helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: Run unit tests
run: make charttesting
- name: Set up chart-testing
uses: helm/[email protected]
- name: Run chart-testing (lint)
run: make chartlint
release-helm-chart:
name: "Release Helm Chart"
runs-on: ubuntu-latest
needs: [ test-helm-charts ]
if: github.ref == 'refs/heads/main'
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Set up Helm
uses: azure/setup-helm@v4
with:
version: v3.12.2
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: charts
mark_as_latest: false
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"