Skip to content

Instantly share code, notes, and snippets.

@adamghill
Last active September 19, 2024 12:30
Show Gist options
  • Save adamghill/ba816554995d1fe5e5b2195ec76eaef8 to your computer and use it in GitHub Desktop.
Save adamghill/ba816554995d1fe5e5b2195ec76eaef8 to your computer and use it in GitHub Desktop.
Settings, files, and a checklist to deploy a Django app to Render with gunicorn + redis and using `poetry` for dependencies.
  • GitHub for code
  • Render blueprint specified by render.yaml
    • Postgres
    • Redis
    • Linked to GitHub repo
    • Add environment variables for PYTHON_VERISON=3.9.7, ENVIRONMENT=live, and SECRET_KEY
  • Cloudflare for SSL and CNAME pointing to Render app domain
    • Force SSL with a Cloudflare rule
  • Namecheap for the domain
    • Point nameservers to Cloudflare
  • Sentry for error logging
  • Panelbear and Plausible for privacy-focused analytics
  • UptimeRobot to get alerts for when the site goes down
#!/usr/bin/env bash
set -o errexit
poetry install --no-dev
python manage.py collectstatic --noinput
python manage.py compress --force
python manage.py collectstatic --noinput
python manage.py migrate
services:
- type: web
name: something-web
env: python
repo: https://github.com/adamghill/something.com
region: ohio
scaling:
minInstances: 1
maxInstances: 2
targetMemoryPercent: 60 # optional if targetCPUPercent is set
targetCPUPercent: 60 # optional if targetMemory is set
buildCommand: ./render-build.sh
startCommand: gunicorn -c gunicorn.conf.py project.wsgi
plan: free
domains:
- something.com
- www.something.com
envVars:
- key: DATABASE_URL
fromDatabase:
name: something-postgres
property: connectionString
- key: REDIS_URL
fromService:
type: redis
name: something-redis
property: connectionString
- fromGroup: something
- type: redis
name: something-redis
ipAllowList: []
plan: free
region: ohio
databases:
- name: something-postgres
region: ohio
plan: standard
@jnns
Copy link

jnns commented Oct 24, 2022

Thanks for sharing. Do you mind explaining what you're using the /tmp/app-initialized file for?

By the way, be careful when specifying non-default Python versions on Render.com with libraries where no Wheel is available (see this post over at community.render.com).

@adamghill
Copy link
Author

Thanks for sharing. Do you mind explaining what you're using the /tmp/app-initialized file for?

I think that's actually left over from my Heroku set-up. Gonna clean that up now, thanks!

By the way, be careful when specifying non-default Python versions on Render.com with libraries where no Wheel is available (see this post over at community.render.com).

This is interesting, I'm specifying 3.9.x because I use orjson as a dependency which won't build with 3.7. I wonder if a better approach would be a Dockerfile? That way I could also experiment with nginx in front of gunicorn and potentially pgbouncer as well (similar to the Heroku buildpacks I had set up in https://gist.github.com/adamghill/9c11687eb87e98951adb11c4dacdb709)?

@jnns
Copy link

jnns commented Oct 24, 2022

I avoided deploying to Render using Dockerfiles so far. They recently published documentation about how to setup pgbouncer on their platform. This is the Dockerfile that they advise to use: https://github.com/render-oss/docker-pgbouncer

@adamghill
Copy link
Author

Oh, I hadn't seen https://render.com/docs/databases#connection-pooling before! This looks perfect, I'll try this out soon.

@czue
Copy link

czue commented Nov 2, 2022

Hey Adam - thanks for providing this info!

Let me know if you have any luck with the dockerfile approach. I'm finding they don't have any good alternative to the build script which makes it problematic to run things like migrations in a clean way. More here: https://community.render.com/t/release-command-for-db-migrations/247/7

@adamghill
Copy link
Author

I am hopeful that render adds a release phase soon. Looks like it is "planned" according to https://render.canny.io/features/p/release-phase-script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment