aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md40
-rw-r--r--docker-compose.yml1
-rw-r--r--postgrest/Dockerfile4
-rw-r--r--postgrest/migrations/003-roles.sql4
-rw-r--r--postgrest/postgrest.conf2
-rwxr-xr-xpostgrest/start-postgrest.sh2
6 files changed, 49 insertions, 4 deletions
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