-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (201 loc) · 7.58 KB
/
deploy-manuelt.yaml
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
name: Deploy
on:
workflow_dispatch:
inputs:
environment:
description: 'Miljø (q1, q2 eller prod)'
required: true
default: 'q2'
permissions:
contents: write
packages: write
env:
IMAGE: docker.pkg.github.com/${{ github.repository }}/melosys-eessi:${{ github.sha }}
IMAGE_MANIFEST: https://docker.pkg.github.com/v2/${{ github.repository }}/melosys-eessi/manifests/${{ github.sha }}
jobs:
check_docker_image_exists:
name: Check if docker image exists in registry
runs-on: ubuntu-latest
steps:
- run: |
echo "DOCKER_IMAGE_EXISTS_HTTP_STATUS=$(curl -X GET -s -o /dev/null -w "%{http_code}" ${{ env.IMAGE_MANIFEST }} -u ${{ github.actor }}:${{ secrets.GITHUB_TOKEN }})" >> $GITHUB_ENV
- id: set_output
run: |
if [ ${{ env.DOCKER_IMAGE_EXISTS_HTTP_STATUS }} -eq 200 ]
then
echo "::set-output name=exists::true"
else
echo "::set-output name=exists::false"
fi
outputs:
exists: ${{ steps.set_output.outputs.exists }}
build:
runs-on: ubuntu-latest
needs: check_docker_image_exists
if: needs.check_docker_image_exists.outputs.exists != 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Maven
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Test and build
run: mvn clean package -B -e -U -DskipTests
- name: Build docker image
run: |
docker build -t ${IMAGE} .
- name: Login to Github Package Registry
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker login docker.pkg.github.com -u ${GITHUB_REPOSITORY} -p ${GITHUB_TOKEN}
- name: Push Docker image
run: |
docker push ${IMAGE}
# Deploy til dev (Q2) manuelt
deploy_dev:
name: Deploy til Q2
needs: build
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && (github.event.inputs.environment == 'dev' || github.event.inputs.environment == 'q2')
runs-on: ubuntu-latest
environment: dev-fss-q2:teammelosys
steps:
- name: Checkout
uses: actions/checkout@v4
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}}
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: nais/unleash-apitoken.yml
VARS: nais/vars-q2.json
- name: Deploy
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: nais/nais.yml
VARS: nais/vars-q2.json
- run: |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV
- name: Slack Notification (deploy success)
if: success()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: good
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til dev :rocket:'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}
- name: Slack Notification (deploy failure)
if: failure()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: danger
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til dev!'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}
# Deploy til Q1 manuelt
deploy_q1:
name: Deploy til Q1
needs: build
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && github.event.inputs.environment == 'q1'
runs-on: ubuntu-latest
environment: dev-fss-q1:teammelosys
steps:
- name: Checkout
uses: actions/checkout@v4
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}}
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: nais/unleash-apitoken.yml
VARS: nais/vars-q1.json
- name: Deploy
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: dev-fss
RESOURCE: nais/nais.yml
VARS: nais/vars-q1.json
- run: |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV
- name: Slack Notification (deploy success)
if: success()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: good
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til q1 :rocket:'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}
- name: Slack Notification (deploy failure)
if: failure()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: danger
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til q1!'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}
# Deploy til prod manuelt
deploy_prod:
name: Deploy til prod
needs: build
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && github.event.inputs.environment == 'prod'
runs-on: ubuntu-latest
environment: prod-fss:teammelosys
steps:
- name: Checkout
uses: actions/checkout@v4
- name: deploy new Unleash Apikey to ${{github.event.inputs.environment}}
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-fss
RESOURCE: nais/unleash-apitoken.yml
VARS: nais/vars-prod.json
- name: Deploy
uses: nais/deploy/actions/deploy@v1
env:
APIKEY: ${{ secrets.NAIS_DEPLOY_APIKEY }}
CLUSTER: prod-fss
RESOURCE: nais/nais.yml
VARS: nais/vars-prod.json
- run: |
echo "COMMIT_MSG=$(git log --format=%s -n 1)" >> $GITHUB_ENV
- name: Slack Notification (deploy success)
if: success()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: good
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':clap: melosys-eessi ble manuelt deployet til prod :rocket:'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}
- name: Slack Notification (deploy failure)
if: failure()
uses: rtCamp/[email protected]
env:
SLACK_COLOR: danger
SLACK_USERNAME: Github Actions
SLACK_ICON: https://github.com/github.png?size=48
SLACK_TITLE: ':crying_cat_face: melosys-eessi kunne ikke manuelt deployes til prod!'
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_MESSAGE: ${{ env.COMMIT_MSG }}