forked from podkrepi-bg/api
-
Notifications
You must be signed in to change notification settings - Fork 0
262 lines (217 loc) · 8.17 KB
/
release.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
name: Release
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
branches: [master]
paths-ignore:
- '**.md'
jobs:
build-api-docker-image:
name: Build API docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get sha
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=master-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
env:
NODE_ENV: production
with:
push: true
target: production
build-args: |
APP_VERSION=${{ env.VERSION }}
tags: |
ghcr.io/podkrepi-bg/api:master
ghcr.io/podkrepi-bg/api:${{ env.VERSION }}
- name: Scan with Mondoo
uses: mondoohq/actions/docker-image@main
env:
MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SECRET }}
with:
image: ghcr.io/podkrepi-bg/api:${{ env.VERSION }}
build-migrations-docker-image:
name: Build migrations docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get sha
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=master-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
env:
NODE_ENV: production
with:
push: true
file: Dockerfile.migrations
target: base
build-args: |
APP_VERSION=${{ env.VERSION }}
tags: |
ghcr.io/podkrepi-bg/api/migrations:master
ghcr.io/podkrepi-bg/api/migrations:${{ env.VERSION }}
- name: Scan with Mondoo
uses: mondoohq/actions/docker-image@main
env:
MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SECRET }}
with:
image: ghcr.io/podkrepi-bg/api/migrations:${{ env.VERSION }}
build-seed-docker-image:
name: Build seed docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get sha
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=master-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v5
env:
NODE_ENV: production
with:
push: true
file: Dockerfile.migrations
target: seed
tags: |
ghcr.io/podkrepi-bg/api/seed:master
ghcr.io/podkrepi-bg/api/seed:${{ env.VERSION }}
scan-manifests:
name: Scan k8s manifests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
- name: Build development manifests
run: kustomize build manifests/overlays/development > dev-manifests.yaml
- name: Scan development manifests with Mondoo
uses: mondoohq/actions/k8s-manifest@main
env:
MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SECRET }}
with:
path: dev-manifests.yaml
- name: Build production manifests
run: kustomize build manifests/overlays/production > prod-manifests.yaml
- name: Scan production manifests with Mondoo
uses: mondoohq/actions/k8s-manifest@main
env:
MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SECRET }}
with:
path: prod-manifests.yaml
release-dev:
name: Release to dev
runs-on: ubuntu-latest
needs: [build-api-docker-image, build-migrations-docker-image, scan-manifests]
environment:
name: dev
url: https://dev.podkrepi.bg/swagger
steps:
- uses: actions/checkout@v4
- name: Install kubectl
uses: azure/setup-kubectl@v3
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
- name: Get tag
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Get sha
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "VERSION=master-$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Set container versions in manifests
working-directory: manifests/overlays/development
run: |
kustomize edit set image ghcr.io/podkrepi-bg/api=ghcr.io/podkrepi-bg/api:$VERSION
kustomize edit set image ghcr.io/podkrepi-bg/api/migrations=ghcr.io/podkrepi-bg/api/migrations:$VERSION
kustomize edit set annotation app.komodor.com/app.ref:$GITHUB_SHA
- name: Set kubeconfig
run: echo ${{ secrets.K8S_DEV_CONFIG }} | base64 -d > config.yaml
- name: Apply new manifests
run: kubectl apply -k manifests/overlays/development --kubeconfig config.yaml
- name: Wait until deployment is ready
run: kubectl wait --for=condition=Available=True deployment/api-headless --timeout=180s -n podkrepibg-dev --kubeconfig config.yaml
- name: Delete kubeconfig
if: always()
run: rm config.yaml
release-gh:
name: Github release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
needs: [release-dev]
permissions:
contents: write
steps:
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
release-prod:
name: Release to prod
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
needs: [release-gh]
environment:
name: prod
url: https://podkrepi.bg/swagger
steps:
- uses: actions/checkout@v4
- name: Install kubectl
uses: azure/setup-kubectl@v3
- name: Install kustomize
uses: imranismail/setup-kustomize@v2
- name: Get tag
run: echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Set container versions in manifests
working-directory: manifests/overlays/production
run: |
kustomize edit set image ghcr.io/podkrepi-bg/api=ghcr.io/podkrepi-bg/api:$VERSION
kustomize edit set image ghcr.io/podkrepi-bg/api/migrations=ghcr.io/podkrepi-bg/api/migrations:$VERSION
kustomize edit set annotation app.komodor.com/app.ref:$GITHUB_SHA
- name: Set kubeconfig
run: echo ${{ secrets.K8S_CONFIG }} | base64 -d > config.yaml
- name: Apply new manifests
run: kubectl apply -k manifests/overlays/production --kubeconfig config.yaml
- name: Wait until deployment is ready
run: kubectl wait --for=condition=Available=True deployment/api-headless --timeout=180s -n podkrepibg --kubeconfig config.yaml
- uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: 'deploy'
url: https://podkrepi.bg/swagger
description: Version ${{ env.VERSION }} of the API is deployed. The list of changes can be found at https://github.com/podkrepi-bg/api/releases/tag/${{ env.VERSION }}
color: 0x26A641
- name: Delete kubeconfig
if: always()
run: rm config.yaml