Build, deploy and host your Django application for Free with Utopiops

Photo by David Clode on Unsplash

Build, deploy and host your Django application for Free with Utopiops

Mohsen Kamrani's photo
Mohsen Kamrani
·Jan 26, 2022·

4 min read

Subscribe to my newsletter and never miss my upcoming articles

As a software developer or a software development team, the most important thing for you is building quality software, shipping it and getting feedback from your customers.

Utopiops (utopiops.com) is a new player in town that aims to solve the problem uniquely by giving you a complete ecosystem that supports you entire platform from build, deployment and hosting your applications to monitoring the platform, incident reports and integrations with issue tracking systems.

Utopiops also supports Fully-managed and Managed applications. The Fully-managed applications are hosted on Utopiops cloud platform, while Managed applications are hosted on your own cloud accounts.

In his post I show you how to host your applications using Fully-managed applications on Utopiops for free.

To do so, I have implemented a simple Django application with a typical Dockerfile.

First we create a virtual environment and install django:

# Windows
> python -m venv .venv
> .venv\Scripts\Activate.ps1
(.venv) > python -m pip install django~=4.0.0

# macOS
% python3 -m venv .venv
% source .venv/bin/activate
(.venv) % python3 -m pip install django~=4.0.0

Now we can create our django application with the startproject command. You can obviously use any valid arbitrary name instead of django_utopiops_example.

django-admin startproject django_utopiops_example .

I want to keep the application as simple as possible, so I use the basic code that I have in my project. The only thing we have to do before deploying our application with Utopiops is to Dockerize it.

I first create a requirements.txt file in the root of my project and I add the required dependencies to it:

Django>=4.0
psycopg2>=2.8

Now we create a Dockerfile again in the root of our project and we add these lines:

# syntax=docker/dockerfile:1
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ]

As always I've optionally added a .dockerignore file to avoid bloating my docker images with unnecessary files. This is how it looks like:

.venv

Note: We run our applications inside docker so we have to set ALLOWED_HOSTS = ['*'] in our settings.py.

Screen Shot 2022-01-26 at 9.05.12 pm.png

That's all we need and we're ready to use Utopiops to build, deploy and host our application.

You can find all these files in the repository here.

Before we begin the deployment you need to create an account on Utopiops if you already haven't done that before, by registering and verifying your email.

Now we create a dockerized application

Screen Shot 2022-01-24 at 12.56.53 pm.png

Then we choose the repository we have stored our code:

Screen Shot 2022-01-24 at 1.00.08 pm.png

I'm using Github for this example, but you can also use Gitlab and Bitbucket too.

Finally just git your application a name, set the git branch, the port your application is listening on, and an endpoint that can be used as health check. Remember that health-check path is just any endpoint that returns a 2xx response to an unauthorized HTTP GET request.

You can also set the environment variables if you like.

Screen Shot 2022-01-26 at 9.13.53 pm.png

Right away the built-in CICD on Utopiops is set up and starts building and deploying your application.

Screen Shot 2022-01-26 at 9.16.43 pm.png

You can see the build logs live as they happen:

And in a just few seconds your application is available (for this example it took 3 seconds to be precise)

Screen Shot 2022-01-26 at 9.43.54 pm.png

Notice that by default HTTPS is provided for you application, just the certificate takes a few minutes to be effective, but guess what! We're working on it to reduce that to few seconds as well.

Screen Shot 2022-01-26 at 9.44.29 pm.png

Worth mentioning, any time you make a change to your target branch, the new version of your application is built and deployed right away.


Final note

We're a very young startup with huge goals in our mind. You can be part of the first users who get to know about our features and our journey.

Please join our family by joining our discord channel, and following us on Twitter, and using our service. We have a generous hobby plan!

Please leave a comment if you have any questions or even want to see a private demo!

 
Share this