From 449ebe5164ad9d2ba1e7d61bbae8e4101b703490 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 26 Apr 2020 16:40:34 +0300 Subject: Stuff --- README.md | 40 ++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 1 + postgrest/Dockerfile | 4 +++- postgrest/migrations/003-roles.sql | 4 ++-- postgrest/postgrest.conf | 2 +- postgrest/start-postgrest.sh | 2 ++ 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d167bb4 --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# PostgREST system demo + +# Installation + +* Run +``` +$ docker-compose build +``` + +* Create file `.env` with all variables required in `docker-compose.yml`. +* Set up `authenticator` user role in the database by running + +``` +$ docker-compose run --rm postgrest_api bash -c " + PGPASSWORD=postgres psql -h postgres -U postgres -c \"\ + create role authenticator noinherit login password '${POSTGREST_PASSWORD}' + \" +" +``` + +# Running migrations + +Migration files live under `postgrest/migrations`. Run them all with +``` +$ docker-compose run --rm postgrest_api bash -c ' +for sqlfile in migrations/*.sql +do + echo Migrating ${sqlfile}... + PGPASSWORD=postgres psql -U postgres -h postgres < ${sqlfile} +done' +``` + +# Launching services + +* Run +``` +$ docker-compose up +``` + +Copyright Jan Tuomi 2020 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1c3a756..31b19f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,6 +14,7 @@ services: build: ./postgrest environment: JWT_SECRET: ${JWT_SECRET} + POSTGREST_PASSWORD: ${POSTGREST_PASSWORD} depends_on: - postgres ports: diff --git a/postgrest/Dockerfile b/postgrest/Dockerfile index 5e6abac..7aafc88 100644 --- a/postgrest/Dockerfile +++ b/postgrest/Dockerfile @@ -1,6 +1,8 @@ FROM ubuntu:18.04 WORKDIR /app -RUN apt-get update && apt-get install -y libpq-dev gettext +RUN apt-get update && apt-get install -y libpq-dev gettext postgresql-client ADD postgrest postgrest.conf start-postgrest.sh ./ +ADD migrations ./migrations + CMD ["./start-postgrest.sh"] diff --git a/postgrest/migrations/003-roles.sql b/postgrest/migrations/003-roles.sql index 86e49f0..9ad6685 100644 --- a/postgrest/migrations/003-roles.sql +++ b/postgrest/migrations/003-roles.sql @@ -1,5 +1,5 @@ --- authenticator role -create role authenticator noinherit login password 'mysecretpassword'; +-- authenticator role. created manually, see README.md +-- create role authenticator noinherit login password '${POSTGREST_PASSWORD}'; -- web_anon role create role web_anon nologin; diff --git a/postgrest/postgrest.conf b/postgrest/postgrest.conf index 638b528..9c1b675 100644 --- a/postgrest/postgrest.conf +++ b/postgrest/postgrest.conf @@ -1,4 +1,4 @@ -db-uri = "postgres://authenticator:mysecretpassword@postgres:5432/postgres" +db-uri = "postgres://authenticator:${POSTGREST_PASSWORD}@postgres:5432/postgres" db-schema = "api" db-anon-role = "web_anon" jwt-secret = "${JWT_SECRET}" diff --git a/postgrest/start-postgrest.sh b/postgrest/start-postgrest.sh index 5995898..f74e180 100755 --- a/postgrest/start-postgrest.sh +++ b/postgrest/start-postgrest.sh @@ -1,5 +1,7 @@ #!/bin/bash +# Insert env vars into postgrest.conf envsubst < postgrest.conf > postgrest.conf.tmp mv postgrest.conf.tmp postgrest.conf + ./postgrest postgrest.conf -- cgit v1.3