Skip to main content

Django + Postgres

Note: if you're looking for a simpler Django deployment option, consider the Django + SQLite guide.

Pre-requisites

Set up

  • If you haven't yet connected your GitHub account with your disco installation, run:
disco github:apps:add

You only need to do this once.

Steps

  • Create an CNAME record for your project and point it to your disco server's address
    • let's say that your disco server's address is disco.example.com
    • create a CNAME for your project such as blog.example.com (the "from") and point it to the server's disco.example.com address (the "to")
  • Fork the example repo
  • Add the project to your server by running the command below:
disco projects:add \
--name my-django-site \
--github USERNAME/REPONAME \
--domain DOMAINNAME

above, replace:

  • the USERNAME/REPONAME with the path to your GitHub fork (e.g., john/my-project)
  • DOMAINNAME with the domain you wish to deploy your project to

Install the Postgres addon

Let's now setup Postgres to run on your disco server. We're in the process of improving these steps, so please bear with us.

# install the Postgres addon
disco postgres:addon:install

# create a new Postgres instance.
disco postgres:instances:add

# in the output of the command above, you will see
# "Added instance postgres-instance-XXX-YYY" where XXX and YYY are two random words.
# your instance name is "XXX-YYY". note this as it will be used for the command below.

# add a new database to the instance you just created.
disco postgres:databases:add --instance INSTANCENAME

# the command above will also print out an important piece of information:
# the database name. note it as well. we're now ready for the last command:

# finally, attach the database to your project.
# in the command below, replace:
# - INSTANCENAME with the "XXX-YYY" instance name you got previously
# - DATABASENAME with the database name you got from the most recent command
disco postgres:databases:attach \
--instance INSTANCENAME \
--database DATABASENAME \
--project my-django-site

Last steps

We need to run 2 more commands so that the deployed project can work:

# generate a secret key, for example using `uuidgen`,
# and set it as the DJANGO_SECRET_KEY value below:
disco env:set --project my-django-site \
DJANGO_SECRET_KEY="... secret value ..."
disco run --project my-django-site "python manage.py migrate"

That's it! Your project will now deploy to your server.

Once deployed, go to your domain name. Your site should be there!