Skip to content

Commit

Permalink
Update self hosting docs to include running docker w/postgres (#34122)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 147be320be8499e9466d3220431b9fb5b50ef152
  • Loading branch information
emmaling27 authored and Convex, Inc. committed Feb 6, 2025
1 parent f900492 commit fede130
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
37 changes: 31 additions & 6 deletions self-hosted/SELFHOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Development of the Convex backend is led by the Convex team. We
[love receiving feedback](https://discord.gg/convex). We keep this repository
synced with any internal development work within a handful of days.

# Self Hosting Via Docker [recommended]
# Self Hosting Via Docker

You'll need to have [Docker](https://docs.docker.com/desktop/) installed to run
convex in Docker.
Expand Down Expand Up @@ -66,6 +66,13 @@ npx convex run <run args>
npx convex import <import args>
```

By default, the backend will store its data in a volume managed by Docker. Note
that you'll need to set up persistent storage on whatever cloud hosting platform
you choose to run the Docker container on (e.g. AWS EBS). The default database
is SQLite, but for production workloads, we recommend running Convex backed by
Postgres. Follow [these instructions](#self-hosting-on-postgres-with-neon) to
connect to Postgres.

# Self Hosting with [Fly.io](https://fly.io/)

From the self-hosted directory, deploy the backend.
Expand Down Expand Up @@ -120,22 +127,40 @@ example:
- And you have an HTTP action named `sendEmail`
- You would call it at `https://self-hosted-backend.fly.dev/http/sendEmail`

## Connecting to [Neon Postgres](https://neon.tech)
# Self Hosting on Postgres with [Neon](https://neon.tech)

Create a project on Neon. Copy the connection string from the Neon dashboard.

```sh
export DATABASE_CONNECTION='<connection string>'
```

# Create the database
Create the database

```sh
psql $DATABASE_CONNECTION -c "CREATE DATABASE convex_self_hosted"
```

Strip database name and query params from the connection string. It should end
in neon.tech

# Strip database name and query params from the connection string. It should end in neon.tech
```sh
export DATABASE_URL=$(echo $DATABASE_CONNECTION | sed -E 's/\/[^/]+(\?.*)?$//')
```

Update your `DATABASE_URL` environment variable. If you're deploying on
[Fly](https://fly.io):

```sh
fly secrets set DATABASE_URL=$DATABASE_URL
```

After you've deployed with the environment variable set, check that the database
is connected to your self-hosted convex backend. There should be a line like
"Connected to Postgres" in the logs. If you're deploying on
[Fly](https://fly.io):

# Check that the database is connected to your self-hosted convex backend.
# There should be a line like "Connected to Postgres" in the logs.
```sh
fly logs
```

Expand Down
1 change: 1 addition & 0 deletions self-hosted/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- ACTIONS_USER_TIMEOUT_SECS=${ACTIONS_USER_TIMEOUT_SECS:-}
- CONVEX_CLOUD_ORIGIN=${URL_BASE:-http://127.0.0.1}:${PORT:-3210}
- CONVEX_SITE_ORIGIN=${URL_BASE:-http://127.0.0.1}:${SITE_PROXY_PORT:-3211}
- DATABASE_URL=${DATABASE_URL:-}
container_name: convex-local-backend
healthcheck:
test: curl -f http://localhost:3210/version
Expand Down

0 comments on commit fede130

Please sign in to comment.