-
Notifications
You must be signed in to change notification settings - Fork 1
111 lines (98 loc) · 4.14 KB
/
Copy pathdeploy-kilo-proxy.yml
File metadata and controls
111 lines (98 loc) · 4.14 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
name: Deploy Kilo Proxy to Deno Deploy
on:
workflow_dispatch:
push:
paths:
- 'cloudflare-worker/kilo-proxy/kilo_proxy.ts'
- '.github/workflows/deploy-kilo-proxy.yml'
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Deploy to Deno Deploy
env:
DENO_DEPLOY_TOKEN: ${{ secrets.DENO_DEPLOY_TOKEN }}
run: |
set -euo pipefail
ORG="android-poweruser"
APP="screenoperator-kilo-proxy"
# Deploy is executed from inside the proxy directory, so the
# entrypoint is relative to that directory.
SRC_DIR="cloudflare-worker/kilo-proxy"
ENTRYPOINT="kilo_proxy.ts"
API="https://console.deno.com/api/v2"
# 1) Create the app if it does not exist yet.
# "|| true" is only tolerated here, the runtime mode is enforced in step 2.
deno deploy create \
--org="$ORG" \
--app="$APP" \
--token="$DENO_DEPLOY_TOKEN" \
--json --non-interactive \
--source=local \
--runtime-mode=dynamic \
--entrypoint="$ENTRYPOINT" \
--region=us \
"$SRC_DIR" 2>&1 || echo "create skipped (app probably already exists)"
# 2) Enforce the runtime mode on the EXISTING app.
# This is the actual fix: an app that was once created in "static"
# mode keeps that mode forever, because `deno deploy` (without
# `create`) never changes the runtime configuration. The result is a
# deployment that serves static files and answers every API request
# with 405 "Method Not Allowed" -> the WebView sees a network error.
echo "Current app config:"
curl -sS -H "Authorization: Bearer $DENO_DEPLOY_TOKEN" \
"$API/apps/$APP" | tee current-config.json
echo
echo "Forcing runtime mode: dynamic (entrypoint: $ENTRYPOINT)"
HTTP_CODE=$(curl -sS -o patched-config.json -w '%{http_code}' \
-X PATCH \
-H "Authorization: Bearer $DENO_DEPLOY_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"config\":{\"runtime\":{\"type\":\"dynamic\",\"entrypoint\":\"$ENTRYPOINT\"}}}" \
"$API/apps/$APP")
cat patched-config.json; echo
if [ "$HTTP_CODE" != "200" ]; then
echo "::error::Could not set runtime mode to dynamic (HTTP $HTTP_CODE)"
exit 1
fi
if ! grep -q '"type": *"dynamic"' patched-config.json; then
echo "::error::App is still not in dynamic runtime mode"
exit 1
fi
# 3) Deploy to production.
cd "$SRC_DIR"
deno deploy \
--org="$ORG" \
--app="$APP" \
--token="$DENO_DEPLOY_TOKEN" \
--json --non-interactive \
--prod \
.
- name: Verify proxy is alive
run: |
set -euo pipefail
URL="https://screenoperator-kilo-proxy.android-poweruser.deno.net/api/gateway/chat/completions"
# Give the new revision a moment to be routed.
for i in 1 2 3 4 5 6 7 8 9 10; do
PRE=$(curl -s -o /dev/null -w '%{http_code}' -X OPTIONS "$URL" \
-H "Origin: https://appassets.androidplatform.net" --max-time 20 || echo 000)
POST=$(curl -s -o /dev/null -w '%{http_code}' -X POST "$URL" \
-H "Content-Type: application/json" \
-d '{"model":"probe","messages":[]}' --max-time 30 || echo 000)
echo "attempt $i: OPTIONS=$PRE POST=$POST"
# 405 on POST means the static runtime is still being served.
if [ "$PRE" = "200" ] && [ "$POST" != "405" ] && [ "$POST" != "000" ]; then
echo "Proxy is live and forwarding to api.kilo.ai."
exit 0
fi
sleep 10
done
echo "::error::Proxy did not answer correctly (still static / unreachable)."
exit 1