How to Deploy a Test-Ready Django Rest Framework Project to Heroku Using Gitlab-CI and PostgreSQL

Source: Avengers: Infinity War

First, Create the Heroku app.

Setup the PostgreSQL database for testing

Setup the Gitlab repository

Create your Django project

git clone <your gitlab repository URL here>
cd <your project directory>
python -m venv env
.\env\Scripts\activate
pip install -r requirements.txt
django-admin startproject <your_django_app_name> .

Create your test

python .\manage.py startapp my_app_1

Configure settings.py and static folder

Configure .gitlab-ci.yml

DATABASE_URL=”$TEST_DATABASE_URL$SSLCONF” coverage run --branch --source=my_app1 manage.py test --keepdb
DATABASE_URL=”$TEST_DATABASE_URL$SSLCONF” coverage run --branch --source=my_app1,my_app2,my_app3 manage.py test --keepdb

Configure Procfile and deployment.sh

Configure .gitignore and setup.cfg

Deploy.

git add .
git commit -m "Initial commit"
git push origin master

Computer Science Undergraduate at University of Indonesia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store