Skip to content

Commit

Permalink
Merge pull request #10 from kamil-oberaj/KO/keycloack-in-compose
Browse files Browse the repository at this point in the history
[feat]: keycloack in docker compose
  • Loading branch information
kamil-oberaj authored May 18, 2024
2 parents eb34a7e + 11f40d0 commit d61a6ba
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
3 changes: 2 additions & 1 deletion StudioManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudioManager.API", "Studio
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CE3FDE3B-F991-4566-A97C-D7520119F8EF}"
ProjectSection(SolutionItems) = preProject
docker-compose.yml = docker-compose.yml
.github\workflows\build_test.yaml = .github\workflows\build_test.yaml
docker-compose.yml = docker-compose.yml
pg-init-scripts\create-multiple-postgresql-databases.sh = pg-init-scripts\create-multiple-postgresql-databases.sh
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StudioManager.Infrastructure", "StudioManager.Infrastructure\StudioManager.Infrastructure.csproj", "{08F62C62-D31E-4E64-929F-D5DBF0C78E10}"
Expand Down
41 changes: 39 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
services:

#### STUDIOMANAGER DATABASE ####
studiomanager.database:
image: postgres:latest
container_name: studiomanager.database
Expand All @@ -7,24 +9,59 @@
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: P@ssw0rd
POSTGRES_DB: StudioManager
POSTGRES_MULTIPLE_DATABASES: StudioManager,Keycloak
healthcheck:
test: 'pg_isready -U postgres --dbname=StudioManager'
interval: 10s
timeout: 5s
retries: 5
volumes:
- ./.containers/studiomanager-db:/var/lib/postgresql/data
- ./pg-init-scripts:/docker-entrypoint-initdb.d
restart: unless-stopped


#### KEYCLOAK ####

studiomanager.keycloak:
image: quay.io/keycloak/keycloak:latest
container_name: studiomanager.keycloak
command: ["start-dev", "--import-realm"]
environment:
#KC_LOG_LEVEL: debug
KC_DB_VENDOR: postgres
KC_DB_ADDR: studiomanager.database
KC_DB_DATABASE: Keycloak
KC_DB_USER: postgres
KC_DB_PASSWORD: P@ssw0rd

KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
ports:
- 8080:8080
- 8443:8443
links:
- studiomanager.database
depends_on:
studiomanager.database:
condition: service_started
volumes:
- ./.containers/realm.json:/opt/keycloak/data/import/realm.json:r
restart: unless-stopped

#### API ####

studiomanager.api:
image: ${DOCKER_REGISTRY-}studiomanager.api
container_name: studiomanager.api
depends_on:
studiomanager.keycloak:
condition: service_started
studiomanager.database:
condition: service_healthy
condition: service_started
links:
- studiomanager.database
- studiomanager.keycloak
build:
context: .
dockerfile: StudioManager.API/Dockerfile
Expand Down
22 changes: 22 additions & 0 deletions pg-init-scripts/create-multiple-postgresql-databases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e
set -u

function create_user_and_database() {
local database=$1
echo " Creating user and database '$database'"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER $database;
CREATE DATABASE $database;
GRANT ALL PRIVILEGES ON DATABASE $database TO $database;
EOSQL
}

if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then
echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES"
for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do
create_user_and_database $db
done
echo "Multiple databases created"
fi

0 comments on commit d61a6ba

Please sign in to comment.