Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Adds the docker setup

Paul Copplestone913add2e3ca4
diff --git a/docker/README.md b/docker/README.md
new file mode 100644
index 00000000000..a22a5825e38
--- /dev/null
+++ b/docker/README.md
@@ -0,0 +1,27 @@
+
+## Docker
+
+You can emulate Supabase using `docker-compose` by following these steps inside the `./docker` folder.
+
+- Starting the emulator: `docker-compose up -d`
+- Stopping the emulator: `docker-compose down`
+
+**Usage**
+
+```js
+import { createClient } from '@supabase/supabase-js'
+
+const SUPABASE_URL = 'http://localhost:8000'
+const SUPABASE_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoyNTUwNjUzNjM0LCJhdWQiOiIiLCJzdWIiOiIiLCJSb2xlIjoicG9zdGdyZXMifQ.kdRWxJKxqgFOlx4BZQj-GIIOEeMILqUvdHMh8ebcn8M'
+
+const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
+```
+
+Accessing the services directly:
+
+- Kong: http://localhost:8000
+ - GoTrue: http://localhost:8000/auth/v1/
+ - PostgREST: http://localhost:8000/rest/v1/
+ - Realtime: http://localhost:8000/realtime/v1/
+- Postgres: http://localhost:5432
+
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
new file mode 100644
index 00000000000..ca81429fc7c
--- /dev/null
+++ b/docker/docker-compose.yml
@@ -0,0 +1,74 @@
+version: '3.6'
+services:
+ kong:
+ build:
+ context: ./kong
+ environment:
+ KONG_DECLARATIVE_CONFIG: /var/lib/kong/kong.yml
+ KONG_PLUGINS: request-transformer,cors,key-auth,http-log
+ ports:
+ - 8000:8000/tcp
+ - 8443:8443/tcp
+ gotrue:
+ image: supabase/gotrue:latest
+ ports:
+ - '9999:9999'
+ environment:
+ GOTRUE_JWT_SECRET: super-secret-jwt-token
+ GOTRUE_JWT_EXP: 3600
+ GOTRUE_DB_DRIVER: postgres
+ DB_NAMESPACE: auth
+ API_EXTERNAL_URL: localhost
+ GOTRUE_API_HOST: 0.0.0.0
+ PORT: 9999
+ GOTRUE_DISABLE_SIGNUP: "false"
+ GOTRUE_SITE_URL: localhost
+ GOTRUE_MAILER_AUTOCONFIRM: "true"
+ GOTRUE_LOG_LEVEL: DEBUG
+ GOTRUE_OPERATOR_TOKEN: super-secret-operator-token
+ DATABASE_URL: "postgres://postgres:postgres@db:5432/postgres?sslmode=disable"
+ depends_on:
+ - db
+ rest:
+ image: postgrest/postgrest:latest
+ ports:
+ - '3000:3000'
+ depends_on:
+ - db
+ restart: always
+ environment:
+ PGRST_DB_URI: postgres://postgres:postgres@db:5432/postgres
+ PGRST_DB_SCHEMA: public
+ PGRST_DB_ANON_ROLE: postgres
+ PGRST_JWT_SECRET: super-secret-jwt-token
+ realtime:
+ image: supabase/realtime:latest
+ ports:
+ - '4000:4000'
+ depends_on:
+ - db
+ restart: on-failure
+ environment:
+ DB_HOST: db
+ DB_NAME: postgres
+ DB_USER: postgres
+ DB_PASSWORD: postgres
+ DB_PORT: 5432
+ PORT: 4000
+ HOSTNAME: localhost
+ JWT_SECRET: super-secret-jwt-token
+ db:
+ image: supabase/postgres:latest
+ ports:
+ - 5432:5432
+ volumes:
+ - ./docker/db:/docker-entrypoint-initdb.d/
+ command:
+ - postgres
+ - -c
+ - wal_level=logical
+ environment:
+ POSTGRES_DB: postgres
+ POSTGRES_USER: postgres
+ POSTGRES_PASSWORD: postgres
+ POSTGRES_PORT: 5432
diff --git a/docker/kong/Dockerfile b/docker/kong/Dockerfile
new file mode 100644
index 00000000000..5cba6a01970
--- /dev/null
+++ b/docker/kong/Dockerfile
@@ -0,0 +1,15 @@
+FROM kong:2.0.1
+
+COPY kong.yml /var/lib/kong/kong.yml
+
+# Build time defaults
+ARG build_KONG_DATABASE=off
+ARG build_KONG_PLUGINS=request-transformer,cors,key-auth
+ARG build_KONG_DECLARATIVE_CONFIG=/var/lib/kong/kong.yml
+
+# Run time values
+ENV KONG_DATABASE=$build_KONG_DATABASE
+ENV KONG_PLUGINS=$build_KONG_PLUGINS
+ENV KONG_DECLARATIVE_CONFIG=$build_KONG_DECLARATIVE_CONFIG
+
+EXPOSE 8000
diff --git a/docker/kong/kong.yml b/docker/kong/kong.yml
new file mode 100644
index 00000000000..e5b5915c5d4
--- /dev/null
+++ b/docker/kong/kong.yml
@@ -0,0 +1,45 @@
+_format_version: "1.1"
+services:
+- name: auth-v1
+ _comment: 'GoTrue: /auth/v1/* -> http://auth:9999/*'
+ url: http://auth:9999/
+ routes:
+ - name: auth-v1-all
+ strip_path: true
+ paths:
+ - /auth/v1/
+ plugins:
+ - name: cors
+ - name: key-auth
+ config:
+ hide_credentials: true
+- name: rest-v1
+ _comment: 'PosgREST: /rest/v1/* -> http://rest:3000/*'
+ url: http://rest:3000/
+ routes:
+ - name: rest-v1-all
+ strip_path: true
+ paths:
+ - /rest/v1/
+ plugins:
+ - name: cors
+ - name: key-auth
+ config:
+ hide_credentials: true
+- name: realtime-v1
+ _comment: 'Realtime: /realtime/v1/* -> ws://realtime:4000/socket/*'
+ url: http://realtime:4000/socket/
+ routes:
+ - name: realtime-v1-all
+ strip_path: true
+ paths:
+ - /realtime/v1/
+ plugins:
+ - name: cors
+ - name: key-auth
+ config:
+ hide_credentials: true
+consumers:
+- username: 'private-key'
+ keyauth_credentials:
+ - key: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoyNTUwNjUzNjM0LCJhdWQiOiIiLCJzdWIiOiIiLCJSb2xlIjoicG9zdGdyZXMifQ.kdRWxJKxqgFOlx4BZQj-GIIOEeMILqUvdHMh8ebcn8M
diff --git a/docker/postgres/00-initial-schema.sql b/docker/postgres/00-initial-schema.sql
new file mode 100644
index 00000000000..a0b6303d5ec
--- /dev/null
+++ b/docker/postgres/00-initial-schema.sql
@@ -0,0 +1,26 @@
+
+
+-- Set up reatime
+create publication supabase_realtime for all tables;
+
+-- Extension namespacing
+create schema extensions;
+create extension if not exists "uuid-ossp" with schema extensions;
+create extension if not exists pgcrypto with schema extensions;
+create extension if not exists pgjwt with schema extensions;
+
+-- Developer roles
+create role anon nologin noinherit;
+create role authenticated nologin noinherit; -- "logged in" user: web_user, app_user, etc
+create role service_role nologin noinherit bypassrls; -- allow developers to create JWT's that bypass their policies
+
+create user authenticator noinherit;
+grant anon to authenticator;
+grant authenticated to authenticator;
+grant service_role to authenticator;
+
+grant usage on schema public to postgres, anon, authenticated, service_role;
+alter default privileges in schema public grant all on tables to postgres, anon, authenticated, service_role;
+alter default privileges in schema public grant all on functions to postgres, anon, authenticated, service_role;
+alter default privileges in schema public grant all on sequences to postgres, anon, authenticated, service_role;
+
diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile
new file mode 100644
index 00000000000..cbec306808c
--- /dev/null
+++ b/docker/postgres/Dockerfile
@@ -0,0 +1,18 @@
+FROM supabase/postgres:0.13.0
+
+COPY 00-initial-schema.sql /docker-entrypoint-initdb.d/00-initial-schema.sql
+COPY auth-schema.sql /docker-entrypoint-initdb.d/auth-schema.sql
+
+# Build time defaults
+ARG build_POSTGRES_DB=postgres
+ARG build_POSTGRES_USER=postgres
+ARG build_POSTGRES_PASSWORD=postgres
+ARG build_POSTGRES_PORT=5432
+
+# Run time values
+ENV POSTGRES_DB=$build_POSTGRES_DB
+ENV POSTGRES_USER=$build_POSTGRES_USER
+ENV POSTGRES_PASSWORD=$build_POSTGRES_PASSWORD
+ENV POSTGRES_PORT=$build_POSTGRES_PORT
+
+EXPOSE 5432
diff --git a/docker/postgres/auth-schema.sql b/docker/postgres/auth-schema.sql
new file mode 100644
index 00000000000..73eec1c021f
--- /dev/null
+++ b/docker/postgres/auth-schema.sql
@@ -0,0 +1,91 @@
+
+CREATE SCHEMA IF NOT EXISTS auth AUTHORIZATION postgres;
+
+-- auth.users definition
+CREATE TABLE auth.users (
+ instance_id uuid NULL,
+ id uuid NOT NULL,
+ aud varchar(255) NULL,
+ "role" varchar(255) NULL,
+ email varchar(255) NULL,
+ encrypted_password varchar(255) NULL,
+ confirmed_at timestamptz NULL,
+ invited_at timestamptz NULL,
+ confirmation_token varchar(255) NULL,
+ confirmation_sent_at timestamptz NULL,
+ recovery_token varchar(255) NULL,
+ recovery_sent_at timestamptz NULL,
+ email_change_token varchar(255) NULL,
+ email_change varchar(255) NULL,
+ email_change_sent_at timestamptz NULL,
+ last_sign_in_at timestamptz NULL,
+ raw_app_meta_data jsonb NULL,
+ raw_user_meta_data jsonb NULL,
+ is_super_admin bool NULL,
+ created_at timestamptz NULL,
+ updated_at timestamptz NULL,
+ CONSTRAINT users_pkey PRIMARY KEY (id)
+);
+CREATE INDEX users_instance_id_email_idx ON auth.users USING btree (instance_id, email);
+CREATE INDEX users_instance_id_idx ON auth.users USING btree (instance_id);
+-- auth.refresh_tokens definition
+CREATE TABLE auth.refresh_tokens (
+ instance_id uuid NULL,
+ id bigserial NOT NULL,
+ "token" varchar(255) NULL,
+ user_id varchar(255) NULL,
+ revoked bool NULL,
+ created_at timestamptz NULL,
+ updated_at timestamptz NULL,
+ CONSTRAINT refresh_tokens_pkey PRIMARY KEY (id)
+);
+CREATE INDEX refresh_tokens_instance_id_idx ON auth.refresh_tokens USING btree (instance_id);
+CREATE INDEX refresh_tokens_instance_id_user_id_idx ON auth.refresh_tokens USING btree (instance_id, user_id);
+CREATE INDEX refresh_tokens_token_idx ON auth.refresh_tokens USING btree (token);
+-- auth.instances definition
+CREATE TABLE auth.instances (
+ id uuid NOT NULL,
+ uuid uuid NULL,
+ raw_base_config text NULL,
+ created_at timestamptz NULL,
+ updated_at timestamptz NULL,
+ CONSTRAINT instances_pkey PRIMARY KEY (id)
+);
+-- auth.audit_log_entries definition
+CREATE TABLE auth.audit_log_entries (
+ instance_id uuid NULL,
+ id uuid NOT NULL,
+ payload json NULL,
+ created_at timestamptz NULL,
+ CONSTRAINT audit_log_entries_pkey PRIMARY KEY (id)
+);
+CREATE INDEX audit_logs_instance_id_idx ON auth.audit_log_entries USING btree (instance_id);
+-- auth.schema_migrations definition
+CREATE TABLE auth.schema_migrations (
+ "version" varchar(255) NOT NULL,
+ CONSTRAINT schema_migrations_pkey PRIMARY KEY ("version")
+);
+INSERT INTO auth.schema_migrations (version)
+VALUES ('20171026211738'),
+ ('20171026211808'),
+ ('20171026211834'),
+ ('20180103212743'),
+ ('20180108183307'),
+ ('20180119214651'),
+ ('20180125194653');
+-- Gets the User ID from the request cookie
+create or replace function auth.uid() returns uuid as $$
+ select nullif(current_setting('request.jwt.claim.sub', true), '')::uuid;
+$$ language sql stable;
+-- Gets the User Role from the request cookie
+create or replace function auth.role() returns text as $$
+ select nullif(current_setting('request.jwt.claim.role', true), '')::text;
+$$ language sql stable;
+-- Gets the User Email from the request cookie
+create or replace function auth.email() returns text as $$
+ select nullif(current_setting('request.jwt.claim.email', true), '')::text;
+$$ language sql stable;
+GRANT ALL PRIVILEGES ON SCHEMA auth TO postgres;
+GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA auth TO postgres;
+GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA auth TO postgres;
+ALTER USER postgres SET search_path = "auth";
\ No newline at end of file