Up till now my preferred method of deploying my django websites has been using Ansible to provision DigitalOcean droplets(EC2 instances if you are on AWS) and then to automate deployments when a pull request is merged into main.
This approach has been useful for me to be able to learn a bunch of stuff such as Ansible which is an excellent automation platform which is super useful for Devop's work. It becomes more and more useful as the size of your IT infrastructure increases.
I have also learnt a lot about setting up Linux/ubuntu for the purpose of being a web server. This then has meant I have needed to learn tools like Nginx , Gunicorn and Systemd. I like learning about these tools so for me its been great.
All of that has been really time consuming. Believe me there have been tears of frustration and tears of joy. There is also the ongoing maintenance that is required. Security patches, OS upgrades. Trying to work out best practices for deployments. The list goes on.
In my new role as technical director at Therapyguide I am wearing a number of hats ranging from Django dev and Data Engineer to Product Owner. One of the areas I don't want to wear much of a hat is in the Devops domain.
There is and its called DigitalOcean Apps. Their tagline is focus on code not servers. The selling points for me is that it eradicates all of the above work and it also enables auto scaling either vertically or horizontally. All of the server maintenance gets done by DigitalOcean and the price differential is not that much. Maybe an extra $20 per month for a basic pro setup with two web servers which can handle a lot of traffic. Its a no brainer really. This post will take you through how to get up and running with a super simple django app which can be found on github here django-demos. I have set up this repo for all of my demos. I have created a branch called digitalocean_apps_part_one which you can refer to as the master branch will be further along and I want to keep your learning experience as simple as possible. Go ahead and fork that repo and you can then use it to try the steps in this demo in your own environment. This part one will be deploying a super basic app , part two will look at how to integrate a database, part three will be looking at static files and part four will look at all our production/scaling options and configurations.
The end goal of this series is for you to be supremely confident in setting up a DigitalOcean App in a real life production setting :)
Go over to DigitalOcean and if you don't have one go ahead and create an account. You will get $100 to use over 60 days.
Fork the django-demos repo in github
Clone the fork into your local dev environment
git clone https://github.com/your-github-account/django-demos.git
Go to the digitalocean_apps_part_one branch
git checkout digitalocean_apps_part_one
Now we are ready to go....
Here you need to select Github and then choose your repo and branch name. By choosing the autodeploy code changes any merge into the branch will create a deployment.
You will also need to authenticate with Github if this is your first time.
Source directory is our root, the type is a Web Service(we will look at the other types through the series)
For our basic apps we do not need any environment variables or build commands.
We need to provide a run command. In production we are using gunicorn short for 'Green Unicorn'
which is a Python WSGI HTTP Server for UNIX. In our project there is a wsgi file that we need to provide.
You can leave the port at 8080 and the HTTP Request Routes to be only /.
Name your App :)
Choose your plan, just basic for this post and you will only be able to use one container and click finish.
The app will build and hopefully all will go green. If not you can look at the runtime logs to diagnose
The I go to my app url which is just something digital ocean gave us for now. In this case https://django-demos-n27ou.ondigitalocean.app/
Thanks for reading. Next post will be about using postgresql as a database.