Deploying EdgeDB to DigitalOcean

In this guide we show how to deploy EdgeDB to DigitalOcean either with a One-click Deploy option or a managed PostgreSQL database as the backend.

One-click Deploy

Prerequisites

  • edgedb CLI (install)

  • DigitalOcean account

Click the button below and follow the droplet creation workflow on DigitalOcean to deploy an EdgeDB instance.

DigitalOcean - 图1

By default, the admin password is edgedbpassword; let’s change that to something more secure. First, find your droplet’s IP address on the DigitalOcean dashboard and assign it to an environment variable IP.

  1. $
  1. IP=<your-droplet-ip>

Then use the read command to securely assign a value to the PASSWORD environment variable.

  1. $
  1. echo -n "> " && read -s PASSWORD

Use these variables to change the password for the default role edgedb.

  1. $
  1. printf edgedbpassword | edgedb query \
  2. --host $IP \
  3. --password-from-stdin \
  4. --tls-security insecure \
  5. "alter role edgedb set password := '${PASSWORD}'"
  1. OK: ALTER ROLE

You can now link and connect to the new EdgeDB instance:

  1. $
  1. printf $PASSWORD | edgedb instance link \
  2. --password-from-stdin \
  3. --trust-tls-cert \
  4. --host $IP \
  5. --non-interactive \
  6. digitalocean
  1. Authenticating to edgedb://edgedb@your-droplet-ip:5656/edgedb
  2. Trusting unknown server certificate
  3. Successfully linked to remote instance. To connect run:
  4. edgedb -I digitalocean

You can now use the EdgeDB instance deployed on DigitalOcean as digitalocean, for example:

  1. $
  1. edgedb -I digitalocean
  1. edgedb>

Deploy with Managed PostgreSQL

Prerequisites

Create a managed PostgreSQL instance

If you already have a PostgreSQL instance you can skip this step.

  1. $
  1. DSN="$( \
  2. doctl databases create edgedb-postgres \
  3. --engine pg \
  4. --version 13 \
  5. --size db-s-1vcpu-1gb \
  6. --num-nodes 1 \
  7. --region sfo3 \
  8. --output json \
  9. | jq -r '.[0].connection.uri' )"

Provision a droplet

Replace $SSH_KEY_IDS with the ids for the ssh keys you want to ssh into the new droplet with. Separate multiple values with a comma. You can list your keys with doctl compute ssh-key list. If you don’t have any ssh keys in your DigitalOcean account you can follow this guide to add one now.

  1. $
  1. IP="$( \
  2. doctl compute droplet create edgedb \
  3. --image edgedb \
  4. --region sfo3 \
  5. --size s-2vcpu-4gb \
  6. --ssh-keys $SSH_KEY_IDS \
  7. --format PublicIPv4 \
  8. --no-header \
  9. --wait )"

Configure the backend postgres DSN. To simplify the initial deployment, let’s instruct EdgeDB to run in insecure mode (with password authentication off and an autogenerated TLS certificate). We will secure the instance once things are up and running.

  1. $
  1. printf "EDGEDB_SERVER_BACKEND_DSN=${DSN} \
  2. \nEDGEDB_SERVER_SECURITY=insecure_dev_mode\n" \
  3. | ssh root@$IP -T "cat > /etc/edgedb/env"
  1. $
  1. ssh root@$IP "systemctl restart edgedb.service"

Set the superuser password.

  1. $
  1. echo -n "> " && read -s PASSWORD
  1. $
  1. edgedb -H $IP --tls-security insecure query \
  2. "alter role edgedb set password := '$PASSWORD'"
  1. OK: ALTER ROLE

Set the security policy to strict.

  1. $
  1. printf "EDGEDB_SERVER_BACKEND_DSN=${DSN} \
  2. \nEDGEDB_SERVER_SECURITY=strict\n" \
  3. | ssh root@$IP -T "cat > /etc/edgedb/env"
  1. $
  1. ssh root@$IP "systemctl restart edgedb.service"

That’s it! You can now start using the EdgeDB instance located at edgedb://$IP.

To access the EdgeDB instance you’ve just provisioned on DigitalOcean from your local machine run the following command.

  1. $
  1. printf $PASSWORD | edgedb instance link \
  2. --password-from-stdin \
  3. --trust-tls-cert \
  4. --host $IP \
  5. --non-interactive \
  6. digitalocean
  1. Authenticating to edgedb://edgedb@137.184.227.94:5656/edgedb
  2. Trusting unknown server certificate:
  3. SHA1:1880da9527be464e2cad3bdb20dfc430a6af5727
  4. Successfully linked to remote instance. To connect run:
  5. edgedb -I digitalocean

You can now use the EdgeDB instance deployed on DigitalOcean as digitalocean, for example:

  1. $
  1. edgedb -I digitalocean
  1. edgedb>

Upgrading EdgeDB

To upgrade an existing EdgeDB droplet to the latest point release, ssh into your droplet and run the following.

  1. $
  1. apt-get update && apt-get install --only-upgrade edgedb-server-2
  1. $
  1. systemctl restart edgedb