version: "3"

services:
  nginx:
    container_name: nginx
    image: nginx:1.17
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./logs/nginx:/var/log/nginx
    ports:
      - 80:80
    depends_on:
      - frontend
      - backend

  backend:
    container_name: backend
    restart: unless-stopped
    build:
      context: backend
      dockerfile: Dockerfile
    env_file:
      - .env
    environment:
      PYTHONPATH: .
      DATABASE_URL: postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_USER}
    volumes:
      - ./backend:/app
      - ./logs/backend:/logs
    depends_on:
      - postgres

  frontend:
    container_name: frontend
    build:
      context: frontend
      dockerfile: Dockerfile
    volumes:
      - ./frontend/app:/app
    ports:
      - 3000:3000
    environment:
      NODE_ENV: development
      CHOKIDAR_USEPOLLING: "true"

  postgres:
    container_name: postgres
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    ports:
      - 5432:5432
    volumes:
      - postgres_data:/var/lib/postgresql/data

  keycloak:
    container_name: keycloak
    image: jboss/keycloak:12.0.4
    environment:
      DB_VENDOR: POSTGRES
      DB_SCHEMA: public
      DB_ADDR: keycloak_postgres
      DB_DATABASE: ${KEYCLOAK_DB_DATABASE}
      DB_USER: ${KEYCLOAK_DB_USER}
      DB_PASSWORD: ${KEYCLOAK_DB_PASSWORD}
      KEYCLOAK_USER: ${KEYCLOAK_ADMIN_USERNAME}
      KEYCLOAK_PASSWORD: ${KEYCLOAK_ADMIN_PASSWORD}
      JDBC_PARAMS: "useSSL=false"
    ports:
      - 8080:8080
    depends_on:
      - keycloak_postgres

  keycloak_postgres:
    container_name: keycloak_postgres
    image: postgres
    volumes:
      - keycloak_postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: ${KEYCLOAK_DB_DATABASE}
      POSTGRES_USER: ${KEYCLOAK_DB_USER}
      POSTGRES_PASSWORD: ${KEYCLOAK_DB_PASSWORD}

volumes:
  postgres_data:
  keycloak_postgres_data: