DEV Community

Self-hosting with Supabase

Scott P on July 22, 2021

Please note that this article is a work in progress. Please leave any suggestions or questions in the comments. Relevant materials: https://supa...
The discussion has been locked. New comments can't be added.
This guide hasn't been updated in a long time - please consider checking other resources for more recent and accurate information
Collapse
 
thewebisyourfriend profile image
Tony Westaway

What digital Ocean droplet would be suitable for this? Let's say I wanted to run 6 databases for example. I'm new to full stack and finding it all very expensive. I have a few ideas for web apps but the cost of running them seems high just for my own personal use, and potentially a few other users.

Collapse
 
chronsyn profile image
Scott P

You could realistically run the Supabase stack on a 2GB / 1 VCPU droplet, which costs $10 a month.

In terms of hosting multiple databases, if it was just postgres, you'd be able to create multiple databased on a server, but to get the Supabase stack to work, you'd potentially need to fork their code and make some adjustments and the manage creating the docker images yourself.

You could also create 1 droplet for each project, and this would be what I'd suggest, but the costs can be quite prohibitive. One possible solution is to host some projects on a free Supabase plan (i.e. on their managed platform), and some self-hosted.

Another option would be to think whether you need 6 independent projects. If money is an issue, thinking smart about how your tables are structured can significantly reduce your financial overhead. For example, if you have an app and an API, and both need database storage, you could prefix some tables with app_ and others with api_.

It's not something I'd recommend for most situations, but it's certainly an option.

Remember that you can run additional containers on your Supabase droplet. If you have an API that needs to access the database, instead of hosting it on a separate droplet, create a docker image of it and host it on the same droplet as Supabase. That saves you the monthly cost of 1 droplet.

Collapse
 
treboryx profile image
Robert • Edited

Nice guide. How about oauth providers? Can you set them up with the self host version?

EDIT: I think I might've got it, it's right here:
github.com/supabase/gotrue#externa...

Collapse
 
chronsyn profile image
Scott P • Edited

You can - I'm going to be updating the guide soon with the details needed to configure oAuth on self-hosted.

EDIT - 17:52, 01 August 2021:
The environment config example for oAuth support has been added near the bottom of the article

Collapse
 
j2l profile image
Philippe Manzano

Thank you very much!
Just to let you know for OS wise additions: On Ubuntu 21.04 (home setup for server), you have to sudo for everything about docker. Portainer is more picky, you can't simply use stack to github docker-compose.yml as is,
I had to add version: "3" , remove # github.com/supabase/cli/issues/14
and change all ports in .env since I had to use docker-compose up -d and it creates a docker-default network that seems to see bridge (and I'm running other postgres and nodejs containers). I guess it should have its own network set in docker-compose.
Additionally, on portainer running on Ubuntu, you usually can't edit a container without stopping it first (sometimes you can though).
I preferred to go local and use binds to my clone of supabase/docker/volumes/ instead of docker far far away volumes /var/lib/docker/volumes/ with sudo everywhere.
I'm missing a ssl certificate on this local docker, so nginx default.conf has listen 80
Reading supabase.io/docs/guides/self-hosting, it looks like, if you change the JWT_SECRET, you need to generate JWTs to add to your docker-coimpose.yml. I guess with jwt.io/?
Now, I have all the containers running but I don't know how to add a new user + project or base.
I know how to use supabase UI, and I locally can open db using Adminer but everything seems pretty empty, no user table.
Would you please let us know about using supabase from docker?
Thank you again,

Collapse
 
christopherkapic profile image
CK

Truly a fantastic resource Scott! Would you mind if I made a video walkthrough of this article? I'll link back to it in the description.

Collapse
 
chronsyn profile image
Scott P

Absolutely! Be sure to post a link here and I'll add it to the article!

Collapse
 
christopherkapic profile image
CK

One question--Portainer and Kong both use port 8000. How did you handle this?

 
chronsyn profile image
Scott P

The Supabase stack is on it's own network and I believe this is what prevents the routing from getting confused. Portainer uses ports 8000 and 9000 - 9000 is for the GUI, and 8000 is an SSH tunnel server used to create a tunnel between portainer agents and the portainer instance.

My Nginx config points towards the Kong instance (e.g. proxy_pass http://supabase-kong:8000;), which in turn handles routing to each individual service. The portainer container, being on a separate network, doesn't even know that the Supabase stack exists at the network level.

 
Sloan, the sloth mascot
Comment deleted
Collapse
 
benquan profile image
Ben

Did you ever publish the video?

Collapse
 
f041 profile image
Gabriele Giordano

about the passwords in the env part, this might look useful: supabase.com/docs/guides/self-host...
but then it produces a

Failed to deploy a stack: kong Pulling rest Pulling functions Pulling realtime Pulling storage Pulling vector

Collapse
 
tomitrescak profile image
Tomas Trescak

Hi, thanks for the amazing resource. My nginx complains about folowing:

2021/09/16 02:42:00 [emerg] 1#1: host not found in upstream "realtime:4000" in /etc/nginx/nginx.conf:39
Enter fullscreen mode Exit fullscreen mode

Any idea?

Collapse
 
willdvlpr profile image
Will Jones

Scott, brilliant article! Found to be very helpful!

Collapse
 
abdalaliy11 profile image
abdalaliy1

how to do everything without dashboard easily?
maybe it's worth another article

Collapse
 
chronsyn profile image
Scott P

Most of what I've covered within the article should be sufficient to get someone from nothing to self-hosted within a few hours.

Just about everything that's not covered is SQL, and I have no plans for an article covering that at this time as there are a huge number of resources out there which cover thousands of possible use cases in detail.

Collapse
 
mirsahib profile image
Mir Habib Ul Latif

What is the minimum system requirements for supabase stack to run in vps