How to deploy to render

This is only a guide. The final deployment will depend on the services you have setup, settings and more. If you run into trouble check the following guides.

Overview for how this works

  • Define the web service and other supporting services in the service definition file - render.yaml.

  • Define and custom build script that will run during deployments. This script includes actions to be performed before deploying to render.com , e.g. collect staticfiles or run migrations.

  • During deployment render will build the Dockerfile and deploy it based on the service definition.

Example service definition file

text

services:
  - type: web
    name: app-name
    env: python
    plan: starter plus # optional; defaults to starter
    numInstances: 1
    domains: # custom domains
      - your-domain.com
    region: frankfurt
    buildCommand: ./ops/deploy/render/build.sh
    startCommand: 'gunicorn -w 1 -k uvicorn.workers.UvicornH11Worker config.asgi:application --max-requests 1000'
    envVars:
      - key: AWS_ENABLED 
        value: True
      - key: DEBUG 
        value: False
      - key: DEFAULT_EMAIL 
        value: admin@advantch.com
      - key: DISABLE_COLLECTSTATIC 
        value: 0
      - key: DJANGO_AWS_S3_REGION_NAME 
        value: eu-west-2
      - key: DJANGO_AWS_STORAGE_BUCKET_NAME 
        value: advantch
      - key: DJANGO_SETTINGS_MODULE 
        value: config.settings.production
      - key: TENANT_MODE 
        value: 2
      - key: WEB_CONCURRENCY 
        value: 3
      - key: SENDGRID_API_KEY
        sync: false
      - key: DATABASE_URL
        fromDatabase:
          name: postgres-advantch-db
          property: connectionString
      - key: REDIS_URL
        fromService:
          type: redis
          name: service
          property: connectionString
  - type: worker
    name: huey
    env: python
    startCommand: python manage.py run_huey
    branch: staging
    plan: starter
    region: frankfurt
    envVars:
      .... include the same variables as you included in the web service.
  • in this example we are deploying two services, the web app and a worker.

  • the worker does not include a buildCommand key.

  • make sure to include the necessary variables.

Example build script definition

text
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

pip3 install --upgrade pip
pip3 install -r ./requirements/production.txt

python manage.py collectstatic --noinput
python manage.py migrate

Before checking it into code, make sure the script is executable.

text
chmod a+x build.sh

Deploying the services

To deploy to render connect the Github repository to render.com . This should be done from the dashboard.