This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (82 loc) · 2.96 KB
/
build-and-deploy.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
# This workflow trigger on push to any branch
name: CI / CD
on:
push:
paths-ignore:
- '**.md'
- '.gitignore'
- 'LICENCE'
- 'CODEOWNERS'
env:
IMAGE: ghcr.io/${{ github.repository }}/pleiepenger-i-livets-sluttfase:${{ github.sha }}
jobs:
test:
name: Test Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: Test code
run: |
npm ci
npm run test
build-code-and-push-docker:
name: Build code and push docker image
if: startsWith(github.ref, 'refs/heads/dev-') || startsWith(github.ref, 'refs/heads/master') || github.event.deployment.payload.triggered # Build and push docker if branch is either master or dev-*
needs: test
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18
- name: build code
run: |
npm ci
npm run build
- name: Build Docker image
run: |
docker build --tag ${IMAGE} .
- name: Login to Github Package Registry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker login ghcr.io -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN}
docker push ${IMAGE}
deploy-dev-gcp:
name: Deploy to dev-gcp
if: startsWith(github.ref, 'refs/heads/dev-') || startsWith(github.ref, 'refs/heads/master') # Build and push docker if branch is either master or dev-*
needs: build-code-and-push-docker # Depends on build-code-and-push-docker job
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-gcp
RESOURCE: nais/naiserator.yml
VARS: nais/dev-gcp.json
deploy-prod-gcp:
name: deploy-prod-gcp
if: startsWith(github.ref, 'refs/heads/master')
needs: build-code-and-push-docker # Depends on build-code-and-push-docker job
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-gcp
RESOURCE: nais/naiserator.yml
VARS: nais/prod-gcp.json