From 28c653ef34e1318319482c25cbe5be3c635ce8e8 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Thu, 20 Sep 2018 17:49:23 +0200 Subject: [PATCH] Add PostgreSQL demo container --- demo/postgresql/docker-compose.yml | 23 +++++++++ .../midpoint-additions-for-standalone-run.yml | 45 ++++++++++++++++++ demo/postgresql/midpoint-additions.yml | 47 +++++++++++++++++++ demo/postgresql/postgresql/Dockerfile | 3 ++ .../container_files/init-user-db.sh | 12 +++++ 5 files changed, 130 insertions(+) create mode 100644 demo/postgresql/docker-compose.yml create mode 100644 demo/postgresql/midpoint-additions-for-standalone-run.yml create mode 100644 demo/postgresql/midpoint-additions.yml create mode 100644 demo/postgresql/postgresql/Dockerfile create mode 100755 demo/postgresql/postgresql/container_files/init-user-db.sh diff --git a/demo/postgresql/docker-compose.yml b/demo/postgresql/docker-compose.yml new file mode 100644 index 0000000..79a3738 --- /dev/null +++ b/demo/postgresql/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.3" + +services: + postgresql: + build: ./postgresql/ + environment: + - POSTGRES_PASSWORD=password + expose: + - 5432 + ports: + - 5432:5432 + networks: + - net + volumes: + - data:/var/lib/postgresql/data + + +networks: + net: + driver: bridge + +volumes: + data: diff --git a/demo/postgresql/midpoint-additions-for-standalone-run.yml b/demo/postgresql/midpoint-additions-for-standalone-run.yml new file mode 100644 index 0000000..d89165f --- /dev/null +++ b/demo/postgresql/midpoint-additions-for-standalone-run.yml @@ -0,0 +1,45 @@ +# +# This is a file with additions to ../midpoint/docker-compose.yml file, to be used in the following way: +# +# (in this directory) +# +# $ docker-compose up --build +# +# (in ../midpoint directory) +# +# $ docker-compose -f docker-compose.yml -f ../demo/postgresql/midpoint-additions-for-standalone-run.yml up --build +# +# It expects that PostgreSQL is started independently of midPoint. When executing the containers in this way, there are two compositions with the following containers: +# +# "midpoint" +# +# 1) midpoint-server +# 2) midpoint-data <-- this is the original MariaDB container; it will execute command of 'true' i.e. exiting just upon the startup +# +# "postgresql" +# +# 1) postgresql +# + +version: "3.3" + +services: + midpoint-server: + environment: + - REPO_DATABASE_TYPE=postgresql + - REPO_HOST=postgresql + - REPO_PORT=5432 + - REPO_DATABASE=midpoint + - REPO_USER=midpoint + networks: + - postgresql_net + + # effectively disable original MariaDB service + midpoint-data: + image: alpine:latest + command: "true" + entrypoint: "true" + +networks: + postgresql_net: + external: true diff --git a/demo/postgresql/midpoint-additions.yml b/demo/postgresql/midpoint-additions.yml new file mode 100644 index 0000000..5dfb3d9 --- /dev/null +++ b/demo/postgresql/midpoint-additions.yml @@ -0,0 +1,47 @@ +# +# This is a file with additions to ../midpoint/docker-compose.yml file, to be used in the following way: +# +# (in ../midpoint directory) +# +# $ docker-compose -f docker-compose.yml -f ../demo/postgresql/midpoint-additions.yml up --build +# +# It expects that PostgreSQL is started as part of midPoint composition. So there will be three containers there: +# +# 1) midpoint-server +# 2) postgresql +# 3) midpoint-data <-- this is the original MariaDB container; it will execute command of 'true' i.e. exiting just upon the startup +# + +version: "3.3" + +services: + postgresql: + build: ../demo/postgresql/postgresql/ + entrypoint: ["/docker-entrypoint.sh", "postgres"] # for some reasons this is needed for the correct initialization + environment: + - POSTGRES_PASSWORD=password + expose: + - 5432 + ports: + - 5432:5432 + networks: + - back + volumes: + - postgresql_data:/var/lib/postgresql/data + + midpoint-server: + environment: + - REPO_DATABASE_TYPE=postgresql + - REPO_HOST=postgresql + - REPO_PORT=5432 + - REPO_DATABASE=midpoint + - REPO_USER=midpoint + + # effectively disable original MariaDB service + midpoint-data: + image: alpine:latest + command: "true" + entrypoint: "true" + +volumes: + postgresql_data: diff --git a/demo/postgresql/postgresql/Dockerfile b/demo/postgresql/postgresql/Dockerfile new file mode 100644 index 0000000..dcaf4d6 --- /dev/null +++ b/demo/postgresql/postgresql/Dockerfile @@ -0,0 +1,3 @@ +FROM postgres:9.5 + +COPY container_files/* /docker-entrypoint-initdb.d/ diff --git a/demo/postgresql/postgresql/container_files/init-user-db.sh b/demo/postgresql/postgresql/container_files/init-user-db.sh new file mode 100755 index 0000000..95df619 --- /dev/null +++ b/demo/postgresql/postgresql/container_files/init-user-db.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +echo Creating midPoint user and database + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER midpoint WITH PASSWORD '456654' LOGIN SUPERUSER; + CREATE DATABASE midpoint WITH OWNER = midpoint ENCODING = 'UTF8' TABLESPACE = pg_default LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' CONNECTION LIMIT = -1; +EOSQL + +echo midPoint user and database were created +