-
Notifications
You must be signed in to change notification settings - Fork 2
185 lines (157 loc) · 6.42 KB
/
Copy pathdeploy-demo.yml
File metadata and controls
185 lines (157 loc) · 6.42 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
name: Deploy demo
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-demo
cancel-in-progress: false
env:
NODE_VERSION: '22'
DEMO_WEB_DOMAIN: https://risto-menu.andreabaccega.com
DEMO_PAGES_DOMAIN: https://risto-menu-demo.pages.dev
DEMO_API_DOMAIN: https://risto-menu-api.andreabaccega.com
DEMO_CHAT_DOMAIN: https://risto-menu-demo-chat.vekexasia.workers.dev
DEMO_CHAT_NAME: risto-menu-demo-chat
DEMO_CHAT_KV_NAMESPACE_ID: 705f0360cf374bb2b67f4f76b2937dea
DEMO_BACKEND_NAME: risto-menu-demo-api
DEMO_PAGES_PROJECT: risto-menu-demo
DEMO_D1_DATABASE_NAME: risto-menu-demo-db
jobs:
deploy-demo:
name: Deploy demo stack
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: npm
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci
- name: Install chat worker dependencies
working-directory: web/workers/chat
run: npm ci
- name: Backend checks
run: |
npm --workspace backend run check
npm --workspace backend run test:run
npm --workspace backend run test:migration-sql
- name: Web checks
run: |
npm --workspace web run lint
npm --workspace web run test:run
- name: Write demo backend config
working-directory: backend
run: |
cat > wrangler.demo.toml <<EOF
name = "${DEMO_BACKEND_NAME}"
main = "src/index.ts"
compatibility_date = "2025-04-11"
routes = [
{ pattern = "risto-menu-api.andreabaccega.com", custom_domain = true }
]
[vars]
APP_ENV = "staging"
API_VERSION = "v1"
SERVICE_NAME = "risto-menu-demo-api"
DEMO_MODE = "true"
ALLOWED_ORIGINS = "${DEMO_WEB_DOMAIN}"
ALLOWED_HOST_SUFFIXES = ".pages.dev"
R2_PUBLIC_URL = ""
[triggers]
crons = ["0 * * * *"]
[[d1_databases]]
binding = "DB"
database_name = "${DEMO_D1_DATABASE_NAME}"
database_id = "${{ vars.DEMO_D1_DATABASE_ID }}"
migrations_dir = "drizzle"
EOF
- name: Apply demo D1 migrations
working-directory: backend
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler d1 migrations apply "${DEMO_D1_DATABASE_NAME}" --remote --config wrangler.demo.toml
- name: Deploy demo backend
working-directory: backend
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler deploy --config wrangler.demo.toml
- name: Write demo chat config
working-directory: web/workers/chat
run: |
cat > wrangler.demo.toml <<EOF
name = "${DEMO_CHAT_NAME}"
main = "src/index.ts"
compatibility_date = "2024-12-01"
[[kv_namespaces]]
binding = "MENU_CACHE"
id = "${DEMO_CHAT_KV_NAMESPACE_ID}"
[[d1_databases]]
binding = "DB"
database_name = "${DEMO_D1_DATABASE_NAME}"
database_id = "${{ vars.DEMO_D1_DATABASE_ID }}"
migrations_dir = "../../../backend/drizzle"
[ai]
binding = "AI"
[vars]
CHAT_SESSION_SECRET = "${{ secrets.DEMO_CHAT_SESSION_SECRET }}"
LLM_PROVIDER = "workers-ai"
LLM_MODEL = "@cf/meta/llama-3.3-70b-instruct-fp8-fast"
DAILY_AI_REQUEST_LIMIT = "200"
ALLOWED_ORIGINS = "${DEMO_WEB_DOMAIN},${DEMO_PAGES_DOMAIN}"
ALLOWED_HOST_SUFFIXES = ".pages.dev"
EOF
- name: Deploy demo chat worker
working-directory: web/workers/chat
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler deploy --config wrangler.demo.toml
- name: Build demo frontend
working-directory: web
env:
NEXT_PUBLIC_API_URL: ${{ env.DEMO_API_DOMAIN }}
NEXT_PUBLIC_CHAT_WORKER_URL: ${{ env.DEMO_CHAT_DOMAIN }}
NEXT_PUBLIC_DEFAULT_LOCALE: en
run: npm run build:cf
- name: Deploy demo frontend
working-directory: web
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npx wrangler pages deploy out --project-name="${DEMO_PAGES_PROJECT}" --branch=main
- name: Seed demo data
env:
DEMO_API_DOMAIN: ${{ env.DEMO_API_DOMAIN }}
run: |
curl --fail --retry 5 --retry-delay 5 -X POST "${DEMO_API_DOMAIN}/admin/demo/reset"
- name: Smoke test demo API
env:
DEMO_API_DOMAIN: ${{ env.DEMO_API_DOMAIN }}
run: |
curl --fail --retry 8 --retry-all-errors --retry-delay 5 --max-time 20 "${DEMO_API_DOMAIN}/health"
curl --fail --retry 8 --retry-all-errors --retry-delay 5 --max-time 20 "${DEMO_API_DOMAIN}/catalog" -o /tmp/catalog.json
node -e "const c=require('/tmp/catalog.json'); const entries=(c.menus||[]).flatMap(m => m.categories || []).flatMap(cat => cat.entries || []); if (c.restaurant?.name !== 'Trattoria Demo') throw new Error('demo fixture not loaded: ' + c.restaurant?.name); if (entries.length < 10) throw new Error('demo catalog too small')"
- name: Smoke test demo frontend
env:
DEMO_PAGES_DOMAIN: ${{ env.DEMO_PAGES_DOMAIN }}
DEMO_API_DOMAIN: ${{ env.DEMO_API_DOMAIN }}
run: |
curl --fail --retry 10 --retry-delay 6 "${DEMO_PAGES_DOMAIN}/it/menu/" -o /tmp/menu.html
grep -q "_next/static" /tmp/menu.html
grep -R "${DEMO_API_DOMAIN}" web/out/_next/static
grep -R "${DEMO_CHAT_DOMAIN}" web/out/_next/static
! grep -R "http://localhost\|http://127\.0\.0\.1\|:8787\|:8788" web/out/_next/static
grep -R "Tony" web/out/_next/static
- name: Demo URLs
run: |
echo "Public menu: ${DEMO_WEB_DOMAIN}/it/menu/"
echo "Pages fallback: ${DEMO_PAGES_DOMAIN}/it/menu/"
echo "Admin: ${DEMO_WEB_DOMAIN}/admin"
echo "API: ${DEMO_API_DOMAIN}"