Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ NOTES.md
!.env.local.template
supabase-local.env

# Ignore Postgres data generated by the Supabase stack
/supabase-project/volumes/db/data/

# Node.js dependencies
node_modules/*
.nvmrc
Expand Down
91 changes: 91 additions & 0 deletions docs/developers/containerization-of-Supabase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Containerization Of Supabase Instance

## Getting started

Run these commands

```sh
# Get the code
git clone --depth 1 https://github.com/supabase/supabase

# Make your new supabase project directory
mkdir supabase-project

# Tree should look like this
# .
# ├── supabase
# └── supabase-project

# Copy the compose files over to your project
cp -rf supabase/docker/* supabase-project

# Copy the fake env vars
cp supabase/docker/.env.example supabase-project/.env

# Switch to your project directory
cd supabase-project

# Pull the latest images
docker compose pull

# Start the services (in detached mode)
docker compose up -d
```

## Change the env varibables

Change any of the variables from their placeholders to real urls for the app and so on.

## Dump DB

If not linked to supabase yet run this

```shell
# Link with the current project you are using
npx supabase link
```

1. Run one of the following commands to dump the DB with or without data

```shell
cd supabase_CLI

# schema-only (safer)
npx supabase db dump -f scheme.sql

# or data
npx supabase db dump --data-only -f data.sql
```

NOTE:
if the previous commands do not work, try this instead

```shell
cd supabase-project
# schema
supabase db dump \
--db-url "postgresql://postgres:<DB_PASSWORD>@db.<PROJECT_REF>.supabase.co:5432/postgres?sslmode=require" \
-f scheme.sql

# or data only
supabase db dump \
--db-url "postgresql://postgres:<DB_PASSWORD>@db.<PROJECT_REF>.supabase.co:5432/postgres?sslmode=require" \
--data-only -f data.sql
```

2. Restore into self-hosted DB with docker

```shell
cd supabase-project
# restore schema first
docker compose exec -T db psql -U postgres -d postgres < schema.sql
# then restore data
docker compose exec -T db psql -U postgres -d postgres < data.sql
```

3. Run the images again

```shell
cd supabase-project
docker compose restart
```
3 changes: 3 additions & 0 deletions supabase-project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore Postgres data generated by the Supabase stack
/volumes/db/data/
volumes/db/data
3 changes: 3 additions & 0 deletions supabase-project/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Supabase Docker

This is a minimal Docker Compose setup for self-hosting Supabase. Follow the steps [here](https://supabase.com/docs/guides/hosting/docker) to get started.
48 changes: 48 additions & 0 deletions supabase-project/dev/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
create table profiles (
id uuid references auth.users not null,
updated_at timestamp with time zone,
username text unique,
avatar_url text,
website text,

primary key (id),
unique(username),
constraint username_length check (char_length(username) >= 3)
);

alter table profiles enable row level security;

create policy "Public profiles are viewable by the owner."
on profiles for select
using ( auth.uid() = id );

create policy "Users can insert their own profile."
on profiles for insert
with check ( auth.uid() = id );

create policy "Users can update own profile."
on profiles for update
using ( auth.uid() = id );

-- Set up Realtime
begin;
drop publication if exists supabase_realtime;
create publication supabase_realtime;
commit;
alter publication supabase_realtime add table profiles;

-- Set up Storage
insert into storage.buckets (id, name)
values ('avatars', 'avatars');

create policy "Avatar images are publicly accessible."
on storage.objects for select
using ( bucket_id = 'avatars' );

create policy "Anyone can upload an avatar."
on storage.objects for insert
with check ( bucket_id = 'avatars' );

create policy "Anyone can update an avatar."
on storage.objects for update
with check ( bucket_id = 'avatars' );
34 changes: 34 additions & 0 deletions supabase-project/dev/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
version: "3.8"

services:
studio:
build:
context: ..
dockerfile: apps/studio/Dockerfile
target: dev
ports:
- 8082:8082
mail:
container_name: supabase-mail
image: inbucket/inbucket:3.0.3
ports:
- '2500:2500' # SMTP
- '9000:9000' # web interface
- '1100:1100' # POP3
auth:
environment:
- GOTRUE_SMTP_USER=
- GOTRUE_SMTP_PASS=
meta:
ports:
- 5555:8080
db:
restart: 'no'
volumes:
# Always use a fresh database when developing
- /var/lib/postgresql/data
# Seed data should be inserted last (alphabetical order)
- ./dev/data.sql:/docker-entrypoint-initdb.d/seed.sql
storage:
volumes:
- /var/lib/storage
94 changes: 94 additions & 0 deletions supabase-project/docker-compose.s3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
services:

minio:
image: minio/minio
ports:
- '9000:9000'
- '9001:9001'
environment:
MINIO_ROOT_USER: supa-storage
MINIO_ROOT_PASSWORD: secret1234
command: server --console-address ":9001" /data
healthcheck:
test: [ "CMD", "curl", "-f", "http://minio:9000/minio/health/live" ]
interval: 2s
timeout: 10s
retries: 5
volumes:
- ./volumes/storage:/data:z

minio-createbucket:
image: minio/mc
depends_on:
minio:
condition: service_healthy
entrypoint: >
/bin/sh -c "
/usr/bin/mc alias set supa-minio http://minio:9000 supa-storage secret1234;
/usr/bin/mc mb supa-minio/stub;
exit 0;
"

storage:
container_name: supabase-storage
image: supabase/storage-api:v1.11.13
depends_on:
db:
# Disable this if you are using an external Postgres database
condition: service_healthy
rest:
condition: service_started
imgproxy:
condition: service_started
minio:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"wget",
"--no-verbose",
"--tries=1",
"--spider",
"http://localhost:5000/status"
]
timeout: 5s
interval: 5s
retries: 3
restart: unless-stopped
environment:
ANON_KEY: ${ANON_KEY}
SERVICE_KEY: ${SERVICE_ROLE_KEY}
POSTGREST_URL: http://rest:3000
PGRST_JWT_SECRET: ${JWT_SECRET}
DATABASE_URL: postgres://supabase_storage_admin:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
FILE_SIZE_LIMIT: 52428800
STORAGE_BACKEND: s3
GLOBAL_S3_BUCKET: stub
GLOBAL_S3_ENDPOINT: http://minio:9000
GLOBAL_S3_PROTOCOL: http
GLOBAL_S3_FORCE_PATH_STYLE: true
AWS_ACCESS_KEY_ID: supa-storage
AWS_SECRET_ACCESS_KEY: secret1234
AWS_DEFAULT_REGION: stub
FILE_STORAGE_BACKEND_PATH: /var/lib/storage
TENANT_ID: stub
# TODO: https://github.com/supabase/storage-api/issues/55
REGION: stub
ENABLE_IMAGE_TRANSFORMATION: "true"
IMGPROXY_URL: http://imgproxy:5001
volumes:
- ./volumes/storage:/var/lib/storage:z

imgproxy:
container_name: supabase-imgproxy
image: darthsim/imgproxy:v3.8.0
healthcheck:
test: [ "CMD", "imgproxy", "health" ]
timeout: 5s
interval: 5s
retries: 3
environment:
IMGPROXY_BIND: ":5001"
IMGPROXY_USE_ETAG: "true"
IMGPROXY_ENABLE_WEBP_DETECTION: ${IMGPROXY_ENABLE_WEBP_DETECTION}
Loading
Loading