How to Deploy Django Website to Heroku with Gitlab CI/CD

Step 1: Create Heroku app

Step 2: Create CI/CD script

Step 3: Set environment variable

  • HEROKU_APP_NAME = <your app name>
  • HEROKU_API_KEY = <your account API key>
  • HEROKU_APP_HOST = <your host url>
  • HEROKU_APP_NAME = simpk
  • HEROKU_API_KEY = 01234567-abcd-1234
  • HEROKU_APP_HOST = simpk.herokuapp.com

Step 4: Install dependencies

pip install gunicorn coverage

Step 5: Create required files

  • Procfile
  • requirements.txt
release: python manage.py migrate
web: gunicorn simpk.wsgi --log-file -
pip freeze > requirements.txt

Step 6: Modify settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
ALLOWED_HOST = ['localhost', 'simpk.herokuapp.com']

Step 7: Enjoy

git add .
git commit -m "deployment"
git push origin main
Where to find View Logs in Heroku

References

--

--

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