version: '3.9'

services:
  app:
    build:
      context: ..
      dockerfile: .devcontainer/Dockerfile
    volumes:
      - ..:/workspace:cached
    command: sleep infinity
  postgres:
    image: 'postgres:14.5-alpine'
    environment:
      - POSTGRES_DB=automatisch
      - POSTGRES_USER=automatisch_user
      - POSTGRES_PASSWORD=automatisch_password
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}']
      interval: 10s
      timeout: 5s
      retries: 5
    ports:
      - '5432:5432'
    expose:
      - 5432
  redis:
    image: 'redis:7.0.4-alpine'
    volumes:
      - redis_data:/data
    ports:
      - '6379:6379'
    expose:
      - 6379
  keycloak:
    image: quay.io/keycloak/keycloak:21.1
    restart: always
    environment:
      - KEYCLOAK_ADMIN=admin
      - KEYCLOAK_ADMIN_PASSWORD=admin
      - KC_DB=postgres
      - KC_DB_URL_HOST=postgres
      - KC_DB_URL_DATABASE=keycloak
      - KC_DB_USERNAME=automatisch_user
      - KC_DB_PASSWORD=automatisch_password
      - KC_HEALTH_ENABLED=true
    ports:
      - "8080:8080"
    command: start-dev
    depends_on:
      - postgres
    healthcheck:
      test: "curl -f http://localhost:8080/health/ready || exit 1"
    volumes:
      - keycloak:/opt/keycloak/data/
    expose:
      - 8080

volumes:
  postgres_data:
  redis_data:
  keycloak:
