Django Blueprint

What are DigitalOcean Blueprints?

DigitalOcean Blueprints are pre-configured infrastructure stacks with ready-to-use applications and they’re deployed with only a few clicks. With DigitalOcean Blueprints you’ll be able to skip complicated deployment configurations and infrastructure setups. You’ll be able to deploy easily and begin using your applications right away!

DigitalOcean Blueprints are designed to be the starting point for your production-ready infrastructure. They aim to make deployment as seamless as possible so you can access the value of the application quickly. Each Blueprint has its own infrastructure configuration, cost, and software deployments. Please refer to the documentation for more details on each of these components.

What is this Blueprint?

The Django Blueprint will deploy 3 Django Droplet 1-Clicks, 1 load balancer, and 1 PostgreSQL database.

Each Droplet deployed contains:

  • 4 vCPUs
  • 8GB RAM
  • 160GB SSD Disk

The database is a 30GB PostgreSQL 12 with 2 GB RAM and 1 vCPU.

The load balancer is a single-node with up to 10000 simultaneous connections.

The approximate cost of this deployment is $186 monthly.

How to use DigitalOcean Blueprints?

Install Terraform

Head to the Terraform install page and follow the instructions for your platform.

You can validate your local Terraform installation by running:

$ terraform -v
Terraform v1.5.7
...

Create a DigitalOcean API token

Head to the Applications & API page and create a new personal access token (PAT) by clicking the Generate New Token button. Make sure to check the Write scope for the token, as Terraform needs it to create new resources. After creating the token, make sure to save it as it disappears forever if you close the page. If you lost the token, delete it and create a new one.

Set up a blueprint and variables

Clone this repository to the machine where Terraform is installed:

$ git clone https://github.com/digitalocean/marketplace-blueprints.git

Head to the blueprint you are interested in, for this example we will use Django:

$ cd blueprints/django/

Edit variables.tf file and specify your API token like this:

variable “do_token” {
  default = “dop_v1_your_beautiful_token_here”
}

Optionally, if you want to initialize Django Droplets with your Django application, you can specify the link to your project:

variable "project_url" {
  default = "https://github.com/your_amazing_django_project"
}

Also optionally, if you want to connect to your Django Droplets using SSH, use doctl to retrieve your SSH key IDs:

$ doctl compute ssh-key list

Paste the keys IDs from the doctl in variable.tf:

variable "ssh_key_ids" {
  default = [123, 112233] // <--- HERE
  type = list(number)
}

We are almost there, now initialize the Terraform project by running:

$ terraform init

Finally, after the project is initialized, run the Terraform apply to spin the blueprint:

$ terraform apply

It can take a few minutes to spin the droplets and some blueprints require extra time after the creation to finish the configuration.

Software Included

Package Version License
Django 5 Custom
Nginx 1.18.0 Custom
Certbot 0.40.0 Apache 2
Gunicorn 20.0.4 MIT
Postgres 12 Postgres SQL
Postfix 3.4.10 IBM Public

Getting Started After Deploying Django Blueprint

After the stack is deployed, give it 5-6 minutes to finish the configuration.

After this, you can access your via load balancer IP: http://<load-balancer-ip>.

Keep in mind that unless specified in the variables.tf, Django Blueprint will not contain a sample project and requests may time out.

After making any change inside Django Droplet 1-Click, don’t forget to reload Gunicorn:

$ systemctl daemon-reload
$ systemctl restart gunicorn

Stack Details

  • Gunicorn system service is enabled systemctl status gunicorn.
  • The Django application is automatically configured if specified.
  • The Django application is served from /home/django/django_project.
  • Certbot preinstalled for easy HTTPS setup.