-
Notifications
You must be signed in to change notification settings - Fork 0
254 lines (219 loc) · 9.65 KB
/
docker-publish.yml
File metadata and controls
254 lines (219 loc) · 9.65 KB
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
name: Build and Publish and Deploy
on:
push:
branches:
- main
workflow_dispatch:
# if input image tag, then skip test and build
inputs:
image:
description: "Image name and tag"
required: false
jobs:
unit-test:
if: ${{ github.event.inputs.image == '' || github.event.inputs.image == null }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4.4.1
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Make gradlew executable
run: chmod +x gradlew
- name: Make protobuf executable
run: chmod +x service-application/protoc-gen-grpc-java-1.73.0-linux-x86_64.exe
- name: Run tests for all modules
run: ./gradlew test
build-and-push:
needs: unit-test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Generate .env with proper tag
run: |
echo "GHCR_USER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" > .env
echo "GHCR_REPO=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> .env
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "GHCR_TAG=${{ github.sha }}" >> .env
else
echo "GHCR_TAG=dev-${{ github.sha }}" >> .env
fi
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "VITE_API_BASE_URL=${{ vars.K8S_BASE_API }}" >> .env
else
echo "VITE_API_BASE_URL=${{ vars.K8S_BASE_API_DEV }}" >> .env
fi
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build all images via docker compose
run: docker compose -f docker-compose.prod.yml build
- name: Push all images via docker compose
run: docker compose -f docker-compose.prod.yml push
deploy-k8s:
needs: build-and-push
runs-on: ubuntu-latest
environment:
name: ${{ github.ref == 'refs/heads/main' && 'k8s' || 'k8s-dev' }}
url: ${{ github.ref == 'refs/heads/main' && 'https://ai-hr.student.k8s.aet.cit.tum.de' || 'https://ai-hr-dev.student.k8s.aet.cit.tum.de' }}
steps:
- uses: actions/checkout@v4
- name: Set kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG_AIHR }}" > ~/.kube/config
chmod 600 ~/.kube/config
- uses: azure/setup-kubectl@v4
with: { version: 'v1.30.0' }
- uses: azure/setup-helm@v4
with: { version: 'v3.14.0' }
- name: Calc stage / ns
id: vars
run: |
BRANCH="${GITHUB_REF##*/}"
echo "GHCR_USER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "GHCR_REPO=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
if [[ "$BRANCH" == "main" ]]; then
echo "IMAGE_TAG=${GITHUB_SHA}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=dev-${GITHUB_SHA}" >> $GITHUB_ENV
fi
if [[ "$BRANCH" == "main" ]]; then
echo "stage=prod" >>$GITHUB_OUTPUT
echo "ns=ai-hr" >>$GITHUB_OUTPUT
echo "release=ai-hr-prod" >>$GITHUB_OUTPUT
else
echo "stage=dev" >>$GITHUB_OUTPUT
echo "ns=ai-hr-dev" >>$GITHUB_OUTPUT
echo "release=ai-hr-dev" >>$GITHUB_OUTPUT
fi
echo "OLLAMA_MODEL=${{ vars.OLLAMA_MODEL }}" >> $GITHUB_ENV
- name: Write JWT keys
run: |
echo "${{ secrets.JWT_PRIV_KEY }}" > priv.pem
echo "${{ secrets.JWT_PUB_KEY }}" > pub.pem
- name: Helm dependency update
run: helm dependency update ./helm/aihr
- name: unzip tgz files inside helm
run: |
cd helm/aihr/charts/
tar -xvzf grafana-9.2.10.tgz
rm grafana-9.2.10.tgz
- name: Copy dashboard json
run: |
cp -r ./dashboards/* ./helm/aihr/charts/grafana/dashboards/
- name: Helm deploy
run: |
helm upgrade --install ${{ steps.vars.outputs.release }} ./helm/aihr \
--namespace ${{ steps.vars.outputs.ns }} --create-namespace \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-prometheus.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-grafana.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-loki.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-promtail.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-frontend.yaml \
-f helm/aihr/values-common-loki.yaml \
-f helm/aihr/values-common-promtail.yaml \
-f helm/aihr/values-common-prometheus.yaml \
-f helm/aihr/values-common-grafana.yaml \
-f helm/aihr/values-common-discord-alert.yaml \
--set discordWebhook.url=${{ secrets.DISCORD_WEBHOOK }} \
--set global.ghcrUser=${{ env.GHCR_USER }} \
--set global.ghcrRepo=${{ env.GHCR_REPO }} \
--set global.imageTag=${{ env.IMAGE_TAG }} \
--set-file global.jwt.privateKey=priv.pem \
--set-file global.jwt.publicKey=pub.pem \
--set global.ollama.ollamaBaseUrl=${{ secrets.OLLAMA_BASE_URL }} \
--set global.ollama.ollamaModel=${{ env.OLLAMA_MODEL }} \
--set global.ollama.ollamaApiKey=${{ secrets.OLLAMA_API_KEY }} \
--wait --timeout 15m
deploy-k8s-direct:
if: ${{ github.event.inputs.image != '' && github.event.inputs.image != null }}
runs-on: ubuntu-latest
environment:
name: ${{ github.ref == 'refs/heads/main' && 'k8s' || 'k8s-dev' }}
url: ${{ github.ref == 'refs/heads/main' && 'https://ai-hr.student.k8s.aet.cit.tum.de' || 'https://ai-hr-dev.student.k8s.aet.cit.tum.de' }}
steps:
- uses: actions/checkout@v4
- name: Set kubeconfig
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG_AIHR }}" > ~/.kube/config
chmod 600 ~/.kube/config
- uses: azure/setup-kubectl@v4
with: { version: 'v1.30.0' }
- uses: azure/setup-helm@v4
with: { version: 'v3.14.0' }
- name: Calc stage / ns
id: vars
run: |
BRANCH="${GITHUB_REF##*/}"
echo "GHCR_USER=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
echo "GHCR_REPO=$(echo '${{ github.event.repository.name }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
if [[ -n "${{ github.event.inputs.image }}" ]]; then
echo "IMAGE_TAG=${{ github.event.inputs.image }}" >> $GITHUB_ENV
else
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
fi
if [[ "$BRANCH" == "main" ]]; then
echo "stage=prod" >>$GITHUB_OUTPUT
echo "ns=ai-hr" >>$GITHUB_OUTPUT
echo "release=ai-hr-prod" >>$GITHUB_OUTPUT
else
echo "stage=dev" >>$GITHUB_OUTPUT
echo "ns=ai-hr-dev" >>$GITHUB_OUTPUT
echo "release=ai-hr-dev" >>$GITHUB_OUTPUT
fi
echo "OLLAMA_MODEL=${{ vars.OLLAMA_MODEL }}" >> $GITHUB_ENV
- name: Write JWT keys
run: |
echo "${{ secrets.JWT_PRIV_KEY }}" > priv.pem
echo "${{ secrets.JWT_PUB_KEY }}" > pub.pem
- name: Helm dependency update
run: helm dependency update ./helm/aihr
- name: unzip tgz files inside helm
run: |
cd helm/aihr/charts/
tar -xvzf grafana-9.2.10.tgz
rm grafana-9.2.10.tgz
- name: Copy dashboard json
run: |
cp -r ./dashboards/* ./helm/aihr/charts/grafana/dashboards/
- name: Helm deploy
run: |
helm upgrade --install ${{ steps.vars.outputs.release }} ./helm/aihr \
--namespace ${{ steps.vars.outputs.ns }} --create-namespace \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-prometheus.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-grafana.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-loki.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-promtail.yaml \
-f helm/aihr/values-${{ steps.vars.outputs.stage }}-frontend.yaml \
-f helm/aihr/values-common-loki.yaml \
-f helm/aihr/values-common-promtail.yaml \
-f helm/aihr/values-common-prometheus.yaml \
-f helm/aihr/values-common-grafana.yaml \
-f helm/aihr/values-common-discord-alert.yaml \
--set discordWebhook.url=${{ secrets.DISCORD_WEBHOOK }} \
--set global.ghcrUser=${{ env.GHCR_USER }} \
--set global.ghcrRepo=${{ env.GHCR_REPO }} \
--set global.imageTag=${{ env.IMAGE_TAG }} \
--set-file global.jwt.privateKey=priv.pem \
--set-file global.jwt.publicKey=pub.pem \
--set global.ollama.ollamaBaseUrl=${{ secrets.OLLAMA_BASE_URL }} \
--set global.ollama.ollamaModel=${{ env.OLLAMA_MODEL }} \
--set global.ollama.ollamaApiKey=${{ secrets.OLLAMA_API_KEY }} \
--wait --timeout 15m