# DigitalOcean App Platform

Run Charter as a container on DigitalOcean App Platform with a managed Postgres database.

You may deploy Charter as a container on DigitalOcean App Platform with a managed Postgres database. App Platform terminates Transport Layer Security (TLS) in front of your service, so leave Charter's TLS flags unset and let `charter serve` listen in plain Hypertext Transfer Protocol (HTTP) on the port the platform forwards to.

## What you need

- A DigitalOcean account with permission to create App Platform apps and Managed Databases
- The published Charter container image (`ghcr.io/snaapi/charter:<version>` from [Install](/docs/install/)). App Platform only runs Linux AMD64 images
- A Postgres cluster in the same region as the app (managed database for production)
- Values for `COOKIE_SIGNING_KEY` and, later, a public URL for `CHARTER_BASE_URL`

For a Virtual Private Server (VPS) where Charter terminates TLS itself, see [Install on Ubuntu](/docs/install-on-ubuntu/) and [Mutual TLS with Cloudflare](/docs/mutual-tls-cloudflare/).

DigitalOcean documents [deploying from container images](https://docs.digitalocean.com/products/app-platform/how-to/deploy-from-container-images/) and [managed databases in App Platform](https://docs.digitalocean.com/products/app-platform/how-to/manage-databases/).

## Create a managed Postgres database

- In the DigitalOcean Control Panel, create a Managed Database cluster with the PostgreSQL engine
- Pick the same datacenter region you will use for the app
- Keep trusted sources enabled. You will add the App Platform app (and temporarily your laptop) in the steps below

Copy the connection string from the cluster Overview when you need it for local admin work. Default connection details use `sslmode=require`. See [DigitalOcean's Postgres connection guide](https://docs.digitalocean.com/products/databases/postgresql/how-to/connect/). Charter's Postgres version floor and role privileges: [Requirements](/docs/requirements/).

> [!INFO]
> App Platform also offers a small **dev database** inside the app. Prefer a managed cluster when the data needs backups, scaling, or a longer lifetime.

## Deploy the Charter image

- Create → App Platform, then choose **Container image**
- Select GitHub Container Registry (or copy the image into DigitalOcean Container Registry first)
- Repository `snaapi/charter`, tag matching the version on [Install](/docs/install/)
- If the registry asks for credentials, use a GitHub username and a personal access token that can pull the package, in the form `username:token`
- Resource type: **Web Service**
- Set the public HTTP port to `3000`. That matches Charter's default (`CHARTER_PORT` / `--port`). App Platform's default is `8080`; if you leave it at `8080`, set `CHARTER_PORT=8080` instead so the process listens where the platform expects
- Leave the run command empty so the image entrypoint runs `serve`
- Choose the same region as the database, then create the app

Charter binds `0.0.0.0` by default for `serve`, which App Platform requires.

## Attach the managed database

- On the app, use **Add components** → **Create or attach database**
- Attach the managed Postgres cluster. When trusted sources are on, add the app as a trusted source (the attach flow can do this for you)
- Give the database component a short name, such as `db`. Bindable variable prefixes are limited to 32 characters

Set Charter's connection URL on the web service (or at the app level):

- `DATABASE_URL` = `${db.DATABASE_URL}` (replace `db` with your database component name; mark the variable encrypted if the UI offers it)

`${db.DATABASE_URL}` is a bindable variable App Platform fills at runtime. Prefer `${db.DATABASE_PRIVATE_URL}` when the app and database share a Virtual Private Cloud (VPC); that keeps traffic on the private network. See [bindable variables](https://docs.digitalocean.com/products/app-platform/how-to/use-environment-variables/).

Do not point a build step at the database. Charter's published image does not need the database at build time, and App Platform cannot use trusted sources during builds. See [DigitalOcean's note on build-time database access](https://docs.digitalocean.com/support/why-does-my-app-fail-to-build-while-trying-to-connect-to-a-digitalocean-managed-database/).

## Set runtime environment variables

Add these on the web service (encrypt secrets):

- `APP_ENV` = `production` (production cookie and `charter dev` rules)
- `COOKIE_SIGNING_KEY` = output of `openssl rand -base64 64` (required off loopback; generate once and keep it)
- `CHARTER_BASE_URL` = `${APP_URL}` (public origin for OAuth redirects and trusted origin checks). After you add a custom domain, set this to that `https://…` URL instead
- `DATABASE_URL` = `${db.DATABASE_URL}` (same bindable value as above)
- `CHARTER_SETUP_TOKEN` = output of `openssl rand -base64 32` (encrypt it). This is how you create the first operator. At least 32 characters. See below

Optional but useful:

- `CHARTER_API_NAME` for the docs page title
- `CHARTER_MCP_ROLE` so MCP read tools have a role (unset means those tools refuse reads)
- `DATABASE_MAX_CONNECTIONS` if you size the pool against the cluster's connection limit

Full list: [Environment variables](/docs/environment-variables/).

Redeploy after saving so the new values reach the container.

## Health checks

Charter serves `GET /healthz` on the API listener without authentication. Point App Platform's HTTP health check at `/healthz` on the same port as the public HTTP port (`3000` if you followed the steps above). See [App Platform health checks](https://docs.digitalocean.com/products/app-platform/how-to/manage-health-checks/).

You do not need `--health-addr` here. That second plaintext listener is for deployments where the API port speaks TLS, such as [Mutual TLS with Cloudflare](/docs/mutual-tls-cloudflare/).

## Create the first operator

`charter serve` applies Charter's own schema on startup. It does not create an operator. The published image has no shell, so the first operator is created in the browser.

After the app is healthy, open the app URL from the Overview page and add `/setup` to the end. Enter `CHARTER_SETUP_TOKEN`, your name, and your email. Charter shows an API key once. Copy it then. The page stores only a hash of the key, and that setup secret will not work a second time, even if the variable is still set.

Send the key on later requests as `Authorization: Bearer` followed by the key. This operator has no password, so the console sign-in page will not accept the account.

> [!WARNING]
> Changing `CHARTER_SETUP_TOKEN` after a successful setup does not open `/setup` again.

Use `charter serve` in production, not `charter dev`. `charter dev` refuses `APP_ENV=production` and ignores `CHARTER_SETUP_TOKEN`.

## Apply config

Resource definitions still come from `charter import config`. Run that from a machine that has Charter installed and can reach the database, not from App Platform's console. Adding another operator (including one with a password) is the same path: `charter admin create`.

- On the managed database, add your laptop's public IP to trusted sources (Network Access)
- Copy the cluster's connection string (with `sslmode=require`) into a local `DATABASE_URL`
- From your project directory, run the command below
- Remove your laptop from trusted sources when you are done, unless you still need direct access

```sh
export DATABASE_URL='postgresql://…?sslmode=require'
charter import config --path charter.toml --apply
```

## Check it

After a successful deploy, open the app URL from the Overview page:

```sh
curl -sS "$CHARTER_BASE_URL/healthz"
curl -sS "$CHARTER_BASE_URL/openapi.json" | head
```

`/healthz` should return `200` with body `ok`. If the deploy fails the health check, confirm the public HTTP port matches `CHARTER_PORT` (default `3000`) and that `DATABASE_URL` resolves inside the running container.

## Example app spec

You can express the same layout in an app spec and apply it with `doctl` or the Control Panel. Replace the image tag, region, cluster name, and secret values:

```yaml
name: charter
region: nyc
services:
  - name: api
    http_port: 3000
    instance_count: 1
    instance_size_slug: apps-s-1vcpu-0.5gb
    image:
      registry_type: GHCR
      registry: snaapi
      repository: charter
      tag: "REPLACE_WITH_CHARTER_VERSION"
    health_check:
      http_path: /healthz
      initial_delay_seconds: 15
    envs:
      - key: DATABASE_URL
        scope: RUN_TIME
        value: ${db.DATABASE_URL}
      - key: APP_ENV
        scope: RUN_TIME
        value: production
      - key: COOKIE_SIGNING_KEY
        type: SECRET
        scope: RUN_TIME
        value: REPLACE_WITH_OPENSSL_RAND_BASE64_64
      - key: CHARTER_BASE_URL
        scope: RUN_TIME
        value: ${APP_URL}
      - key: CHARTER_SETUP_TOKEN
        type: SECRET
        scope: RUN_TIME
        value: REPLACE_WITH_OPENSSL_RAND_BASE64_32
databases:
  - name: db
    engine: PG
    production: true
    cluster_name: REPLACE_WITH_CLUSTER_NAME
    db_name: defaultdb
    db_user: doadmin
```

Field reference: [App Platform app spec](https://docs.digitalocean.com/products/app-platform/reference/app-spec/).
