-
Notifications
You must be signed in to change notification settings - Fork 2
412 lines (342 loc) · 13.2 KB
/
push.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
name: "Push"
on: [push]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build and cache Docker image
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: mariners-dashboard-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-image-
- name: "Login to Docker Hub"
uses: docker/[email protected]
continue-on-error: true
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
uses: docker/[email protected]
with:
context: .
target: dev
push: false
tags: gmri/neracoos-mariners-dashboard:latest
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/myimage.tar
build-prod:
name: Build production Docker image
runs-on: ubuntu-24.04
needs: build
timeout-minutes: 10
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: mariners-dashboard-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-image-
- name: Cache production Docker image
uses: actions/cache@v4
with:
path: /tmp/prodimage.tar
key: mariners-dashboard-prod-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-prod-image-
- name: Load Docker image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: Build Docker Image
uses: docker/[email protected]
with:
context: .
target: runner
push: false
tags: gmri/neracoos-mariners-dashboard:latest
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=/tmp/prodimage.tar
unit_tests:
name: Unit tests, typecheck and coverage
runs-on: ubuntu-24.04
needs: build
timeout-minutes: 10
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/myimage.tar
key: mariners-dashboard-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-image-
- name: Load Docker image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: Run unit tests and coverage
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
if: env.CODACY_PROJECT_TOKEN != null
run: docker compose -f docker-compose.dev.yaml run -e CI=true client npm run test-with-coverage
- name: Codacy Coverage Reporter
if: env.CODACY_PROJECT_TOKEN != null
uses: codacy/[email protected]
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: ./coverage/lcov.info
- name: Run unit test (and skip coverage if no project token secret)
env:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
if: env.CODACY_PROJECT_TOKEN == null
run: docker compose -f docker-compose.dev.yaml run -e CI=true client npm run test-ci
- name: npm run Build
run: docker compose -f docker-compose.dev.yaml run client npm run build
- name: Build Storybook Pages
run: docker compose -f docker-compose.dev.yaml run client npm run build-storybook
# - name: Cache Storybook Build
# uses: actions/cache@v4
# with:
# path: /tmp/storybook-public/
# key: mariners-dashboard-storybook-${{ github.sha }}
# - name: Copy Storybook Build to cache directory
# run: |
# rm -rf /tmp/storybook-public
# cp -r storybook-public /tmp/storybook-public
playwright:
name: Playwright integration tests
runs-on: ubuntu-24.04
needs: build-prod
timeout-minutes: 30
env:
# Playwright uses this env var for the browser install path. See:
# https://playwright.dev/docs/ci#directories-to-cache
# It makes most sense to default this to something cross-platform
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/ms-playwright
steps:
- name: "Checkout"
uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "22"
cache: npm
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/prodimage.tar
key: mariners-dashboard-prod-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-prod-image-
- name: Load Docker image
run: |
docker load --input /tmp/prodimage.tar
docker image ls -a
- name: Start container
run: docker compose up -d client
- run: npm install --frozen-lockfile
# Use Playwright version as part of the cache key
# AFAIK this is a x-platform way to get your installed Playwright version.
# Be sure to be diligent in specifying ^, ~, or locked versions.
- run: |
echo "PLAYWRIGHT_VERSION=$(node -e "process.stdout.write(require('@playwright/test/package.json').version)")" >> $GITHUB_OUTPUT
id: playwright-version
# Cache action
- uses: actions/cache@v4
id: playwright-cache
with:
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.PLAYWRIGHT_VERSION }}
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}
# This command should work and only be ran on cold cache
- run: npx playwright install
if: steps.playwright-cache.outputs.cache-hit != 'true'
- name: Wait for container to become available
run: npx wait-on http://localhost:3000
timeout-minutes: 1
- name: Run Playwright tests
run: npm run test:e2e
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
# pages:
# name: Deploy Storybook to Github Pages on version tag
# runs-on: ubuntu-24.04
# needs: [unit_tests, playwright]
# timeout-minutes: 10
# if: |
# github.repository == 'gulfofmaine/Neracoos-1-Buoy-App'
# && contains(github.ref, 'refs/tags/v')
# steps:
# - name: "Checkout"
# uses: actions/checkout@v4
# - name: Cache Storybook Build
# uses: actions/cache@v4
# with:
# path: /tmp/storybook-public/
# key: mariners-dashboard-storybook-${{ github.sha }}
# - name: Deploy Storybook to Github Pages 🚀
# uses: JamesIves/[email protected]
# with:
# branch: gh-pages
# folder: /tmp/storybook-public/
push_image:
name: Build and push tagged image to Docker Hub
runs-on: ubuntu-24.04
needs: [unit_tests, playwright]
timeout-minutes: 20
environment: Deploy with ArgoCD
if: |
github.repository == 'gulfofmaine/Neracoos-1-Buoy-App'
&& contains(github.ref, 'refs/tags/v')
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/prodimage.tar
key: mariners-dashboard-prod-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-prod-image-
- name: Load Docker image
run: |
docker load --input /tmp/prodimage.tar
docker image ls -a
- name: "Login to Docker Hub"
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get tag name
uses: olegtarasov/[email protected]
id: tagName
- name: Build and push Docker Image
uses: docker/[email protected]
with:
context: .
push: true
tags: gmri/neracoos-mariners-dashboard:${{ steps.tagName.outputs.tag }}
cache-from: type=local,src=/tmp/.buildx-cache
build-args: |
NEXT_PUBLIC_ERDDAP_SERVICE=https://buoybarn.neracoos.org
NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN_PROD }}
- name: Make GitOps directory
run: mkdir gitops
- name: Clone GitOps config repo
run: git clone "https://[email protected]/gulfofmaine/neracoos-aws-cd.git"
working-directory: ./gitops
env:
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
- name: Update GitOps config repo
working-directory: ./gitops/neracoos-aws-cd
run: |
sed -i 's/?ref=.\+/?ref=${{ steps.tagName.outputs.tag }}/' overlays/mariners/kustomization.yaml
sed -i 's/newTag: .\+/newTag: ${{ steps.tagName.outputs.tag }}/' overlays/mariners/kustomization.yaml
git config --global user.email '[email protected]'
git config --global user.name 'NERACOOS Mariners Dashboard CI'
git diff --exit-code && echo 'Already Deployed' || (git commit -am 'Upgrade Mariners Dashboard to ${{ steps.tagName.outputs.tag }}' && git push)
- name: Copy Next.JS sourcemaps
run: docker run -v $PWD:/opt/mount --rm --entrypoint cp gmri/neracoos-mariners-dashboard -r /app/.next /opt/mount/next-build
- name: Create Sentry Release
uses: getsentry/[email protected]
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
version: ${{ steps.tagName.outputs.tag }}
sourcemaps: ./next-build
push_dev_image:
name: Build and push dev image to Docker Hub
runs-on: ubuntu-24.04
needs: [unit_tests, playwright]
timeout-minutes: 20
environment: Deploy with ArgoCD
if: |
github.repository == 'gulfofmaine/Neracoos-1-Buoy-App'
&& github.ref == 'refs/heads/main'
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Cache Docker image
uses: actions/cache@v4
with:
path: /tmp/prodimage.tar
key: mariners-dashboard-prod-image-${{ github.sha }}
restore-keys: |
mariners-dashboard-prod-image-
- name: Load Docker image
run: |
docker load --input /tmp/prodimage.tar
docker image ls -a
- name: "Login to Docker Hub"
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get tag name
id: tagName
run: echo "tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build and push Docker Image
uses: docker/[email protected]
with:
context: .
push: true
tags: gmri/neracoos-mariners-dashboard:${{ steps.tagName.outputs.tag }}
cache-from: type=local,src=/tmp/.buildx-cache
build-args: |
NEXT_PUBLIC_ERDDAP_SERVICE=https://buoybarn.neracoos.org
NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN_DEV }}
- name: Make GitOps directory
run: mkdir gitops
- name: Clone GitOps config repo
run: git clone "https://[email protected]/gulfofmaine/neracoos-aws-cd.git"
working-directory: ./gitops
env:
GITOPS_TOKEN: ${{ secrets.GITOPS_TOKEN }}
- name: Update GitOps config repo
working-directory: ./gitops/neracoos-aws-cd
run: |
sed -i 's/?ref=.\+/?ref=${{ github.sha }}/' overlays/mariners-dev/kustomization.yaml
sed -i 's/newTag: .\+/newTag: "${{ steps.tagName.outputs.tag }}"/' overlays/mariners-dev/kustomization.yaml
git config --global user.email '[email protected]'
git config --global user.name 'NERACOOS Mariners Dashboard CI'
git diff --exit-code && echo 'Already Deployed' || (git commit -am 'Upgrade Mariners Dashboard dev deployment to ${{ steps.tagName.outputs.tag }}' && git push)
- name: Copy Next.JS sourcemaps
run: docker run -v $PWD:/opt/mount --rm --entrypoint cp gmri/neracoos-mariners-dashboard -r /app/.next /opt/mount/next-build
- name: Create Sentry Release
uses: getsentry/[email protected]
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: dev
version: ${{ steps.tagName.outputs.tag }}
sourcemaps: ./next-build