App Platform
App Platform runs your containers for you. You give it an image and it runs it as a service: HTTPS on an *.ondigitalocean.app address, a load balancer in front, and as many instances as you ask for. It pulls images from your team’s Container Registry, and redeploys with no downtime when the image changes.
An Alchemy App is your program and its App Platform configuration in one class. Deploy bundles the program into an image, pushes it to the registry, and updates the App.
- api
- a1b2c3 · d4e5f6
Write an App
Section titled “Write an App”import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";
export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url, region: "nyc" }, Effect.gen(function* () { return { fetch: Effect.succeed(HttpServerResponse.text("hello from App Platform")), }; }),) {}Yield it in the Stack; api.url is its HTTPS address. Deploy needs Docker on the machine running it, to build the image.
Use the Container Registry
Section titled “Use the Container Registry”App Platform pulls images from the team’s registry, and a team has exactly one. Declare it and pass it to the App, or leave registry out to use the registry the team already has:
import * as DigitalOcean from "@alchemy.run/digitalocean";
export const Registry = DigitalOcean.Registry("Registry", { tier: "starter" });{ main: import.meta.url, region: "nyc", registry: Registry }The free starter tier holds one repository, so it fits one App. Each App pushes to its own repository; use basic or professional for more.
Size and scale it
Section titled “Size and scale it”{ main: import.meta.url, region: "nyc", instanceSizeSlug: "apps-d-1vcpu-1gb", instanceCount: 3, healthCheckPath: "/health",}instanceSizeSlug sets each instance’s CPU and memory; apps-s-* sizes share a CPU and apps-d-* sizes have their own. App Platform routes traffic only to instances whose healthCheckPath answers 2xx.
Run a scheduled job
Section titled “Run a scheduled job”A job runs the App’s image on a cron schedule. Declare it next to the handler with DigitalOcean.cron, and provide CronLive:
import * as DigitalOcean from "@alchemy.run/digitalocean";import * as Effect from "effect/Effect";import * as HttpServerResponse from "effect/http/HttpServerResponse";
export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url, region: "nyc" }, Effect.gen(function* () { yield* DigitalOcean.cron("0 3 * * *", () => Effect.log("nightly report"), { timeZone: "UTC", }); return { fetch: Effect.succeed(HttpServerResponse.text("ok")) }; }).pipe(Effect.provide(DigitalOcean.CronLive)),) {}The job has the App’s bindings, so it reads and writes the same resources as the handler.
Pass configuration and secrets
Section titled “Pass configuration and secrets”Read configuration with Config during construction. The value travels from your deploy to the App, and a Config.Redacted value becomes an App Platform secret, encrypted and hidden in the control panel:
const apiKey = yield* Config.Redacted("STRIPE_KEY");See Secrets.
Alert on failures
Section titled “Alert on failures”{ main: import.meta.url, alerts: [ { rule: "DEPLOYMENT_FAILED", emails: ["ops@example.com"] }, { rule: "CPU_UTILIZATION", operator: "GREATER_THAN", value: 80, window: "FIVE_MINUTES" }, ],}Alert emails must belong to members of the team. slackWebhooks sends to Slack instead.
Run an async handler or an image
Section titled “Run an async handler or an image”Any module that exports fetch(request, env) runs as an App with isExternal: true:
export default { async fetch(request: Request) { return new Response("hello"); },};const hello = yield* DigitalOcean.App("Hello", { main: "./src/hello.ts", isExternal: true });context and dockerfile build your own Dockerfile instead, and image: "nginx:1.27" mirrors a public image into the registry and runs it.
Limits
Section titled “Limits”- Deploys take two to ten minutes: App Platform pulls the image and starts new instances before it stops the old ones.
- An App runs in one region. App Platform names regions by city:
nyc,ams,fra,sfo,sgp,lon,tor,blr,syd,atl. - The team’s Container Registry is shared by every App and stage on the team. Destroying an App deletes its repository, not the registry.
See Websites to serve a framework app on App Platform.