Skip to content

Commit 887001c

Browse files
First draft of PostgreSQL deployment instructions
1 parent 373b829 commit 887001c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/deployment.qmd

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,69 @@ There are *many* hosting options available for each of these services; this guid
1313

1414
### On Digital Ocean
1515

16+
#### Getting Started
17+
18+
- Create a [DigitalOcean](mdc:https:/www.digitalocean.com) account
19+
- Install the [`doctl` CLI tool](mdc:https:/docs.digitalocean.com/reference/doctl) and authenticate with `doctl auth init`
20+
- Install the [`psql` client](mdc:https:/www.postgresql.org/download)
21+
22+
#### Create a Project
23+
24+
Create a new project to organize your resources:
25+
26+
```bash
27+
# List existing projects
28+
doctl projects list
29+
30+
# Create a new project
31+
doctl projects create --name "YOUR-PROJECT-NAME" --purpose "YOUR-PROJECT-PURPOSE" --environment "Production"
32+
```
33+
34+
Take note of the Project ID in the output for later use.
35+
36+
#### Set Up a Managed PostgreSQL Database
37+
38+
Create a managed, serverless PostgreSQL database instance:
39+
40+
```bash
41+
doctl databases create your-db-name --engine pg --version 17 --size db-s-1vcpu-1gb --num-nodes 1 --wait
42+
```
43+
44+
Get the database ID from the output of the create command and use it to retrieve the database connection details:
45+
46+
```bash
47+
# Get the database ID from the output of the create command
48+
DATABASE_ID="your-database-id"
49+
50+
# Get connection details
51+
doctl databases connection $DATABASE_ID --format Host,Port,User,Password,Database
52+
```
53+
54+
Store these details securely in a `.env.production` file (you will need to set them later in application deployment as production secrets):
55+
56+
```bash
57+
# Database connection parameters
58+
DB_HOST=your-host
59+
DB_PORT=your-port
60+
DB_USER=your-user
61+
DB_PASS=your-password
62+
DB_NAME=your-database
63+
```
64+
65+
You may also want to save your database id, although you can always find it again later by listing your databases with `doctl databases list`.
66+
67+
#### Setting Up a Firewall Rule (after Deploying Your Application Layer)
68+
69+
Note that by default your database is publicly accessible from the Internet, so you should create a firewall rule to restrict access to only your application's IP address once you have deployed the application. The command to do this is:
70+
71+
```bash
72+
doctl databases firewalls append <database-cluster-id> --rule <type>:<value>
73+
```
74+
75+
where `<type>` is `ip_addr` and `<value>` is the IP address of the application server. See the [DigitalOcean documentation](https://docs.digitalocean.com/reference/doctl/reference/databases/firewalls/append/) for more details.
76+
77+
**Note:** You can only complete this step after you have deployed your application layer and obtained the IP address of the application server.
78+
1679
## Deploying and Configuring the FastAPI App
1780

1881
### On Modal.com

0 commit comments

Comments
 (0)