Deploy to theDigitalOcean App Platform. Docker uses only local environment

This article explains how to deploy web applications to DigitalOcean App Platform.

For beginners in web development, the biggest obstacle they face on the road to publishing their own apps is deployment.

I have been using DigitalOcean since 5-6 years ago, and at that time, I used their VPS called Droplet for deployment.

Although Droplet is affordable and perfect for individual development, it is not a service that focuses on deploying and operating applications (PaaS), so I need to configure web servers and databases from scratch. This is very cumbersome, and I remember struggling for several days until these settings were successful during my first deployment.

However, since the release of App Platform in DigitalOcean in 2020 , my deployment work has become much easier.

Although App Platform is slightly more expensive than Droplet, it is a service that more than justifies its cost.

This time, to avoid struggling with deployments for those new to web development with Django, I would like to show you a stress-free and quick deployment method using the DigitalOcean App Platform.

Additionally, note that I use Docker in my development environment, but this article introduces a deployment method that does not use Docker.

I have tried several ways to deploy using Docker, but none of them worked. On the other hand, the method without docker succeeded in deploying easily, so we will introduce the method without docker in this issue.

How to Deploy a Django App to the App Platform

Let's first examine the local Docker setup.

1. Setting up Django Locally Using Docker

2. Rewrite the Setup to Deploy without Docker

3.Set up the digital ocean App platform

Since deploying in the standard way to the App platform is also written in other blogs and documents, I would like to explain the process in a way that is consistent with our current environment.

There are five steps to deployment.

  1. Create an account of DigitalOcean, choose AppPlatform, and connect to GitHub account.
  2. Select the github repository to deploy to
  3. Choose whether to use the database or not
  4. Enter environment variables in the admin panel
  5. Deploy

If you look at the admin panel of DigitalOcean, you can easily understand 1 and 2, but 3 and 4 need a little explanation.

Concerning step 3, in the local environment, you need to enter settings about database such as the password and hostname. However, in the App platform, it is unnecessary since the settings are applied automatically.

Regarding step 4, in the local environment, you set environment variables in a .env file. In contrast, in the App platform, there is a field to enter these variables in the admin panel. Therefore, you can directly enter the values in the admin panel.

Summary of the Deploy Process

This concludes the tutorial on deploying a Django application. The key points from the above tutorial are summarized below.

  1. Use the Django package whitenoise to serve static files during deployment. When not installed, errors in static file processing can occur. Be sure to include this package when deploying.
  2. Create a settings folder for deployment, and divide the settings file into base.py, dev.py, and prod.py. Include an __init__.py file in the folder to separate the development and production settings files. Rename the original settings.py file used during development to something like old_settings.py.
  3. When deploying on an AppPlatform, set environment variables from the management screen. This involves reading the settings file and setting environment variables for the database host and URL.

If you've tried it and it doesn't work for some reason,Please review the above three points carefully. I'm sure it will work.

With the emergence of Platform as a Service (PaaS), deploying applications has become much easier. Let's take advantage of these services and release more and more original services!