forked from open-webui/open-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
355 lines (320 loc) · 14.1 KB
/
Copy pathbuild.yml
File metadata and controls
355 lines (320 loc) · 14.1 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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
name: Build and Deploy Garnet
on:
workflow_dispatch:
push:
tags:
- v*
branches:
- deploy/staging
- deploy/prod
- garnet-privacy-proxy
pull_request:
branches:
- garnet-privacy-proxy
jobs:
get-meta:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
tag: ${{ steps.get_tag.outputs.name }}
revision: ${{ steps.get_revision.outputs.revision }}
proxy_changed: ${{ steps.changes.outputs.proxy }}
webui_changed: ${{ steps.changes.outputs.webui }}
steps:
- name: Checkout
run: |
git clone --branch ${{ github.ref_name }} \
https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/enclaive/garnet.git .
- name: Get version
id: get_version
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
echo "version=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
else
echo "version=$(cat version/VERSION).nightly" >> $GITHUB_OUTPUT
fi
- name: Get revision
id: get_revision
run: echo "revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Get tag
id: get_tag
run: |
case "${GITHUB_REF}" in
refs/heads/deploy/staging) NAME=staging ;;
refs/heads/deploy/prod) NAME=prod ;;
refs/tags/v*) NAME=latest ;;
*) NAME="${FALLBACK}" ;;
esac
echo "name=${NAME}" >> $GITHUB_OUTPUT
env:
FALLBACK: ${{ steps.get_revision.outputs.revision }}
- name: Check changed files
id: changes
run: |
git diff --name-only HEAD~1 HEAD | grep '^backend/privacy_proxy/' \
&& echo "proxy=true" >> $GITHUB_OUTPUT \
|| echo "proxy=false" >> $GITHUB_OUTPUT
git diff --name-only HEAD~1 HEAD | grep -E '^src/|^backend/open_webui/' \
&& echo "webui=true" >> $GITHUB_OUTPUT \
|| echo "webui=false" >> $GITHUB_OUTPUT
build-proxy:
needs: get-meta
if: needs.get-meta.outputs.proxy_changed == 'true'
runs-on: ubuntu-latest
environment: production
permissions:
contents: read
steps:
- name: Checkout
run: |
git clone --branch ${{ github.ref_name }} \
https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/enclaive/garnet.git .
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache
df -h
- name: Set up Docker Buildx
run: |
docker buildx create --use --name garnet-builder
docker buildx inspect --bootstrap
- name: Login to Harbor
run: |
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login harbor.enclaive.cloud \
-u "${{ secrets.HARBOR_USERNAME }}" --password-stdin
- name: Build and push proxy image
id: build-proxy
run: |
DIGEST=$(docker buildx build \
-f backend/privacy_proxy/Dockerfile \
--build-arg PRODUCT_VERSION=${{ needs.get-meta.outputs.version }} \
--build-arg PRODUCT_REVISION=${{ needs.get-meta.outputs.revision }} \
--cache-from type=registry,ref=harbor.enclaive.cloud/garnetdemo/privacy-proxy:cache \
--cache-to type=registry,ref=harbor.enclaive.cloud/garnetdemo/privacy-proxy:cache,mode=max \
--tag harbor.enclaive.cloud/garnetdemo/privacy-proxy:${{ needs.get-meta.outputs.tag }} \
--tag harbor.enclaive.cloud/garnetdemo/privacy-proxy:${{ needs.get-meta.outputs.version }} \
--tag harbor.enclaive.cloud/garnetdemo/privacy-proxy:${{ needs.get-meta.outputs.revision }} \
--tag harbor.enclaive.cloud/garnetdemo/privacy-proxy:gh-run-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.run_number }} \
--push \
--metadata-file /tmp/proxy-meta.json \
backend/privacy_proxy/ && \
cat /tmp/proxy-meta.json | python3 -c "import sys,json; print(json.load(sys.stdin)['containerimage.digest'])")
echo "digest=harbor.enclaive.cloud/garnetdemo/privacy-proxy@${DIGEST}" >> $GITHUB_OUTPUT
- name: Install cosign
run: |
curl -sfL https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 \
-o /usr/local/bin/cosign && chmod +x /usr/local/bin/cosign
- name: Sign proxy image
run: |
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
COSIGN_PASSWORD="" cosign sign --yes --key /tmp/cosign.key \
${{ steps.build-proxy.outputs.digest }}
rm /tmp/cosign.key
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh \
| sh -s -- -b /usr/local/bin
- name: Generate SBOM + attest proxy
run: |
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
syft ${{ steps.build-proxy.outputs.digest }} -o spdx-json > /tmp/sbom-proxy.spdx.json
COSIGN_PASSWORD="" cosign attest --yes \
--key /tmp/cosign.key \
--type spdxjson \
--predicate /tmp/sbom-proxy.spdx.json \
${{ steps.build-proxy.outputs.digest }}
rm /tmp/cosign.key
- name: Attest provenance proxy
run: |
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
cat > /tmp/provenance-proxy.json << EOF
{
"buildType": "https://github.com/enclaive/garnet",
"builder": {"id": "github-actions"},
"invocation": {
"configSource": {
"uri": "git+https://github.com/enclaive/garnet",
"digest": {"sha1": "${{ github.sha }}"}
}
}
}
EOF
COSIGN_PASSWORD="" cosign attest --yes \
--key /tmp/cosign.key \
--type slsaprovenance \
--predicate /tmp/provenance-proxy.json \
${{ steps.build-proxy.outputs.digest }}
rm /tmp/cosign.key
- name: Save SBOM + provenance to cVM
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan ${{ secrets.CVM_HOST }} >> ~/.ssh/known_hosts
ssh root@${{ secrets.CVM_HOST }} "mkdir -p /opt/garnet/sbom"
scp /tmp/sbom-proxy.spdx.json root@${{ secrets.CVM_HOST }}:/opt/garnet/sbom/sbom-proxy-${{ needs.get-meta.outputs.revision }}.spdx.json
scp /tmp/provenance-proxy.json root@${{ secrets.CVM_HOST }}:/opt/garnet/sbom/provenance-proxy-${{ needs.get-meta.outputs.revision }}.json
python-checks:
needs: [get-meta, build-proxy]
if: needs.get-meta.outputs.proxy_changed == 'true'
uses: ./.github/workflows/pythoncheck.yml
with:
image_tag: ${{ needs.get-meta.outputs.revision }}
secrets:
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
deploy-proxy:
needs: [get-meta, build-proxy, python-checks]
if: needs.get-meta.outputs.proxy_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Deploy proxy to cVM
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan ${{ secrets.CVM_HOST }} >> ~/.ssh/known_hosts
ssh root@${{ secrets.CVM_HOST }} "cd /opt/garnet && \
echo '${{ secrets.HARBOR_PASSWORD }}' | docker login harbor.enclaive.cloud \
-u '${{ secrets.HARBOR_USERNAME }}' --password-stdin && \
docker compose pull privacy-proxy && \
docker compose up -d --force-recreate privacy-proxy"
- name: Health check proxy
run: |
sleep 10
ssh root@${{ secrets.CVM_HOST }} "\
docker exec garnet-privacy-proxy-1 python3 -c \
'import urllib.request; print(urllib.request.urlopen(\"http://localhost:8080/health\").read())'"
run-tests:
needs: deploy-proxy
if: needs.get-meta.outputs.proxy_changed == 'true'
uses: ./.github/workflows/proxy-tests.yml
secrets:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
CVM_HOST: ${{ secrets.CVM_HOST }}
build-webui:
needs: get-meta
if: needs.get-meta.outputs.webui_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
run: |
git clone --branch ${{ github.ref_name }} \
https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/enclaive/garnet.git .
- name: Free disk space
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache
df -h
- name: Set up Docker Buildx
run: |
docker buildx create --use --name garnet-builder
docker buildx inspect --bootstrap
- name: Login to Harbor
run: |
echo "${{ secrets.HARBOR_PASSWORD }}" | docker login harbor.enclaive.cloud \
-u "${{ secrets.HARBOR_USERNAME }}" --password-stdin
- name: Build and push webui image
id: build-webui
run: |
DIGEST=$(docker buildx build \
--build-arg PRODUCT_VERSION=${{ needs.get-meta.outputs.version }} \
--build-arg PRODUCT_REVISION=${{ needs.get-meta.outputs.revision }} \
--cache-from type=registry,ref=harbor.enclaive.cloud/garnetdemo/garnet-webui:cache \
--cache-to type=registry,ref=harbor.enclaive.cloud/garnetdemo/garnet-webui:cache,mode=max \
--tag harbor.enclaive.cloud/garnetdemo/garnet-webui:${{ needs.get-meta.outputs.tag }} \
--tag harbor.enclaive.cloud/garnetdemo/garnet-webui:${{ needs.get-meta.outputs.version }} \
--tag harbor.enclaive.cloud/garnetdemo/garnet-webui:${{ needs.get-meta.outputs.revision }} \
--tag harbor.enclaive.cloud/garnetdemo/garnet-webui:gh-run-${{ github.run_id }}-${{ github.run_attempt }}-${{ github.run_number }} \
--push \
--metadata-file /tmp/webui-meta.json \
. && \
cat /tmp/webui-meta.json | python3 -c "import sys,json; print(json.load(sys.stdin)['containerimage.digest'])")
echo "digest=harbor.enclaive.cloud/garnetdemo/garnet-webui@${DIGEST}" >> $GITHUB_OUTPUT
- name: Install cosign
run: |
curl -sfL https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64 \
-o /usr/local/bin/cosign && chmod +x /usr/local/bin/cosign
- name: Sign webui image
run: |
sleep 10
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
COSIGN_PASSWORD="" cosign sign --yes --key /tmp/cosign.key \
${{ steps.build-webui.outputs.digest }}
rm /tmp/cosign.key
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh \
| sh -s -- -b /usr/local/bin
- name: Generate SBOM + attest webui
run: |
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
syft ${{ steps.build-webui.outputs.digest }} -o spdx-json > /tmp/sbom-webui.spdx.json
COSIGN_PASSWORD="" cosign attest --yes \
--key /tmp/cosign.key \
--type spdxjson \
--predicate /tmp/sbom-webui.spdx.json \
${{ steps.build-webui.outputs.digest }}
rm /tmp/cosign.key
- name: Attest provenance webui
run: |
echo "${{ secrets.COSIGN_PRIVATE_KEY }}" > /tmp/cosign.key
chmod 600 /tmp/cosign.key
cat > /tmp/provenance-webui.json << EOF
{
"buildType": "https://github.com/enclaive/garnet",
"builder": {"id": "github-actions"},
"invocation": {
"configSource": {
"uri": "git+https://github.com/enclaive/garnet",
"digest": {"sha1": "${{ github.sha }}"}
}
}
}
EOF
COSIGN_PASSWORD="" cosign attest --yes \
--key /tmp/cosign.key \
--type slsaprovenance \
--predicate /tmp/provenance-webui.json \
${{ steps.build-webui.outputs.digest }}
rm /tmp/cosign.key
- name: Save SBOM + provenance to cVM
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan ${{ secrets.CVM_HOST }} >> ~/.ssh/known_hosts
ssh root@${{ secrets.CVM_HOST }} "mkdir -p /opt/garnet/sbom"
scp /tmp/sbom-webui.spdx.json root@${{ secrets.CVM_HOST }}:/opt/garnet/sbom/sbom-webui-${{ needs.get-meta.outputs.revision }}.spdx.json
scp /tmp/provenance-webui.json root@${{ secrets.CVM_HOST }}:/opt/garnet/sbom/provenance-webui-${{ needs.get-meta.outputs.revision }}.json
deploy-webui:
needs: [get-meta, build-webui]
if: needs.get-meta.outputs.webui_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Deploy webui to cVM
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan ${{ secrets.CVM_HOST }} >> ~/.ssh/known_hosts
ssh root@${{ secrets.CVM_HOST }} "cd /opt/garnet && \
echo '${{ secrets.HARBOR_PASSWORD }}' | docker login harbor.enclaive.cloud \
-u '${{ secrets.HARBOR_USERNAME }}' --password-stdin && \
docker compose pull open-webui && \
docker compose up -d --force-recreate open-webui"
- name: Health check webui
run: |
sleep 15
ssh root@${{ secrets.CVM_HOST }} "\
docker exec garnet-open-webui-1 python3 -c \
'import urllib.request; print(urllib.request.urlopen(\"http://localhost:8080/\").read()[:50])'"