Skip to content

About

Example: an app deployed by Alchemy v2 that keeps its Alchemy state on a branch of its own GitHub repository

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alchemy state on a GitHub branch

An example app that Alchemy v2 deploys, with its Alchemy state in this repository, on the branch alchemy-state-store. The state needs no bucket, no database, and no extra account: the repository and the GITHUB_TOKEN of the run are enough.

Live site · The state · The deploys · The store's package

The whole setup

One line in alchemy.run.ts gives the stack its state store (shortened here):

import * as GitHubState from "@samebase/alchemy-kit/github-state";

export default Alchemy.Stack(
  repository,
  {
    providers: Convex.providers(),
    state: Convex.withRunRecord(GitHubState.state()),
  },
  program,
);

withRunRecord adds the commit and the run to each stage output. The store works without it.

The workflow alchemy.yml gives each run two things:

  • permissions: contents: write, so the run writes the branch with its own GITHUB_TOKEN.
  • The repository secret ALCHEMY_GITHUB_STATE_KEY, which seals each secret in the state.

The first deploy made the two branches. The quick start has the same steps for your repository.

Where to look

  • The state is one JSON file for each resource, {stack}/{stage}/{resource}.json. prod/IdentityHubClient.json is plain JSON, and its client secret is sealed with AES-256-GCM.
  • Each write is a commit that names what it changed, such as samebase/cloudflare-state-test prod: set Site.
  • The lock of each stage is on the branch alchemy-state-store-lock. A second deploy of the same stage fails at once.
  • The stages. A push to main deploys the stage prod. Each pull request deploys the stage pr-<number>, and closing it removes the preview and its state.
  • A preview and production deploy at the same time. A preview reads the Convex project from the state of prod (Convex.Project.ref("Project", { stage: "prod" })). That read takes no lock, so each deploy holds only the lock of its own stage.

How the store works

  • It is Alchemy's own makeBucketState (alchemy/State/BucketState) with a Git branch as the bucket, read and written through GitHub's Git database API.
  • All the writes that are waiting go into one commit. When another deploy moved the branch first, the store reads the new head and tries again.
  • The lock is a lease file. A deploy renews it while it runs, and it ends after 60 seconds if the deploy stops without a release.
  • The sealing of secrets is the package's own until Alchemy releases state encryption (alchemy-run/alchemy#3167).

The package's README has the limits, and GitHubState.ts is the source.

The app

The app is the samebase/base starter: a public todo list on Convex, with Google sign-in on every pull request preview. Its README has the app, the sign-in, and local development.

One thing differs here: a local alchemy run needs GITHUB_TOKEN and ALCHEMY_GITHUB_STATE_KEY in its environment. See From your laptop.

  • How deploys work: the stages, the state, and local alchemy deploy.
  • Google sign-in: the hub, /samebase-verification.json, apps on other hosts, the hub's terms, and how to run your own hub.
  • Files: where things are, and which files are generated.

License

MIT. Copy it, change it, ship it; keep the copyright line. See THIRD_PARTY_NOTICES.md for included third-party material.

About

Example: an app deployed by Alchemy v2 that keeps its Alchemy state on a branch of its own GitHub repository

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

Generated from samebase/base