Add HowTo create Docker based test setup

README.md contains step (with necessary gerrit.config changes) for
setting up Postgres Docker based setup.

Change-Id: I550dc16e61bb398b179d31fb5592e88724d17575
Signed-off-by: Jacek Centkowski <jcentkowski@collab.net>
diff --git a/README.md b/README.md
index 0a3788b..ee820a8 100644
--- a/README.md
+++ b/README.md
@@ -63,3 +63,32 @@
 
 If a unit suffix is not specified, `milliseconds` is assumed.
 Default is `30 seconds`.
+
+## Testing with docker based Postgres setup
+
+One can start test Postgres server that contains both `gerrit_review`
+(Gerrit db) and `gerrit_caches` (db for caches) with the
+following command
+```
+docker-compose -f docker/gerrit-caches-compose.yaml up
+```
+
+One nedds to add the following parameters to `gerrit.config`
+```
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.type POSTGRESQL
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.hostname localhost
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.port 5432
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.database gerrit_review
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.username gerrit
+git config --file ${GERRIT_ETC_DIR}/gerrit.config database.password gerrit
+git config --file ${GERRIT_ETC_DIR}/gerrit.config cache.url "jdbc:postgresql://localhost:5432/gerrit_caches?user=gerrit&password=gerrit"
+```
+
+where `GERRIT_ETC_DIR` is `GERRIT_SITE/etc`;
+
+Notes
+* container name is `gerrit-pg`
+* container uses `docker_gerrit-db-data` volume therefore restarting it
+preserves data
+* details of Postgres user/dbs setup can be found in `docker/create-gerrit-dbs.sh`
+* Postgres container details (ports, volumes, etc.) are in `docker/gerrit-caches-compose.yaml`
diff --git a/docker/create-gerrit-dbs.sh b/docker/create-gerrit-dbs.sh
new file mode 100755
index 0000000..f681e78
--- /dev/null
+++ b/docker/create-gerrit-dbs.sh
@@ -0,0 +1,22 @@
+USERNAME="gerrit"
+USERPASS="gerrit"
+
+# create user and modify password
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
+  CREATE USER "$USERNAME";
+  ALTER USER "$USERNAME" WITH PASSWORD '$USERPASS';
+EOSQL
+
+# create caches DB
+DBNAME="gerrit_caches"
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
+  CREATE DATABASE "$DBNAME" ENCODING UTF8;
+  GRANT ALL PRIVILEGES ON DATABASE "$DBNAME" TO "$USERNAME";
+EOSQL
+
+# create review DB
+DBNAME="gerrit_review"
+psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
+  CREATE DATABASE "$DBNAME" ENCODING UTF8;
+  GRANT ALL PRIVILEGES ON DATABASE "$DBNAME" TO "$USERNAME";
+EOSQL
diff --git a/docker/gerrit-caches-compose.yaml b/docker/gerrit-caches-compose.yaml
new file mode 100644
index 0000000..57a89b1
--- /dev/null
+++ b/docker/gerrit-caches-compose.yaml
@@ -0,0 +1,21 @@
+version: '3.5'
+
+services:
+  db:
+    container_name: ${DB_CONTAINER_NAME:-gerrit-pg}
+    image: postgres:${DB_IMAGE_ID:-9.6.8-alpine}
+    restart: unless-stopped
+    environment:
+      - POSTGRES_USER=${DB_USER:-postgres}
+      - POSTGRES_PASSWORD=${DB_PASS:-postgres}
+    ports:
+      - '5432:5432'
+    volumes:
+      - type: bind
+        source: ./create-gerrit-dbs.sh
+        target: /docker-entrypoint-initdb.d/create-gerrit-dbs.sh
+        read_only: true
+      - gerrit-db-data:/var/lib/postgresql/data
+
+volumes:
+  gerrit-db-data: