forked from open-webui/open-webui
-
Notifications
You must be signed in to change notification settings - Fork 0
281 lines (252 loc) · 11.5 KB
/
Copy pathbuild.yml
File metadata and controls
281 lines (252 loc) · 11.5 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
name: Build and Deploy Garnet
on:
workflow_dispatch:
push:
tags:
- v*
branches:
- deploy/staging
- deploy/prod
- garnet-privacy-proxy
paths:
- 'backend/privacy_proxy/**'
- 'src/**'
- 'backend/open_webui/**'
- 'Dockerfile'
- 'docker-compose.yml'
- 'version/VERSION'
- '.github/workflows/**'
pull_request:
branches:
- garnet-privacy-proxy
jobs:
# ── GET VERSION + TAG ─────────────────────────────────
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
# ── SECRET SCAN (PR) ──────────────────────────────────
secret-scan-pr:
needs: get-meta
if: github.event_name == 'pull_request'
uses: enclaive/security-workflows/.github/workflows/trufflehog-pr.yml@v1
# ── SECRET SCAN (FULL) ────────────────────────────────
secret-scan-full:
needs: get-meta
if: github.event_name == 'push'
uses: enclaive/security-workflows/.github/workflows/trufflehog-full.yml@v1
# ── PROXY ─────────────────────────────────────────────
build-proxy:
needs: get-meta
if: needs.get-meta.outputs.proxy_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 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
# ── PYTHON CHECKS (pip-audit, ruff, mypy, trivy, bandit) ──
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 ──────────────────────────────────────
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 ─────────────────────────────────────────
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 }}
# ── WEBUI ─────────────────────────────────────────────
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
# ── DEPLOY WEBUI ──────────────────────────────────────
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])'"