This article will cover how to deploy your Django app to an Ubuntu Droplet from Digital Ocean
Luckily you don't have to learn web server configuration or even SSH into the droplet.
Let's start, it will take us less than 15 minutes to get your app running
If you are looking for tutorial for another cloud provider checkout out one of these:
- Deploy Django on Hetzner Cloud
- Deploy Django to AWS EC2
- Deploy Django to AWS Lightsail
- Deploy Django on Linode
- Deploy Django on Azure
- Deploy Django to Google Cloud Platform
Table of contents¶
- An application in Git repository
- Digital Ocean account
- Appliku account
To deploy your application you need to push it to a git repository in GitHub, Gitlab or any other git repository hosting.
For easiest deployment:
- put your django project in the root of the repository
requirements.txtin the root with all dependecies needed for your project to run
gunicornor other WSGI server that you need to run your app in requirements
psycopg2-binary==2.9.5if you need a Postgres database support
Procfilein the root of the repository with commands needed to run your project e.g. https://gitlab.com/speedpycom/speedpycom-backend/-/blob/main/Procfile
- app should respect environment variables for example
Digital Ocean Account¶
If you don't already have a Digital Ocean account, Sign up now
Go here to create an API Token: https://cloud.digitalocean.com/account/api/tokens/new?i=c00a4a
After creating token, save it to a safe place, you will need it in a few moments.
If you don't already have an Appliku Account create it by going here: https://app.appliku.com/
Click on "Add a server"
Click on "Setup Credentials" for Digital Ocean
Paste your token that you created earlier in Digital Ocean dashboard and click "Test & Save Credentials"
Status should say "Active" if the key was correct
Go to "Servers"
Then "Add Server"
You can now select the "Digital Ocean" provider
Select a region, droplet type and droplet size and click "Create Droplet"
You will be taken to the list of servers and you can see your new server there. Click on its name.
You can see that Appliku is waiting for droplet being fully booted to start the setup process
You can click on "Setup Logs" tab to see the logs of setup process
When server setup is finished you will see stats and "Setup Status" on the left will say "Finished".
Adding an application¶
Click on the "Applications" menu link
You will get to the Git Provider selection.
Creating application from GitHub¶
Select the "Setup Credentials" for GitHub.
You need to get a personal token from GitHub.
Go to this link to create a token: https://github.com/settings/tokens
Click on Generate new token -> Generate new token(Classic) Fill in the note, select expiration date, check the "repo" checkbox and "user:email"
And click "Generate token".
Copy the token from the next page.
Go back to Appliku dashboard and paste the GitHub Token, and click Test Credentials and Save
Status must change to "Active".
Click on the logo in top left corner to get back to your team and go to Applications again and create an app, select GitHub.
Fill the form with the app name, select the repository with your application, branch and select the server, click on "Create Application".
You will see your app has been created, but not yet deployed.
Creating application from GitLab¶
Alternatively if you use GitLab you should add credentials for GitLab and create an app from GitLab.
Go to Applications menu link, Click "Add Application" and Setup credentials for GitLab.
You need to create a Personal Access Token here: https://gitlab.com/-/profile/personal_access_tokens
Give the key a name, set or clear expiration date, select "api" checkbox and click "Create Personal Access token"
Copy the token and paste it in Appliku dashboard.
After you click "Test Credentials and Save" the Status should turn green and say "Active".
Click on the logo to go back to your team, go to Applications, Add Application and select GitLab
Give your application a name, pick repository and the branch, select the server and click "Create Application"
Setup the app¶
If your application needs a database, which Django apps need most of the time, you can click on the "Manage" in databases block and "Create Database"
Select a database type you need and your server to deploy the DB to, click "Create database"
Your database will start deploying, wait for the deployment status to become "deployed".
Go back to your app
You can see your database is in the list.
Environment variables and build settings¶
Click on the "Settings" link next to the application name.
Go to the "Environment Variables" tab
You can see that the
DATABASE_URL is already added automatically from the database you created.
If you have a
.env file you can use "Import from .env" button to paste variables.
Or click on "Add" button and add variables one by one.
Usually for Django app we need to add
Appliku provides a default host name for your application which is YOUR_APP_NAME+ '.applikuapp.com'
After you finished adding your variables click on "Save and Deploy"
You will see that the deployment started.
Go back to the application overview.
The "Deploy Now" button is grey because deployment is in progress and in the "Latest deployment" Block you can see the currently running deployment.
Click on "Deployment #1"
You can see the deployment log. Scroll down to see the most recent output.
After it finishes and reports the "exit_code: 0", which is success go back to your application overview
Click on "View Application"
It will open your application in a new window!