Automatically Deploy App on Heroku Based on User Creation

Solution 1:

This is highly dependent on how your multi-tenancy is being achieved.

If you haven't already built multi-tenancy into your application I encourage you to look at something like django-tenants, which adds multitenancy support based on subdomains and PostgreSQL schemas. If that's not a good fit you can explore other similar libraries.

Once you've set up django-tenants there's not much more to do on the Django side. It all be comes configuration. Requests to configured subdomains will be routed to the appropriate shared or tenant database schema.

But those requests have to make it to your application. That's where DNS comes in, ideally using wildcard subdomains.

First, add *.your-domain.tld to your app's domains on the Heroku side:

heroku domains:add "*.your-domain.tld"

Next, add a wildcard CNAME entry with your DNS provider¹. The exact mechanics of how to do this will vary from provider to provider. You've said you're moving to DNSimple, and it looks like they support wildcard CNAME records using *.


¹Unfortunately, some DNS providers like GoDaddy don't support wildcard CNAME entries. In that case you'll have to individually create each CNAME record.