-
Notifications
You must be signed in to change notification settings - Fork 2
242 lines (222 loc) · 8.32 KB
/
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
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
name: Deploy to cluster
on:
push:
branches:
- main
- develop
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build images
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.meta.outputs.image_tag }}
release_version: ${{ steps.meta.outputs.release_version }}
steps:
-
name: Checkout
uses: actions/checkout@v3
- name: Prepare references and release
id: meta
run: |
echo "image_tag=sha-`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_OUTPUT
echo "release_version=${GITHUB_SHA}" >> $GITHUB_OUTPUT
- name: Invalidate wiki content
run: |
date > wiki/.ts
- name: Prepare Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
finalize: false
version: ${{ secrets.SENTRY_PROJECT }}@${{ steps.meta.outputs.release_version }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: nologin
password: ${{ secrets.SCW_SECRET_KEY }}
registry: ${{ secrets.SCW_REGISTRY_ENDPOINT }}
- name: Prepare web image metadata
id: webMeta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ secrets.SCW_REGISTRY_ENDPOINT }}/web
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Build and push web
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
target: web-stable
# TODO: ends with 400
# cache-from: type=registry,ref=${{ secrets.SCW_REGISTRY_ENDPOINT }}/web:buildcache
# cache-to: type=registry,ref=${{ secrets.SCW_REGISTRY_ENDPOINT }}/web:buildcache,mode=max
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.webMeta.outputs.tags }}
labels: ${{ steps.webMeta.outputs.labels }}
build-args: |
SENTRY_RELEASE_ENVIRONMENT=production
SENTRY_RELEASE_NAME=${{ secrets.SENTRY_PROJECT }}@${{ steps.meta.outputs.release_version }}
DJANGO_RELEASE_NAME=${{ secrets.SENTRY_PROJECT }}@${{ steps.meta.outputs.release_version }}
secrets: |
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }}
SENTRY_WEBPACK_AUTH_TOKEN=${{ secrets.SENTRY_WEBPACK_AUTH_TOKEN }}
- name: Prepare image metadata
id: proxyMeta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ secrets.SCW_REGISTRY_ENDPOINT }}/proxy
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=ref,event=tag
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Build and push proxy
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
target: proxy-stable
# TODO: ends with 400
# cache-from: type=registry,ref=${{ secrets.SCW_REGISTRY_ENDPOINT }}/web:buildcache
# cache-to: type=registry,ref=${{ secrets.SCW_REGISTRY_ENDPOINT }}/web:buildcache,mode=max
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.proxyMeta.outputs.tags }}
labels: ${{ steps.proxyMeta.outputs.labels }}
build-args: |
SENTRY_RELEASE_ENVIRONMENT=production
SENTRY_RELEASE_NAME=${{ secrets.SENTRY_PROJECT }}@${{ steps.meta.outputs.release_version }}
secrets: |
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.SENTRY_PROJECT }}
SENTRY_WEBPACK_AUTH_TOKEN=${{ secrets.SENTRY_WEBPACK_AUTH_TOKEN }}
deploy:
name: Deploy to cluster
runs-on: ubuntu-latest
concurrency: deploy
environment:
name: production
url: https://fiesta.plus
needs:
- build
steps:
- uses: actions/checkout@v1
- name: Setup k8s context
run: |
echo "${{ secrets.KUBECONFIG }}" > kubeconfig.yaml
- name: Deploy
uses: 'vimeda/[email protected]'
with:
release: 'fiesta'
namespace: 'fiesta'
chart: 'charts'
token: '${{ github.token }}'
timeout: 120s
values: >-
web:
repository: ${{ secrets.SCW_REGISTRY_ENDPOINT }}/web
tag: ${{ needs.build.outputs.image_tag }}
proxy:
repository: ${{ secrets.SCW_REGISTRY_ENDPOINT }}/proxy
tag: ${{ needs.build.outputs.image_tag }}
ingress:
certContactEmail: ${{ secrets.CERT_CONTACT_EMAIL }}
secrets:
databaseUrl: ${{ secrets.DATABASE_URL }}
s3:
keyId: ${{ secrets.S3_KEY_ID }}
accessKey: ${{ secrets.S3_ACCESS_KEY }}
regionName: ${{ secrets.S3_REGION_NAME }}
bucketName: ${{ secrets.S3_BUCKET_NAME }}
dnsWebhook:
accessKey: ${{ secrets.SCW_DNS_ACCESS_KEY }}
secretKey: ${{ secrets.SCW_DNS_SECRET_KEY }}
sentry:
dsn: ${{ secrets.SENTRY_DSN }}
jsLoaderUrl: ${{ secrets.SENTRY_JS_LOADER_URL }}
mailer:
primary:
host: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST }}
port: "${{ secrets.DJANGO_MAILER_PRIMARY_HOST_PORT }}"
user: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST_USER }}
password: ${{ secrets.DJANGO_MAILER_PRIMARY_HOST_PASSWORD }}
value-files: >-
[
"charts/values.yaml"
]
env:
KUBECONFIG_FILE: '${{ secrets.KUBECONFIG }}'
announce-on-telegram:
name: Announce Deploy on Telegram
runs-on: ubuntu-latest
needs:
- deploy
steps:
- name: Announce deploy to Telegram
run: |
message="
👨💻 ${{ github.actor }} deployed:
🌐 [production](https://fiesta.plus)
📝 \`${{ github.event.commits[0].message }}\`
🔗 [see commit](https://github.com/${{ github.repository }}/commit/${{github.sha}})
"
curl -s \
-X POST \
'https://api.telegram.org/bot${{ secrets.ANNOUNCE_TELEGRAM_TOKEN }}/sendMessage' \
--data-urlencode "chat_id=${{ secrets.ANNOUNCE_TELEGRAM_CHAT }}" \
--data-urlencode "text=${message}" \
--data-urlencode "reply_to_message_id=${{ secrets.ANNOUNCE_TELEGRAM_TOPIC }}" \
--data-urlencode "disable_notification=true" \
--data-urlencode "silent=true" \
--data-urlencode "no_webpage=true" \
--data-urlencode "disable_web_page_preview=true" \
--data-urlencode "parse_mode=MarkdownV2"
finalize-sentry-release:
name: Finalize Sentry deploy
runs-on: ubuntu-latest
needs: [build, deploy]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Finalize Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
finalize: true
version: ${{ secrets.SENTRY_PROJECT }}@${{ needs.build.outputs.release_version }}