From f1ca81f18cc4a0aa745800bb2f6cc3d3099512db Mon Sep 17 00:00:00 2001 From: Paul Copplestone Date: Mon, 13 Jan 2020 09:44:05 +0800 Subject: [PATCH] supabase-dev attempt 1: we have the docker container extending our realtime server, but we need to get all commands working together. At the moment only one is running at a time --- test/Makefile => Makefile | 0 {test => dev}/docker-compose.yml | 0 dev/docker/Dockerfile | 70 +++++++++ dev/docker/postgrest.conf | 19 +++ dev/docker/start.sh | 4 + {test => dev}/kong/Dockerfile | 0 {test => dev}/kong/kong.yml | 0 {test => dev}/postgres/Dockerfile | 0 {test => dev}/postgres/mnt/conf.sql | 0 dev/postgres/mnt/latest.sql | 53 +++++++ docker-compose.yml | 30 ++++ .../frontend => examples/next-js}/.gitignore | 0 .../frontend => examples/next-js}/Dockerfile | 0 {test/frontend => examples/next-js}/README.md | 0 .../next-js}/next.config.js | 0 .../next-js}/package-lock.json | 0 .../next-js}/package.json | 0 .../next-js}/pages/index.js | 0 test/postgres/mnt/latest.sql | 146 ------------------ 19 files changed, 176 insertions(+), 146 deletions(-) rename test/Makefile => Makefile (100%) rename {test => dev}/docker-compose.yml (100%) create mode 100644 dev/docker/Dockerfile create mode 100644 dev/docker/postgrest.conf create mode 100644 dev/docker/start.sh rename {test => dev}/kong/Dockerfile (100%) rename {test => dev}/kong/kong.yml (100%) rename {test => dev}/postgres/Dockerfile (100%) rename {test => dev}/postgres/mnt/conf.sql (100%) create mode 100644 dev/postgres/mnt/latest.sql create mode 100644 docker-compose.yml rename {test/frontend => examples/next-js}/.gitignore (100%) rename {test/frontend => examples/next-js}/Dockerfile (100%) rename {test/frontend => examples/next-js}/README.md (100%) rename {test/frontend => examples/next-js}/next.config.js (100%) rename {test/frontend => examples/next-js}/package-lock.json (100%) rename {test/frontend => examples/next-js}/package.json (100%) rename {test/frontend => examples/next-js}/pages/index.js (100%) delete mode 100644 test/postgres/mnt/latest.sql diff --git a/test/Makefile b/Makefile similarity index 100% rename from test/Makefile rename to Makefile diff --git a/test/docker-compose.yml b/dev/docker-compose.yml similarity index 100% rename from test/docker-compose.yml rename to dev/docker-compose.yml diff --git a/dev/docker/Dockerfile b/dev/docker/Dockerfile new file mode 100644 index 00000000000..9c0804e64ef --- /dev/null +++ b/dev/docker/Dockerfile @@ -0,0 +1,70 @@ +FROM supabase/realtime:latest + +ARG POSTGREST_VERSION="v6.0.2" +ENV DB_HOST=localhost \ + DB_NAME=postgres \ + DB_USER=postgres \ + DB_PASSWORD=postgres \ + DB_PORT=5432 \ + PGRST_DB_URI= \ + PGRST_DB_SCHEMA=public \ + PGRST_DB_ANON_ROLE= \ + PGRST_DB_POOL=100 \ + PGRST_DB_EXTRA_SEARCH_PATH=public \ + PGRST_SERVER_HOST=*4 \ + PGRST_SERVER_PORT=3000 \ + PGRST_SERVER_PROXY_URI= \ + PGRST_JWT_SECRET= \ + PGRST_SECRET_IS_BASE64=false \ + PGRST_JWT_AUD= \ + PGRST_MAX_ROWS= \ + PGRST_PRE_REQUEST= \ + PGRST_ROLE_CLAIM_KEY=".role" \ + PGRST_ROOT_SPEC= \ + PGRST_RAW_MEDIA_TYPES= + +RUN apt-get update + +# Install libpq5 +RUN apt-get -qq install -y --no-install-recommends libpq5 && \ + apt-get -qq clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Install postgrest +RUN BUILD_DEPS="curl ca-certificates xz-utils" && \ + apt-get -qq update && \ + apt-get -qq install -y --no-install-recommends $BUILD_DEPS && \ + cd /tmp && \ + curl -SLO https://github.com/PostgREST/postgrest/releases/download/${POSTGREST_VERSION}/postgrest-${POSTGREST_VERSION}-ubuntu.tar.xz && \ + tar -xJvf postgrest-${POSTGREST_VERSION}-ubuntu.tar.xz && \ + mv postgrest /usr/local/bin/postgrest && \ + cd / && \ + apt-get -qq purge --auto-remove -y $BUILD_DEPS && \ + apt-get -qq clean && \ + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +COPY postgrest.conf /etc/postgrest.conf + +RUN groupadd -g 1000 postgrest && \ + useradd -r -u 1000 -g postgrest postgrest && \ + chown postgrest:postgrest /etc/postgrest.conf + +# Add user to Realtime +RUN chown -R postgrest:postgrest /prod/rel/realtime/ + +ADD start.sh / +RUN chmod +x /start.sh + +USER 1000 + +EXPOSE 3000 +EXPOSE 4000 + +CMD ["/start.sh"] + +# PostgREST reads /etc/postgrest.conf so map the configuration +# file in when you run this container +# CMD exec postgrest /etc/postgrest.conf +# CMD ["sh", "-c", "/prod/rel/realtime/bin/realtime start ; exec postgrest /etc/postgrest.conf"] + +# docker build . -t supabase --pull --no-cache \ No newline at end of file diff --git a/dev/docker/postgrest.conf b/dev/docker/postgrest.conf new file mode 100644 index 00000000000..b9c7cde0ede --- /dev/null +++ b/dev/docker/postgrest.conf @@ -0,0 +1,19 @@ +db-uri = "$(PGRST_DB_URI)" +db-schema = "$(PGRST_DB_SCHEMA)" +db-anon-role = "$(PGRST_DB_ANON_ROLE)" +db-pool = "$(PGRST_DB_POOL)" +db-extra-search-path = "$(PGRST_DB_EXTRA_SEARCH_PATH)" + +server-host = "$(PGRST_SERVER_HOST)" +server-port = "$(PGRST_SERVER_PORT)" + +server-proxy-uri = "$(PGRST_SERVER_PROXY_URI)" +jwt-secret = "$(PGRST_JWT_SECRET)" +secret-is-base64 = "$(PGRST_SECRET_IS_BASE64)" +jwt-aud = "$(PGRST_JWT_AUD)" +role-claim-key = "$(PGRST_ROLE_CLAIM_KEY)" + +max-rows = "$(PGRST_MAX_ROWS)" +pre-request = "$(PGRST_PRE_REQUEST)" +root-spec = "$(PGRST_ROOT_SPEC)" +raw-media-types = "$(PGRST_RAW_MEDIA_TYPES)" \ No newline at end of file diff --git a/dev/docker/start.sh b/dev/docker/start.sh new file mode 100644 index 00000000000..ec88c521d00 --- /dev/null +++ b/dev/docker/start.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +exec postgrest /etc/postgrest.conf & +/prod/rel/realtime/bin/realtime start & \ No newline at end of file diff --git a/test/kong/Dockerfile b/dev/kong/Dockerfile similarity index 100% rename from test/kong/Dockerfile rename to dev/kong/Dockerfile diff --git a/test/kong/kong.yml b/dev/kong/kong.yml similarity index 100% rename from test/kong/kong.yml rename to dev/kong/kong.yml diff --git a/test/postgres/Dockerfile b/dev/postgres/Dockerfile similarity index 100% rename from test/postgres/Dockerfile rename to dev/postgres/Dockerfile diff --git a/test/postgres/mnt/conf.sql b/dev/postgres/mnt/conf.sql similarity index 100% rename from test/postgres/mnt/conf.sql rename to dev/postgres/mnt/conf.sql diff --git a/dev/postgres/mnt/latest.sql b/dev/postgres/mnt/latest.sql new file mode 100644 index 00000000000..0eeb65b5572 --- /dev/null +++ b/dev/postgres/mnt/latest.sql @@ -0,0 +1,53 @@ + + +-- +-- Name: cities; Type: TABLE; Schema: public; Owner: supabase +-- + +CREATE TABLE public.cities ( + id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name character varying(255) NOT NULL, + country_id integer NOT NULL +); + + + +-- +-- Name: countries; Type: TABLE; Schema: public; Owner: supabase +-- + +CREATE TABLE public.countries ( + id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name character varying(255) NOT NULL, + iso2 character varying(5) NOT NULL, + continent character varying(255) NOT NULL +); + + +-- +-- Data for Name: cities; Type: TABLE DATA; Schema: public; Owner: supabase +-- + +COPY public.cities (id, name, country_id) FROM stdin; +1 Rio de Janeiro 1 +2 Beijing 2 +3 Paris 3 +4 Auckland 4 +5 Lagos 5 +6 San Francisco 6 +\. + + +-- +-- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: supabase +-- + +COPY public.countries (id, name, iso2, continent) FROM stdin; +1 Brazil BR South America +2 China CN Asia +3 France FR Europe +4 New Zealand NZ Oceania +5 Nigeria NG Africa +6 United States US North America +\. + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000000..412599e8208 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' + +services: + supabase: + build: ./dev/docker + ports: + - "4000:4000" + - "3000:3000" + environment: + DB_HOST: db + DB_NAME: postgres + DB_USER: postgres + DB_PASSWORD: postgres + DB_PORT: 5432 + APP_PORT: 4000 + APP_HOSTNAME: localhost + SECRET_KEY_BASE: SOMETHING_SUPER_SECRET + PGRST_DB_URI: postgres://postgres:postgres@db:5432/postgres + PGRST_DB_SCHEMA: public + PGRST_DB_ANON_ROLE: postgres + depends_on: + - db + # command: ["sh", "-c", "/prod/rel/realtime/bin/realtime start ; exec postgrest /etc/postgrest.conf"] + command: ["/start.sh"] + db: + build: ./dev/postgres + ports: + - "5432:5432" + + \ No newline at end of file diff --git a/test/frontend/.gitignore b/examples/next-js/.gitignore similarity index 100% rename from test/frontend/.gitignore rename to examples/next-js/.gitignore diff --git a/test/frontend/Dockerfile b/examples/next-js/Dockerfile similarity index 100% rename from test/frontend/Dockerfile rename to examples/next-js/Dockerfile diff --git a/test/frontend/README.md b/examples/next-js/README.md similarity index 100% rename from test/frontend/README.md rename to examples/next-js/README.md diff --git a/test/frontend/next.config.js b/examples/next-js/next.config.js similarity index 100% rename from test/frontend/next.config.js rename to examples/next-js/next.config.js diff --git a/test/frontend/package-lock.json b/examples/next-js/package-lock.json similarity index 100% rename from test/frontend/package-lock.json rename to examples/next-js/package-lock.json diff --git a/test/frontend/package.json b/examples/next-js/package.json similarity index 100% rename from test/frontend/package.json rename to examples/next-js/package.json diff --git a/test/frontend/pages/index.js b/examples/next-js/pages/index.js similarity index 100% rename from test/frontend/pages/index.js rename to examples/next-js/pages/index.js diff --git a/test/postgres/mnt/latest.sql b/test/postgres/mnt/latest.sql deleted file mode 100644 index ba7d1ffe743..00000000000 --- a/test/postgres/mnt/latest.sql +++ /dev/null @@ -1,146 +0,0 @@ --- --- PostgreSQL database dump --- - --- Dumped from database version 11.2 --- Dumped by pg_dump version 11.2 - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET client_min_messages = warning; -SET row_security = off; - -SET default_tablespace = ''; - -SET default_with_oids = false; - --- --- Name: cities; Type: TABLE; Schema: public; Owner: supabase --- - -CREATE TABLE public.cities ( - id bigint NOT NULL, - name character varying(255) NOT NULL, - country_id integer NOT NULL -); - - -ALTER TABLE public.cities OWNER TO supabase; - --- --- Name: cities_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase --- - -ALTER TABLE public.cities ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY ( - SEQUENCE NAME public.cities_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1 -); - - --- --- Name: countries; Type: TABLE; Schema: public; Owner: supabase --- - -CREATE TABLE public.countries ( - id bigint NOT NULL, - name character varying(255) NOT NULL, - iso2 character varying(5) NOT NULL, - continent character varying(255) NOT NULL -); - - -ALTER TABLE public.countries OWNER TO supabase; - --- --- Name: countries_id_seq; Type: SEQUENCE; Schema: public; Owner: supabase --- - -ALTER TABLE public.countries ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY ( - SEQUENCE NAME public.countries_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1 -); - - --- --- Data for Name: cities; Type: TABLE DATA; Schema: public; Owner: supabase --- - -COPY public.cities (id, name, country_id) FROM stdin; -1 Rio de Janeiro 1 -2 Beijing 2 -3 Paris 3 -4 Auckland 4 -5 Lagos 5 -6 San Francisco 6 -\. - - --- --- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: supabase --- - -COPY public.countries (id, name, iso2, continent) FROM stdin; -1 Brazil BR South America -2 China CN Asia -3 France FR Europe -4 New Zealand NZ Oceania -5 Nigeria NG Africa -6 United States US North America -\. - - --- --- Name: cities_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase --- - -SELECT pg_catalog.setval('public.cities_id_seq', 6, true); - - --- --- Name: countries_id_seq; Type: SEQUENCE SET; Schema: public; Owner: supabase --- - -SELECT pg_catalog.setval('public.countries_id_seq', 6, true); - - --- --- Name: cities cities_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase --- - -ALTER TABLE ONLY public.cities - ADD CONSTRAINT cities_pkey PRIMARY KEY (id); - - --- --- Name: countries countries_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase --- - -ALTER TABLE ONLY public.countries - ADD CONSTRAINT countries_pkey PRIMARY KEY (id); - - --- --- Name: cities cities_countries_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase --- - -ALTER TABLE ONLY public.cities - ADD CONSTRAINT cities_countries_id_fkey FOREIGN KEY (country_id) REFERENCES public.countries(id) ON DELETE CASCADE; - - --- --- PostgreSQL database dump complete --- -