-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (174 loc) · 5.83 KB
/
deploy-docker-image.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
name: Deploy Docker image
on:
push:
paths-ignore:
- '**.md'
- '.gitignore'
- 'CODEOWNERS'
branches:
- master
env:
TAG_LATEST_PROD: latest_prod
jobs:
build-docker-image:
name: Build Docker image
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
outputs:
tag: ${{ steps.docker-push.outputs.tag }}
image: ${{ steps.docker-push.outputs.image }}
steps:
- name: Hente kode
uses: actions/checkout@v4
- name: Setup + Install
uses: ./.github/actions/setup-install
with:
npmAuthToken: ${{ secrets.READER_TOKEN }}
- name: Set timestamp
run: echo "TIMESTAMP=$(expr $(date +%Y%m%d%H%M%S))" >> $GITHUB_ENV
- name: Bygge dist
run: yarn build
- name: Opprett release med Sentry
run: yarn sentry-release
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- uses: nais/docker-build-push@v0
id: docker-push
with:
tag: 'latest'
team: k9saksbehandling
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
identity_provider: ${{ secrets.NAIS_WORKLOAD_IDENTITY_PROVIDER }}
- name: Sett image for nais deploy
run: |
echo "IMAGE=${{steps.docker-push.outputs.image}}" >> $GITHUB_OUTPUT
echo "TAG=${{steps.docker-push.outputs.tag}}" >> $GITHUB_OUTPUT
- name: Git diff url
shell: bash
run: |
dynamic_url="https://github.com/${{ github.repository }}/compare/${{ env.TAG_LATEST_PROD }}...${{ github.sha }}"
echo "Forskjell mellom denne build og prod: <${dynamic_url}>" >> $GITHUB_STEP_SUMMARY
verdikjede-tester:
name: Verdikjedetester
secrets: inherit
permissions:
id-token: write
contents: read
packages: read
uses: navikt/sif-gha-workflows/.github/workflows/verdikjede-test-v2.yml@main
needs: build-docker-image
with:
tag: ${{ needs.build-docker-image.outputs.tag }}
suites: "frontend"
image_version: ${{ needs.build-docker-image.outputs.tag }}
trivy:
needs: [build-docker-image]
uses: navikt/sif-gha-workflows/.github/workflows/trivy.yml@main
permissions:
contents: write
id-token: write
security-events: write
actions: read
secrets: inherit
with:
image: ${{ needs.build-docker-image.outputs.image }}
team: k9saksbehandling
deploy-dev:
name: Deploy to dev
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
CLUSTER: dev-fss
environment: dev-fss:k9saksbehandling
needs: [build-docker-image]
steps:
- uses: actions/checkout@v4
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ env.CLUSTER }}
RESOURCE: deploy/${{ env.CLUSTER }}-k9saksbehandling.yml
VARS: deploy/dev.yaml
VAR: image=${{ needs.build-docker-image.outputs.image }}
deploy-prod:
name: Deploy to prod
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
env:
CLUSTER: prod-fss
environment: prod-fss:k9saksbehandling
if: github.ref_name == 'master'
needs: [build-docker-image, deploy-dev, verdikjede-tester]
steps:
- uses: actions/checkout@v4
with:
# Ta med litt historie og tags for å finne latest_prod commit hash
fetch-tags: true
fetch-depth: 100
- name: tag deployment image tag
uses: actions/github-script@v7
env:
TAG: prod_${{ needs.build-docker-image.outputs.tag }}
with:
script: |
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.TAG }}',
sha: context.sha
})
} catch (err) {
if(err.status === 422) { // tag already exists
console.info('Tag for deployment ${{ env.TAG }} already existed. Will leave it as is');
} else {
throw err;
}
}
- name: Print static git diff url
shell: bash
run: |
# disable exit on error temporarily in case latest_prod tag does not exist
set +e
latest_prod_sha="$(git rev-list -n 1 tags/${{ env.TAG_LATEST_PROD }})"
# re-enable exit on error
set -e
if [ -n "${latest_prod_sha}" ]; then
static_url="https://github.com/${{ github.repository }}/compare/${latest_prod_sha}...${{ github.sha }}"
echo "Endringer prodsatt i denne utrulling : <${static_url}>" >> $GITHUB_STEP_SUMMARY
fi
- uses: nais/deploy/actions/deploy@v2
env:
CLUSTER: ${{ env.CLUSTER }}
RESOURCE: deploy/${{ env.CLUSTER }}-k9saksbehandling.yml
VAR: image=${{ needs.build-docker-image.outputs.image }}
- name: tag deployment done
uses: actions/github-script@v7
with:
script: |
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/${{ env.TAG_LATEST_PROD }}',
sha: context.sha,
force: true
})
} catch (err) {
if(err.status === 422) { // tag did not exist, try creating it
console.info('Tag for ${{ env.TAG_LATEST_PROD }} did not exist. Will try creating it');
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ env.TAG_LATEST_PROD }}',
sha: context.sha
})
} else {
throw err;
}
}