-
Notifications
You must be signed in to change notification settings - Fork 88
227 lines (188 loc) · 6.97 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
name: Release
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
branches: [master]
paths-ignore:
- '**/*.md'
jobs:
build-maintenance-image:
name: Build maintenance container image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
file: Dockerfile.maintenance
tags: ghcr.io/podkrepi-bg/frontend/maintenance:master
- name: Scan with Mondoo
uses: mondoohq/actions/docker-image@main
env:
MONDOO_CONFIG_BASE64: ${{ secrets.MONDOO_SECRET }}
with:
image: ghcr.io/podkrepi-bg/frontend/maintenance:master
build-frontend-image:
name: Build frontend container image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v2
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@v3
env:
NODE_ENV: production
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
GHOST_API_URL: https://blog.podkrepi.bg
GHOST_CONTENT_KEY: ${{ secrets.GHOST_CONTENT_KEY }}
with:
push: true
target: runner
build-args: |
SENTRY_AUTH_TOKEN=${{ env.SENTRY_AUTH_TOKEN }}
GHOST_API_URL=${{ env.GHOST_API_URL }}
GHOST_CONTENT_KEY=${{ env.GHOST_CONTENT_KEY }}
VERSION=${{ env.VERSION }}
tags: ghcr.io/podkrepi-bg/frontend:${{ 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/frontend:${{ env.VERSION }}
scan-manifests:
name: Scan k8s manifests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install kustomize
uses: imranismail/setup-kustomize@v1
- 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
run-playwright:
name: Run Playwright
uses: ./.github/workflows/playwright.yml
secrets: inherit
release-dev:
name: Release to dev
runs-on: ubuntu-latest
needs: [build-frontend-image, build-maintenance-image, scan-manifests, run-playwright]
environment:
name: dev
url: https://dev.podkrepi.bg
steps:
- uses: actions/checkout@v3
- 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/frontend=ghcr.io/podkrepi-bg/frontend:$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/frontend --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
steps:
- uses: actions/checkout@v3
- 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/frontend=ghcr.io/podkrepi-bg/frontend:$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/frontend --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/
description: Version ${{ env.VERSION }} of the website is deployed. The list of changes can be found at https://github.com/podkrepi-bg/frontend/releases/tag/${{ env.VERSION }}
color: 0x26A641
- name: Delete kubeconfig
if: always()
run: rm config.yaml