Fixup staging worker deploys (#4050)

- Structure wrangler.toml for asset uploads the same way we structure it
for other workers
- Extract worker name from wrangler output, not wrangler.toml - not all
workers have explicit names for all environments
- Remove DNS settings for preview workers - `tldraw.workers.dev` is fine

### Change type

- [x] `bugfix`
This commit is contained in:
alex 2024-07-01 15:32:14 +01:00 committed by GitHub
parent 13ceb909a0
commit 3e8f497b78
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 45 deletions

View file

@ -1,52 +1,65 @@
name = "tldraw-assets"
main = "src/index.ts" main = "src/index.ts"
compatibility_date = "2022-09-22" compatibility_date = "2022-09-22"
[dev] [dev]
port = 8788 port = 8788
[[r2_buckets]] [[analytics_engine_datasets]]
binding = 'UPLOADS'
bucket_name = 'uploads'
preview_bucket_name = 'uploads-preview'
[[analytics_engine_datasets]]
binding = "MEASURE" binding = "MEASURE"
# staging settings #################### Environment names ####################
# dev should never actually get deployed anywhere
[env.dev]
name = 'tldraw-assets-dev'
# we don't have a hard-coded name for preview. we instead have to generate it at build time and append it to this file.
# staging is the same as a preview on main:
[env.staging] [env.staging]
name = "main-tldraw-assets" name = "main-tldraw-assets"
[[env.staging.r2_buckets]] # production gets the proper name
binding = 'UPLOADS'
bucket_name = 'uploads'
preview_bucket_name = 'uploads-preview'
[[env.staging.analytics_engine_datasets]]
binding = "MEASURE"
# production settings
[env.production] [env.production]
name = "tldraw-assets" name = "tldraw-assets"
#################### Assets R2 bucket ####################
# in dev, we write to the preview bucket and need a `preview_bucket_name`
[[env.dev.r2_buckets]]
binding = 'UPLOADS'
bucket_name = 'uploads-preview'
preview_bucket_name = 'uploads-preview'
# in preview and staging we write to the preview bucket
[[env.preview.r2_buckets]]
binding = 'UPLOADS'
bucket_name = 'uploads-preview'
[[env.stating.r2_buckets]]
binding = 'UPLOADS'
bucket_name = 'uploads-preview'
# in production, we write to the main bucket
[[env.production.r2_buckets]]
binding = "ROOMS"
bucket_name = "uploads"
#################### Analytics engine ####################
# analytics engine has the same configuration in all environments:
[[env.dev.analytics_engine_datasets]]
binding = "MEASURE"
[[env.preview.analytics_engine_datasets]]
binding = "MEASURE"
[[env.staging.analytics_engine_datasets]]
binding = "MEASURE"
[[env.production.analytics_engine_datasets]]
binding = "MEASURE"
#################### Routes ####################
# in production, we use a custom domain. others get a default *.tldraw.workers.dev domain
[[env.production.routes]] [[env.production.routes]]
pattern = 'assets.tldraw.xyz' pattern = 'assets.tldraw.xyz'
custom_domain = true custom_domain = true
zone_name = 'tldraw.xyz' zone_name = 'tldraw.xyz'
[[env.production.r2_buckets]]
binding = 'UPLOADS'
bucket_name = 'uploads'
preview_bucket_name = 'uploads-preview'
[[env.production.analytics_engine_datasets]]
binding = "MEASURE"
[[env.preview.r2_buckets]]
binding = 'UPLOADS'
bucket_name = 'uploads'
preview_bucket_name = 'uploads-preview'
[[env.preview.analytics_engine_datasets]]
binding = "MEASURE"

View file

@ -1,3 +1,2 @@
name = "health-worker"
main = "src/index.ts" main = "src/index.ts"
compatibility_date = "2023-12-18" compatibility_date = "2023-12-18"

View file

@ -1,9 +1,7 @@
import * as github from '@actions/github' import * as github from '@actions/github'
import { readFileSync } from 'fs'
import { appendFile } from 'fs/promises' import { appendFile } from 'fs/promises'
import { join } from 'path' import { join } from 'path'
import { env } from 'process' import { env } from 'process'
import toml from 'toml'
import { exec } from './exec' import { exec } from './exec'
export function getDeployInfo() { export function getDeployInfo() {
@ -125,16 +123,14 @@ export async function wranglerDeploy({
throw new Error('Could not find the deploy ID in wrangler output') throw new Error('Could not find the deploy ID in wrangler output')
} }
const workerName = toml.parse(readFileSync(join(location, 'wrangler.toml')).toString())?.env?.[ const workerNameMatch = out.match(/Uploaded ([^ ]+)/)
env
]?.name
if (!workerName) { if (!workerNameMatch) {
throw new Error('Could not find the worker name in wrangler output') throw new Error('Could not find the worker name in wrangler output')
} }
if (sentry) { if (sentry) {
const release = sentry.release ?? `${workerName}.${versionMatch[1]}` const release = sentry.release ?? `${workerNameMatch[1]}.${versionMatch[1]}`
const sentryEnv = { const sentryEnv = {
SENTRY_AUTH_TOKEN: sentry.authToken, SENTRY_AUTH_TOKEN: sentry.authToken,
@ -143,13 +139,13 @@ export async function wranglerDeploy({
} }
// create a sentry release: // create a sentry release:
exec('yarn', ['run', '-T', 'sentry-cli', 'releases', 'new', release], { await exec('yarn', ['run', '-T', 'sentry-cli', 'releases', 'new', release], {
pwd: location, pwd: location,
env: sentryEnv, env: sentryEnv,
}) })
// upload sourcemaps to the release: // upload sourcemaps to the release:
exec( await exec(
'yarn', 'yarn',
[ [
'run', 'run',