-
-
Notifications
You must be signed in to change notification settings - Fork 22
Production Deployment
We are using a Digital Ocean managed instance of PostgreSQL. We have created the following database type.
- Memory: 1 GB RAM
- Compute: 1vCPU
- Disk: 10 GB
- Failover: Primary only
- Region: SFO2
- DB: PostgreSQL 11
A user has been created for the CodeBuddies Backend application: cb_app
.
To create the Digital Ocean host use the following command. You will need to authenticate using a personal access token.
doctl auth init --context=cb
doctl --context=cb compute droplet create api --enable-backups --enable-monitoring --image=docker-18-04 --region=sfo2 --size=s-1vcpu-1gb --ssh-keys=26664376 --tag-names=v3
Our Django application is packaged as a Docker image. It is deployed as a service using Docker Compose. It listens on port 8000 on the container network. This port is not exposed outside the container network as all inbound requests come from the web server. No volumes are mounted as all code and dependencies are contained within the image.
The table below outlines the environment variables that need to be set:
Environment Variable | Value | Description |
---|---|---|
DATABASE_URL |
URL of the PostgreSQL database including username and password | |
EMAIL_HOST |
Hostname of the mail server for outbound email |
Our web server acts as a reverse proxy in front of the Django application. We are using Nginx as the web server. it is deployed as a service using Docker Compose and exposes port 80 on the host network. All requests are forwarded to the Django application on port 8000.
Domains and DNS are handled by Digital Ocean. Records were created as shown below. The IP address used is the address of the droplet hosting the Django application.
- api.codebuddies.org
- api-staging.codebuddies.org
doctl --context=cb compute domain records create codebuddies.org --record-name=api --record-data=165.227.21.195 --record-type=A
doctl --context=cb compute domain records create codebuddies.org --record-name=api-staging --record-data=165.227.21.195 --record-type=A