This repository contains a bash script (generate.bash) to facilitate the creation of multiple Supabase instances on a single VPS. The goal is to allow the operation of several isolated instances, each with its own environment variables and volume configuration, to support different projects efficiently on a single server.
The purpose of generate.bash is to automatically create and configure new Supabase instances, generating unique instance IDs, non-conflicting ports, and customized settings for each new instance. This is useful when you need multiple isolated environments on the same server without manually managing each instance's configurations.
The script:
- Generates a unique INSTANCE_ID based on the date and time, which can be customized.
- Generates secure passwords and keys for environment variables like POSTGRES_PASSWORD, JWT_SECRET, ANON_KEY, and SERVICE_ROLE_KEY.
- Automatically substitutes variables into configuration files such as .env.template, docker-compose.yml, kong.yml, and vector.yml.
- Creates and organizes necessary volume directories for PostgreSQL, functions, and logs for each instance.
- Sets up dynamic ports to avoid conflicts between instances.
- Spins up the instance containers using docker compose.
- generate.bash: Main bash script for generating and configuring new instances.
- docker/: Directory containing configuration templates, such as .env.template and docker-compose.yml, as well as the Kong and Vector configuration files.
- volumes/: Directory containing initial folders and files for PostgreSQL, functions, and logs.
Clone this repository to your VPS.
git clone https://github.com/MendesCorporation/multiple-supabase.git
cd multiple-supabase/docker
Edit the generate.bash file with your desired configurations, such as SMTP_HOST, JWT_EXPIRY, SITE_URL, among other variables specific to your environment.
Run the script to generate a new instance:
sh generate.bash
The script will automatically generate a new INSTANCE_ID and configure the instance with dynamic ports, unique passwords, and keys.
Once the script finishes running, you can access your new instance using the ports configured by the script. The default generated URLs will look like:
Supabase Public URL: http://0.0.0.0:80XX Replace XX with the generated port number.
Each time the script is executed, it generates a new isolated instance with its own environment variables, volumes, and ports. Instances can be managed individually using Docker Compose commands:
docker compose -f docker-compose-${INSTANCE_ID}.yml down
docker compose -f docker-compose-${INSTANCE_ID}.yml up -d
Generated Folder Structure For each new instance, the script creates the following directories:
volumes-${INSTANCE_ID}/
├── api/
├── db/
├── functions/
└── logs/
Each of these directories contains the necessary files to run the associated containers.
Here are some of the environment variables automatically generated:
INSTANCE_ID: Unique ID for the instance.
POSTGRES_PASSWORD: PostgreSQL password.
JWT_SECRET: JWT key for authentication.
ANON_KEY and SERVICE_ROLE_KEY: Keys used in Supabase for permissions.
KONG_HTTP_PORT and KONG_HTTPS_PORT: Dynamic ports for HTTP and HTTPS access.
Docker and Docker Compose installed on the VPS.
OpenSSL for generating secure passwords.
Feel free to open issues and pull requests for improvements and fixes. Feedback is always welcome!