version: '3'
services:
  keycloak:
    image: services-keycloak
    build:
      context: .
    container_name: services-keycloak
    command:
      - start-dev
      - --import-realm
      - --proxy=edge
    ports:
      - 8080
    environment:
      - KEYCLOAK_ADMIN=${KEYCLOAK_USER}
      - KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_PASSWORD}
      - DB_VENDOR=POSTGRES
      - DB_ADDR=postgres
      - DB_PORT=5432
      - DB_DATABASE=${KEYCLOAK_DB}
      - DB_USER=${KEYCLOAK_DB_USER}
      - DB_PASSWORD=${KEYCLOAK_DB_PASS}
      - VIRTUAL_HOST=keycloak
      - CERT_NAME=dev.docker
      - VIRTUAL_PORT=8080
    depends_on:
      - postgres
      - nginx-proxy
    restart: unless-stopped
    volumes:
      - ./realm-export:/opt/keycloak/data/import
  postgres:
    image: postgres:latest
    container_name: postgres
    environment:
      - POSTGRES_DB=${KEYCLOAK_DB}
      - POSTGRES_USER=${KEYCLOAK_DB_USER}
      - POSTGRES_PASSWORD=${KEYCLOAK_DB_PASS}
    ports:
      - 5432
    restart: unless-stopped
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: keycloak_proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ../_shared/certs:/etc/nginx/certs
      - ../../projects-php/_shared/nginx/webdev-nginx.conf:/etc/nginx/conf.d/webdev-nginx.conf
