-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change access-api wrangler.toml to be no_bundle=false. use wran…
…gler bundling (#739) Motivation: * #623 * verify our assumption that we have to use `no_bundle=true` along with d1. Experiment * I wanted to try some new ways of building and whether they would work, but without risking staging, so I used the 'dev' environment from wrangler.toml to try some deploys from local. * I made access-api use of wrangler more like toucan-js@3 [wrangler-basic](https://github.com/robertcepa/toucan-js/blob/master/examples/wrangler-basic/wrangler.toml) * I did a sample deploy from my laptop to 'dev' workers environment, with the sentry/toucan `release` called `bengo-dev-0` [sentry errors here](https://protocol-labs-it.sentry.io/issues/?query=+release%3Abengo-dev-0&referrer=issue-list&statsPeriod=14d) * trigger error via `GET /.debug/error` * expectation: this to lead to an in-route error and show up in sentry with helpful stack traces - because this is what [example](https://github.com/robertcepa/toucan-js/blob/master/examples/wrangler-basic/wrangler.toml) implies should work * trigger error via route that uses d1 binding (e.g. ucanto routes [triggered via w3up+ucanto observable pointing to dev env](https://observablehq.com/d/a76545064f82a998)) * expectation: d1 error - because supposedly `no_bundle=false` (or omitting `no_bundle`) is incompatible with wrangler d1 bindings Findings: * omg it works! * [error triggered by GET /.debug/error (no d1)](https://protocol-labs-it.sentry.io/issues/4078173859/?query=+release%3Abengo-dev-0&referrer=issue-stream&statsPeriod=14d&stream_index=3) * [error triggered by using d1 via access protocol via observable](https://protocol-labs-it.sentry.io/issues/4078175792/?query=is%3Aunresolved+release%3Abengo-dev-0&referrer=issue-stream&statsPeriod=14d&stream_index=2) * The error did not happen in the `access/authorize` handler. That worked fine, and I got an email from dev env. The error happened when I clicked the email (invoking `access/confirm`), when the `access/confirm` invoacation handler tried to write to d1 * It got a D1_ERROR, but I could see from the sentry report > Error: ERROR 9009: SQL prepare error: no such table: delegations_v3 * which makes sense, because `dev` doesn't have latest migrations applied that created that table. So I provisioned a new d1 database for this dev env, and ran `npx wrangler --env=dev d1 migrations apply __D1_BETA__`. This would error every couple migrations, but if I re-ran it it would make progress and error again (`Internal error [code: 7501]`), but eventually it would succeed at all migrations. * then I re-triggered things via the observable, get email, click email. I saw 'email validated'! 🎉 * I continued using the observable to invoke `access/claim` (reads from D1), and got no error all the way through invoking from second device <details><img width="578" alt="Screenshot 2023-04-10 at 5 48 41 PM" src="https://user-images.githubusercontent.com/171782/231026937-25bd396b-8261-4a4e-9c8f-141ef9d2bbf8.png"></details>
- Loading branch information
Showing
8 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.dev.vars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable unicorn/prefer-top-level-await */ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable unicorn/prefer-module */ | ||
/** | ||
* @file | ||
* use this at build time (node.js) to create files that can be | ||
* imported at runtime (maybe workerd). | ||
*/ | ||
import sade from 'sade' | ||
import * as url from 'node:url' | ||
import { getReleaseName } from '../src/utils/release.node.js' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
// @ts-ignore | ||
import git from 'git-rev-sync' | ||
|
||
function __dirname() { | ||
return path.dirname(fileURLToPath(import.meta.url)) | ||
} | ||
|
||
if (import.meta.url.startsWith('file:')) { | ||
const modulePath = url.fileURLToPath(import.meta.url) | ||
if (process.argv[1] === modulePath) { | ||
main().catch((error) => { | ||
throw error | ||
}) | ||
} | ||
} | ||
|
||
async function main(argv = process.argv) { | ||
const cli = sade('access-api-release') | ||
cli | ||
.command('name', '', { default: true }) | ||
.option('--env', 'Environment', process.env.ENV) | ||
.action((opts) => { | ||
const releaseName = getReleaseName(opts.env) | ||
console.log(releaseName) | ||
}) | ||
cli | ||
.command('esm', 'print release info as ES Module string') | ||
.option('--env', 'Environment', process.env.ENV) | ||
.action((opts) => { | ||
const lines = [ | ||
`/** @type {string|undefined} */`, | ||
`export const gitRevShort = '${git.short(__dirname())}'`, | ||
`/** @type {string|undefined} */`, | ||
`export const name = '${getReleaseName(opts.env)}'`, | ||
] | ||
console.log(lines.join('\n')) | ||
}) | ||
cli.parse(argv) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @file | ||
* This file MAY be rewritten during build | ||
* to make some buildtime variables available at runtime. | ||
*/ | ||
/** @type {string|undefined} */ | ||
export const gitRevShort = undefined | ||
/** @type {string|undefined} */ | ||
export const name = undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @file | ||
* utils related to sentry that rely on node. | ||
* These might be used at build time, | ||
* but won't work at run-time in cloudflare workers | ||
*/ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable unicorn/prefer-module */ | ||
|
||
// @ts-ignore | ||
import git from 'git-rev-sync' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { createRequire } from 'node:module' | ||
|
||
const packageJson = createRequire(import.meta.url)('../../package.json') | ||
const __dirname = () => path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
/** | ||
* Create a string to be used for the sentry release value | ||
* | ||
* @param {string} [env] - environment name e.g. 'dev' | ||
* @param {object} pkg - package.json info | ||
* @param {string} pkg.name | ||
* @param {string} pkg.version | ||
* @param {string} gitShort - git-rev-parse short value | ||
* @returns {string} release name e.g. `@web3-storage__access-api@6.0.0-staging+92a89d3` | ||
*/ | ||
export function getReleaseName( | ||
env, | ||
pkg = packageJson, | ||
gitShort = git.short(__dirname()) | ||
) { | ||
const version = `${pkg.name}@${pkg.version}-${env}+${gitShort}`.replace( | ||
'/', | ||
'__' | ||
) | ||
return version | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters