version: '3.8'

services:
  keycloak-db:
    image: postgres:14-alpine
    env_file:
      - ../config/keycloak/keycloak.env
    healthcheck:
      test: ["CMD", "nc", "-v", "localhost", "5432"]
      interval: 30s
      timeout: 10s
      retries: 10
      start_period: 3s
    ports:
      - 5432
  keycloak:
    image: cerc/keycloak:local
    env_file:
      - ../config/keycloak/keycloak.env
    environment:
      JAVA_OPTS_APPEND: "-Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.migration.dir=/import -Dkeycloak.migration.strategy=IGNORE_EXISTING"
    volumes:
      - ../config/keycloak/import:/import
    ports:
      - 8080
    command: ["start"]
    depends_on:
      keycloak-db:
        condition: service_healthy
  keycloak-nginx:
    image: nginx:1.23-alpine
    restart: always
    volumes:
      - ../config/keycloak/nginx:/etc/nginx/conf.d
    ports:
      - 80
    depends_on:
      - keycloak
  keycloak-nginx-prometheus-exporter:
    image: nginx/nginx-prometheus-exporter
    restart: always
    environment:
      - SCRAPE_URI=http://keycloak-nginx:80/stub_status
    depends_on:
      - keycloak-nginx
