Deploy

This app use Render as host, Sentry to track error, GitHub for the versioning, GitHub Actions for the CI, and DockerHub to save the image.

REQUIREMENTS:

A CI/CD pipeline is set to run 3 jobs:

  • build and test - to lint the code, run test and check coverage (must be over 80%)

  • docker - to buid the Docker image and push it to DockerHub

  • deploy - to deploy the Docker container on Render

The pipeline run every job when pushed onto the master branch, or only the Build-and-test job when pushed onto another branch.

If one job fails, the others are skiped.

Set GitHub enviroment variables

If you don’t have a GitHub account yet, create one.

  1. On your respository go to settings

  2. Select Secrets and variables and click on Actions

  3. Click on New repository secrets

  4. Enter secret name

  5. Enter the secret

  6. Repeat 3. 4. and 5. for all secrets to be set

Secrets to be set:

Name

Secret

DOCKERHUB_USERNAME

<your_dockerhub_username>

DOCKERHUB_TOKEN

<your_dockerhub_token>

MY_RENDER_API_KEY

<your_render_api_key>

MY_RENDER_SERVICE_ID

<your_render_service_id>

See below to know how to get it.

Get the DockerHub access token

If you don’t have a DockerHub account yet, create one.

On your DockerHub account:

  1. Click your profile

  2. Then on My Account

  3. Select Security

  4. And create a new token by clicking New Access Token

  5. Add the token to your GitHub secrets with name DOCKERHUB_TOKEN

Warning

The DockerHub Access Token can be view only one time at the creation ! If you loose it you need to generate a new one.

Configure Sentry

If you don’t have a Sentry account yet, create one.

On your dashboard

  1. Select Projects

  2. Click on Create project

  3. Configure the project

  4. Get the DSN

Configure Render

If you don’t have a Render account yet, create one.

On your render dashbord:

  1. Click on New + and select Web Service

  2. Select option Build and deploy from a Git repository

  3. Connect yout GitHub account

  4. Configure your service by setting:

    • Name: Choose a name

    • Region: Choose your region

    • Runtime: set Docker

    • Set environment variables:

      • DJANGO_SECRET_KEY: <your_django_secret_key>

        Warning

        Django can NOT start without a secret key.
        If the secret key is missing it will raise
        ImproperlyConfigured: The SECRET_KEY setting must not be empty.
      • SENTRY_DSN: <your_sentry_dsn>

        Note

        To get your Sentry DSN see Where to Find Your DSN

    • Click on Advanced:

      • Set Dockerfile Path to: Dockerfile

      • Set Auto-Deploy to: No

    • Click Create Web Service

  5. Get the api key:

    • On your profile select Account Settings

    • Under API Keys select Create API key

    • Add the API key to your GitHub secrets with the name MY_RENDER_API_KEY

    Warning

    The Render API key can be view only one time at the creation ! If you loose it you need to generate a new one.

  6. Get the service id:

    • On your dashboard select your service

    • When viewing a service in the Render dashboard grab this value from the URL - it will start with srv-

    • Add the service id to your GitHub secrets with the name MY_RENDER_SERVICE_ID