-
Notifications
You must be signed in to change notification settings - Fork 2
314 lines (270 loc) · 11.6 KB
/
main.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: "Production deployment"
on:
push:
branches:
- "main"
env:
NAMESPACE: eci-prod
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
service: ["worker", "bullboard", "api"]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/${{matrix.service}}
steps:
- name: Checkout
uses: actions/checkout@v4
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Build image
id: docker-build-push
uses: docker/build-push-action@v5
with:
context: .
push: true
file: ./services/${{matrix.service}}/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: commit_sha=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
# after the build job, we have one job, that is tagging all the images with the current version and pushing them to the registry
# we are using semantic-release to determine the current version. We use the docker sha from github as the image name
release:
runs-on: ubuntu-latest
needs: build
env:
REGISTRY: ghcr.io
IMAGE_BASE: ${{ github.repository }}
steps:
- name: Checkout
uses: actions/checkout@v4
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup pnpm
uses: pnpm/action-setup@v3
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'
# Release the new version to GitHub.
# Set the current version as an output variable
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pnpm i @semantic-release/git semantic-release
pnpm semantic-release
echo "CURRENT_VERSION=$(pnpm --silent semantic-release --version)" >> $GITHUB_ENV
# get the current sha that github uses as tag. It looks always like this: ghcr.io/trieb-work/schemabase/logdrain:sha-ba89316. The sha is always the first parts of the current commit sha
- name: Export docker tag sha
run: |
echo "DOCKER_TAG_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
# use the image sha from docker-build-push step as the image name. Tag it with the current version from set_tag. Push it afterwards
- name: Tag and push image
run: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/worker:sha-${{ env.DOCKER_TAG_SHA }}
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/worker:sha-${{ env.DOCKER_TAG_SHA }} ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/worker:${{ env.CURRENT_VERSION }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/worker:${{ env.CURRENT_VERSION }}
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/bullboard:sha-${{ env.DOCKER_TAG_SHA }}
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/bullboard:sha-${{ env.DOCKER_TAG_SHA }} ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/bullboard:${{ env.CURRENT_VERSION }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/bullboard:${{ env.CURRENT_VERSION }}
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/api:sha-${{ env.DOCKER_TAG_SHA }}
docker tag ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/api:sha-${{ env.DOCKER_TAG_SHA }} ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/api:${{ env.CURRENT_VERSION }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_BASE }}/api:${{ env.CURRENT_VERSION }}
# deploy-worker:
# name: Deploy Worker
# needs: build
# runs-on: ubuntu-latest
# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}/worker
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - uses: azure/setup-kubectl@v3
# with:
# version: v1.25.2
# - uses: azure/setup-helm@v3
# with:
# version: 'v3.10.0'
# - name: Set Kubernetes Context
# uses: azure/k8s-set-context@v3
# with:
# method: kubeconfig
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - name: Create the image-pull-secret in Kubernetes
# run: |
# kubectl create secret docker-registry regcred \
# --save-config --dry-run=client \
# --from-file=.dockerconfigjson=$HOME/.docker/config.json\
# -o yaml |
# kubectl apply -f -
# - name: Run helm deploy
# run: >
# helm upgrade eci-worker-v2 ./services/worker/helm-chart
# --debug
# --install
# --create-namespace
# --namespace=eci-prod
# --set=imagePullSecret="regcred"
# --set=image.imageName="${{ env.REGISTRY }}/${{ github.repository }}/worker:sha-$(git rev-parse --short HEAD)"
# --set=eciEnv="production"
# --set=databaseUrl="${{ secrets.DATABASE_URL }}"
# --set=signingKey="${{ secrets.SIGNING_KEY }}"
# --set=redis.host="${{ secrets.REDIS_HOST }}"
# --set=redis.port="${{ secrets.REDIS_PORT }}"
# --set=redis.password="${{ secrets.REDIS_PASSWORD }}"
# --set=elasticsearch.host="${{ secrets.ELASTIC_LOGGING_SERVER }}"
# --set=elasticsearch.username="${{ secrets.ELASTIC_LOGGING_USERNAME }}"
# --set=elasticsearch.password="${{ secrets.ELASTIC_LOGGING_PASSWORD }}"
# --set=kafka.brokerUrl="${{ secrets.PROD_KAFKA_BROKER_URL }}"
# --set=kafka.saslMechanism="scram-sha-256"
# --set=kafka.username="${{ secrets.PROD_KAFKA_USERNAME }}"
# --set=kafka.password="${{ secrets.PROD_KAFKA_PASSWORD }}"
# --set=sendgridApiKey=${{ secrets.SENDGRID_API_KEY }}
# --set=secretKey=${{ secrets.SECRET_KEY_PROD }}
# deploy-logdrain:
# name: Deploy Logdrain
# needs: build
# runs-on: ubuntu-latest
# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}/logdrain
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - uses: azure/setup-kubectl@v3
# with:
# version: v1.25.2
# - uses: azure/setup-helm@v3
# with:
# version: 'v3.10.0'
# - name: Set Kubernetes Context
# uses: azure/k8s-set-context@v3
# with:
# method: kubeconfig
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - run: cat ~/.docker/config.json
# # - name: Create the image-pull-secret in Kubernetes
# # run: |
# # kubectl create secret docker-registry regcred \
# # --save-config --dry-run=client \
# # --from-file=.dockerconfigjson=$HOME/.docker/config.json\
# # -o yaml |
# # kubectl apply -f -
# - name: Run helm deploy
# run: >
# helm upgrade eci-logdrain ./services/logdrain/helm-chart
# --install
# --create-namespace
# --namespace=eci-prod
# --set=imagePullSecret="regcred"
# --set=image.imageName="${{ env.REGISTRY }}/${{ github.repository }}/logdrain:sha-$(git rev-parse --short HEAD)"
# --set=eciEnv="production"
# --set=databaseUrl="${{ secrets.DATABASE_URL }}"
# --set=redis.host="${{ secrets.REDIS_HOST }}"
# --set=redis.port="${{ secrets.REDIS_PORT }}"
# --set=redis.password="${{ secrets.REDIS_PASSWORD }}"
# --set=elasticsearch.host="${{ secrets.ELASTIC_LOGGING_SERVER }}"
# --set=elasticsearch.username="${{ secrets.ELASTIC_LOGGING_USERNAME }}"
# --set=elasticsearch.password="${{ secrets.ELASTIC_LOGGING_PASSWORD }}"
# --set=logdrain.client.id="${{ secrets.LOGDRAIN_CLIENT_ID }}"
# --set=logdrain.client.secret="${{ secrets.LOGDRAIN_CLIENT_SECRET }}"
# --set=logdrain.redirectUri="${{ secrets.LOGDRAIN_REDIRECT_URI }}"
# --set=ingress.host="${{ secrets.LOGDRAIN_HOST }}"
# deploy-bullboard:
# name: Deploy bullboard
# needs: build
# runs-on: ubuntu-latest
# env:
# REGISTRY: ghcr.io
# IMAGE_NAME: ${{ github.repository }}/bullboard
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# - uses: azure/setup-kubectl@v3
# with:
# version: v1.25.2
# - uses: azure/setup-helm@v3
# with:
# version: 'v3.10.0'
# - name: Set Kubernetes Context
# uses: azure/k8s-set-context@v3
# with:
# method: kubeconfig
# kubeconfig: ${{ secrets.KUBE_CONFIG }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# - run: cat ~/.docker/config.json
# # - name: Create the image-pull-secret in Kubernetes
# # run: |
# # kubectl create secret docker-registry regcred \
# # --save-config --dry-run=client \
# # --from-file=.dockerconfigjson=$HOME/.docker/config.json\
# # -o yaml |
# # kubectl apply -f -
# - name: Create the wildcard certificate for *.eci-prod.eu.fsn1.trwrk.xyz
# run: kubectl --v=8 -n ${{ env.NAMESPACE }} --validate=false apply -f ./wildcard-cert-eci.yml
# - name: Run helm deploy
# run: >
# helm upgrade eci-bullboard ./services/bullboard/helm-chart
# --install
# --create-namespace
# --namespace=eci-prod
# --set=imagePullSecret="regcred"
# --set=image.imageName="${{ env.REGISTRY }}/${{ github.repository }}/bullboard:sha-$(git rev-parse --short HEAD)"
# --set=nodeEnv="production"
# --set=redis.host="${{ secrets.REDIS_HOST }}"
# --set=redis.port="${{ secrets.REDIS_PORT }}"
# --set=redis.password="${{ secrets.REDIS_PASSWORD }}"
# --set=ingress.host="queue-manager.eci-prod.eu.fsn1.trwrk.xyz"
# --set=ingress.tls.secretName="eci-trwrk-wildcard"
# --set=google.clientId="${{ secrets.GOOGLE_OAUTH_ID }}"
# --set=google.clientSecret="${{ secrets.GOOGLE_OAUTH_SECRET }}"
# --set=ingress.annotations."cert-manager\.io/cluster-issuer"="letsencrypt-prod"