Repository navigation
276 lines (271 loc) · 13.3 KB
/
Copy pathcloud-deploy.yml
File metadata and controls
276 lines (271 loc) · 13.3 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
name: Cloud deploy
run-name: Alpha Cloud ${{ github.event_name == 'push' && 'staging then production' || format('{0} ({1})', inputs.action, inputs.environment) }} on ${{ github.sha }}
# Deploys Alpha Cloud (spec/cloud/rollout.md): the API Worker (apps/cloud/src/worker.vibe)
# and the web host Worker (apps/cloud/src/edge.vibe), through `pnpm cloud`. Pushes to main promote the same
# commit after staging passes. Manual runs follow the selected environment's deployment branch policy. Deploying the Cloud
# leaves the hosts bundled in each installed app in place.
#
# Each GitHub environment (alpha-cloud-staging, alpha-cloud-production) holds:
# secret CLOUDFLARE_API_TOKEN Workers Scripts and Routes, Hyperdrive edit, and Zone DNS edit
# secret ALPHA_CLOUD_ENV the completed secrets file of `pnpm cloud secrets` (run once locally)
# secret ALPHA_CLOUD_PROFILE the operator's completed apps/cloud/profile/candidate.example.json
# secrets INFERENCE_CACHE_URL and INFERENCE_CACHE_TOKEN environment-specific Redis REST binding
# secret ALPHA_CLOUD_DB_CA the dedicated PostgreSQL server CA certificate for this environment
# secrets SLACK_CLIENT_ID, SLACK_APP_ID, SLACK_APP_TOKEN, SLACK_SIGNING_SECRET, TELEGRAM_API_ID,
# GOOGLE_CLIENT_SECRET, GOOGLE_CONNECT_CLIENT_SECRET
# optional; each one set replaces the same line of ALPHA_CLOUD_ENV
# secrets GOOGLE_CLIENT_ID, GOOGLE_CONNECT_CLIENT_ID
# optional; when set, override environments[E].google.clientId and
# environments[E].google.serverClientId in ALPHA_CLOUD_PROFILE
# Account and resource ids come from the committed apps/cloud/resources.json.
on:
push:
branches: [main]
paths:
- apps/cloud/**
- apps/app/**
- spec/app/**
- spec/kit/**
- packages/ui/**
- packages/design-system/**
- spec/cloud/**
- spec/index.md
- packages/deployment/**
- packages/eliza-harness/**
- eliza.lock.json
- vibestack/**
- .nvmrc
- package.json
- pnpm-lock.yaml
- pnpm-workspace.yaml
- tsconfig.base.json
- turbo.json
- .github/actions/setup/**
- .github/workflows/cloud-deploy.yml
workflow_dispatch:
inputs:
environment:
description: staging or production
required: true
type: choice
options: [staging, production]
action:
description: "bundle: render and bundle only. deploy: secrets, resources, migrations, registration, prices, Workers, public gates."
required: true
type: choice
options: [bundle, deploy]
component:
description: Worker to deploy (deploy only)
required: true
default: all
type: choice
options: [all, api, edge]
permissions:
contents: read
concurrency:
group: ${{ github.event_name == 'workflow_dispatch' && inputs.action == 'bundle' && format('alpha-cloud-bundle-{0}', inputs.environment) || 'alpha-cloud-deploy' }}
cancel-in-progress: false
jobs:
staging:
if: github.repository_id == '1396333361' && (github.event_name == 'push' || inputs.environment == 'staging')
runs-on: ubuntu-24.04
timeout-minutes: 90
environment: alpha-cloud-staging
env:
E: staging
COMPONENT: ${{ github.event_name == 'push' && 'all' || inputs.component }}
steps: &cloud-steps
- uses: actions/checkout@v7
with:
persist-credentials: false
ref: ${{ github.sha }}
- uses: ./.github/actions/setup
with:
job: ""
verification: "false"
- run: pnpm eliza
- name: Write the private profile
env:
ALPHA_CLOUD_PROFILE: ${{ secrets.ALPHA_CLOUD_PROFILE }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_CONNECT_CLIENT_ID: ${{ secrets.GOOGLE_CONNECT_CLIENT_ID }}
run: |
umask 077
node --input-type=module <<'JS'
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
const reject = (message) => {
console.error(message);
process.exit(1);
};
const raw = process.env.ALPHA_CLOUD_PROFILE;
if (!raw) reject('ALPHA_CLOUD_PROFILE is empty: store the completed operator profile');
const clientId = process.env.GOOGLE_CLIENT_ID?.trim();
const connectClientId = process.env.GOOGLE_CONNECT_CLIENT_ID?.trim();
const outPath = join(process.env.RUNNER_TEMP, 'alpha-cloud-profile.json');
if (/[\r\n]/.test(clientId ?? '') || /[\r\n]/.test(connectClientId ?? '')) {
reject('GOOGLE_CLIENT_ID and GOOGLE_CONNECT_CLIENT_ID must be single-line values');
}
let profile;
try {
profile = JSON.parse(raw);
} catch {
reject('ALPHA_CLOUD_PROFILE must contain valid JSON');
}
const envName = process.env.E;
const environments = profile?.environments;
if (!environments || typeof environments !== 'object' || Array.isArray(environments)) {
reject('ALPHA_CLOUD_PROFILE is missing environments');
}
for (const environment of Object.values(environments)) {
const models = environment?.inference?.models;
if (!Array.isArray(models)) continue;
for (const model of models) {
if (model && typeof model === 'object' && model.id === 'qwen-3.8-27b' && model.provider === 'cerebras') {
model.vision = true;
}
}
}
if (clientId || connectClientId) {
const google = environments?.[envName]?.google;
if (!google || typeof google !== 'object' || Array.isArray(google)) {
reject(`ALPHA_CLOUD_PROFILE is missing environments.${envName}.google`);
}
if (clientId) google.clientId = clientId;
if (connectClientId) google.serverClientId = connectClientId;
}
writeFileSync(outPath, `${JSON.stringify(profile, null, 2)}\n`, { mode: 0o600 });
JS
- name: Render and bundle (dry run)
run: pnpm cloud bundle --environment "$E" --profile "$RUNNER_TEMP/alpha-cloud-profile.json" --out "$RUNNER_TEMP/rendered"
- name: Prepare the deployment and PostgreSQL inputs
if: github.event_name == 'push' || inputs.action == 'deploy'
env:
ALPHA_CLOUD_ENV: ${{ secrets.ALPHA_CLOUD_ENV }}
INFERENCE_CACHE_URL: ${{ secrets.INFERENCE_CACHE_URL }}
INFERENCE_CACHE_TOKEN: ${{ secrets.INFERENCE_CACHE_TOKEN }}
ALPHA_CLOUD_DB_CA: ${{ secrets.ALPHA_CLOUD_DB_CA }}
SLACK_CLIENT_ID: ${{ secrets.SLACK_CLIENT_ID }}
SLACK_APP_ID: ${{ secrets.SLACK_APP_ID }}
SLACK_APP_TOKEN: ${{ secrets.SLACK_APP_TOKEN }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
TELEGRAM_API_ID: ${{ secrets.TELEGRAM_API_ID }}
GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }}
GOOGLE_CONNECT_CLIENT_SECRET: ${{ secrets.GOOGLE_CONNECT_CLIENT_SECRET }}
run: |
node --input-type=module <<'JS'
import { X509Certificate } from 'node:crypto';
import { writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { parseEnv } from 'node:util';
const reject = (message) => {
console.error(message);
process.exit(1);
};
const file = process.env.ALPHA_CLOUD_ENV;
const ca = process.env.ALPHA_CLOUD_DB_CA?.trim();
if (!file) reject('ALPHA_CLOUD_ENV is empty: store the completed file of pnpm cloud secrets');
const overrides = [
'SLACK_CLIENT_ID',
'SLACK_APP_ID',
'SLACK_APP_TOKEN',
'SLACK_SIGNING_SECRET',
'TELEGRAM_API_ID',
'GOOGLE_CLIENT_SECRET',
'GOOGLE_CONNECT_CLIENT_SECRET',
].filter((name) => process.env[name]?.trim());
for (const name of overrides) {
const value = process.env[name].trim();
if (/[\r\n]/.test(value)) reject(`${name} must be a single-line value`);
const masked = value.replaceAll('%', '%25').replaceAll('\r', '%0D').replaceAll('\n', '%0A');
process.stdout.write(`::add-mask::${masked}\n`);
}
const source = [
...file.split(/\r?\n/).filter((line) => !overrides.some((name) => new RegExp(`^\\s*${name}\\s*=`).test(line))),
...overrides.map((name) => `${name}=${process.env[name].trim()}`),
].join('\n');
if (!ca) reject('ALPHA_CLOUD_DB_CA is empty: store the dedicated PostgreSQL CA certificate');
try {
if (!/^-----BEGIN CERTIFICATE-----\r?\n[A-Za-z0-9+/=\r\n]+-----END CERTIFICATE-----$/.test(ca) || !new X509Certificate(ca).ca) {
throw new Error();
}
} catch {
reject('ALPHA_CLOUD_DB_CA must contain one PEM CA certificate');
}
let database;
try {
database = new URL(parseEnv(source).DATABASE_URL);
if (!['postgres:', 'postgresql:'].includes(database.protocol) || !database.hostname || !database.username || !database.password || database.pathname.length < 2) {
throw new Error();
}
} catch {
reject('ALPHA_CLOUD_ENV must contain a PostgreSQL DATABASE_URL with credentials');
}
const temp = process.env.RUNNER_TEMP;
const caPath = join(temp, 'alpha-cloud-db-ca.pem');
database.searchParams.set('sslmode', 'verify-ca');
database.searchParams.set('uselibpqcompat', 'true');
database.searchParams.set('sslrootcert', caPath);
const databaseUrl = database.href;
const mask = databaseUrl.replaceAll('%', '%25').replaceAll('\r', '%0D').replaceAll('\n', '%0A');
process.stdout.write(`::add-mask::${mask}\n`);
const databaseEnv = source.split(/\r?\n/).filter((line) => !/^\s*DATABASE_URL\s*=/.test(line));
const privateFile = { mode: 0o600 };
writeFileSync(caPath, `${ca}\n`, privateFile);
const cacheBindings = ['INFERENCE_CACHE_URL', 'INFERENCE_CACHE_TOKEN'].map((key) => {
const value = process.env[key];
if (!value || /[\r\n"\\]/.test(value)) reject(`${key} must contain one cache binding value`);
return `${key}="${value}"`;
});
writeFileSync(join(temp, 'alpha-cloud.env'), [source, ...cacheBindings, ''].join('\n'), privateFile);
writeFileSync(join(temp, 'alpha-cloud-db.env'), [...databaseEnv, `DATABASE_URL=${databaseUrl}`, ''].join('\n'), privateFile);
JS
- name: Verify the secrets, never generating one
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud secrets --environment "$E" --env-file "$RUNNER_TEMP/alpha-cloud.env" --frozen
- name: Check the Cloudflare resources
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud preflight --environment "$E" --env-file "$RUNNER_TEMP/alpha-cloud.env"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Migrate the database
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud migrate --environment "$E" --profile "$RUNNER_TEMP/alpha-cloud-profile.json" --env-file "$RUNNER_TEMP/alpha-cloud-db.env"
- name: Register Alpha's native client
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud register --environment "$E" --profile "$RUNNER_TEMP/alpha-cloud-profile.json" --env-file "$RUNNER_TEMP/alpha-cloud-db.env"
- name: Check the payment catalogue
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud prices --environment "$E" --profile "$RUNNER_TEMP/alpha-cloud-profile.json" --env-file "$RUNNER_TEMP/alpha-cloud-db.env"
- name: Deploy the Workers
if: github.event_name == 'push' || inputs.action == 'deploy'
run: pnpm cloud deploy --environment "$E" --profile "$RUNNER_TEMP/alpha-cloud-profile.json" --env-file "$RUNNER_TEMP/alpha-cloud.env" --component "$COMPONENT"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Public readiness
if: github.event_name == 'push' || inputs.action == 'deploy'
timeout-minutes: 25
run: |
for ((attempt = 1; attempt < 8; attempt++)); do
if pnpm cloud smoke --environment "$E"; then
exit 0
fi
sleep 30
done
pnpm cloud smoke --environment "$E"
- name: Remove the private inputs
if: always()
run: rm -f "$RUNNER_TEMP/alpha-cloud.env" "$RUNNER_TEMP/alpha-cloud-profile.json" "$RUNNER_TEMP/alpha-cloud-db.env" "$RUNNER_TEMP/alpha-cloud-db-ca.pem"
production:
needs: staging
if: >-
${{ !cancelled() && github.repository_id == '1396333361' && github.ref == 'refs/heads/main' &&
((github.event_name == 'push' && needs.staging.result == 'success') ||
(github.event_name == 'workflow_dispatch' && inputs.environment == 'production')) }}
runs-on: ubuntu-24.04
timeout-minutes: 90
environment: alpha-cloud-production
env:
E: production
COMPONENT: ${{ github.event_name == 'push' && 'all' || inputs.component }}
steps: *cloud-steps