Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

359 - One postgres instance for both keycloak and general database #360

Merged
merged 6 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ DB_PASS=postgrespass
DB_PORT=5432
DB_NAME=postgres

## Keycloak ##
##############
KEYCLOAK_DB_VENDOR=POSTGRES
KEYCLOAK_DB_USER=keycloak
KEYCLOAK_DB_PASSWORD=keycloak
KEYCLOAK_DB_NAME=keycloak

## Local prisma db url
DATABASE_URL=postgres://postgres:postgrespass@localhost:5432/postgres?schema=api

Expand Down
9 changes: 9 additions & 0 deletions db/init.d/create-keycloak-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e
set -u

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER keycloak WITH PASSWORD 'keycloak';
CREATE DATABASE keycloak;
GRANT ALL PRIVILEGES ON DATABASE keycloak TO keycloak;
1 change: 1 addition & 0 deletions db/init.d/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
\set ON_ERROR_STOP on

CREATE SCHEMA "api";
CREATE SCHEMA "public";
26 changes: 16 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
restart: 'no'
environment:
DATABASE_URL: postgres://${DB_USER?}:${DB_PASS?}@${DB_HOST?}:${DB_PORT?}/${DB_NAME?}?schema=api
entrypoint: ["sh", "-c", "sleep 5 && yarn prisma migrate deploy"]
entrypoint: ['sh', '-c', 'sleep 5 && yarn prisma migrate deploy']
depends_on:
- pg-db
networks:
Expand All @@ -65,7 +65,7 @@ services:
restart: 'no'
environment:
DATABASE_URL: postgres://${DB_USER?}:${DB_PASS?}@${DB_HOST?}:${DB_PORT?}/${DB_NAME?}?schema=api
entrypoint: ["sh", "-c", "sleep 15 && yarn prisma generate && yarn prisma db seed"]
entrypoint: ['sh', '-c', 'sleep 15 && yarn prisma generate && yarn prisma db seed']
depends_on:
- pg-db
networks:
Expand All @@ -81,8 +81,9 @@ services:
restart: always

volumes:
- pg-db-data:/bitnami/postgresql

# Keycloak creates it's own /data and /conf folders
- keycloak-db-data:/var/lib/keycloak
- pg-db-data:/var/lib/postgresql/data
ports:
- '${DB_PORT?}:5432'

Expand All @@ -95,7 +96,6 @@ services:

networks:
- backend-net

########################################
## LOCAL IDENTITY PROVIDER - KEYCLOAK ##
########################################
Expand All @@ -108,22 +108,27 @@ services:
profiles: ['local-keycloak']
restart: always
environment:
- KEYCLOAK_USER=${KEYCLOAK_PASSWORD}
- KEYCLOAK_PASSWORD=${KEYCLOAK_PASSWORD}
- KEYCLOAK_USER=${KEYCLOAK_USER?}
- KEYCLOAK_PASSWORD=${KEYCLOAK_PASSWORD?}
- JAVA_OPTS_APPEND=-Dkeycloak.profile.feature.token_exchange=enabled -Dkeycloak.profile.feature.admin_fine_grained_authz=enabled
- KEYCLOAK_IMPORT=/opt/jboss/keycloak/config/keycloak-webapp-realm.json
- DEBUG=true
- DEBUG_PORT='*:8787'
- DB_VENDOR=H2
- TZ=Europe/Sofia
- DB_VENDOR=${KEYCLOAK_DB_VENDOR?}
- DB_USER=${KEYCLOAK_DB_USER?}
- DB_PASSWORD=${KEYCLOAK_DB_PASSWORD?}
- DB_ADDR=${COMPOSE_PROJECT_NAME?}-pg-db
- DB_DATABASE=${KEYCLOAK_DB_NAME?}
ports:
- '8180:8080'
- '8787:8787'
volumes:
- './manifests/keycloak/theme_podkrepi:/opt/jboss/keycloak/themes/theme_podkrepi'
- './manifests/keycloak/config:/opt/jboss/keycloak/config'
depends_on:
- pg-db
networks:
backend-net:
- backend-net

# ## KEYCLOAK CONFIGURATOR - removes the need to recreate keycloak container upon config changes
# ## uncomment if you plan to tune the keycloak realm configuration
Expand All @@ -147,6 +152,7 @@ services:
# backend-net:
volumes:
pg-db-data:
driver: local
keycloak-db-data:
driver: local

Expand Down