diff --git a/self-hosted/SELFHOSTING.md b/self-hosted/SELFHOSTING.md index 8e0ac2e4..4f2ec02e 100644 --- a/self-hosted/SELFHOSTING.md +++ b/self-hosted/SELFHOSTING.md @@ -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. @@ -66,6 +66,13 @@ npx convex run npx convex import ``` +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. @@ -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='' +``` -# 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 ``` diff --git a/self-hosted/docker-compose.yml b/self-hosted/docker-compose.yml index f4bc90e8..f2bea47e 100644 --- a/self-hosted/docker-compose.yml +++ b/self-hosted/docker-compose.yml @@ -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