version: '3.8'

services:
  keycloak-db:
    image: postgres:15
    environment:
      POSTGRES_DB: keycloak # CHANGE THIS IN PROD 
      POSTGRES_USER: keycloak # CHANGE THIS IN PROD
      POSTGRES_PASSWORD: password # CHANGE THIS IN PROD
    volumes:
      - ./data/keycloak-db:/var/lib/postgresql/data
    networks:
      - soa

  keycloak:
    image: quay.io/keycloak/keycloak:24.0.3
    command: start-dev
    ports:
      - "8080:8080"
    environment:
      KC_DB: postgres
      KC_DB_URL_HOST: keycloak-db
      KC_DB_URL_DATABASE: keycloak
      KC_DB_USERNAME: keycloak
      KC_DB_PASSWORD: password
      KEYCLOAK_ADMIN: admin
      KEYCLOAK_ADMIN_PASSWORD: admin
      KC_HOSTNAME_URL: https://auth.local
      KC_PROXY: edge
    depends_on:
      - keycloak-db
    networks:
      - soa

  public_api:
    build:
      context: ./public
    depends_on:
      - keycloak
      - mysql
    expose:
      - "5001"
    networks:
      - soa

  user_api:
    build:
      context: ./private
    depends_on:
      - keycloak
      - mysql
    expose:
      - "5002"
    networks:
      - soa

  apache:
    build:
      context: ./apache
    container_name: apache
    ports:
      - "443:443"
      - "80:80"
    depends_on:
      - keycloak
      - public_api
      - user_api
    volumes:
      - ./apache/logs:/usr/local/apache2/conf/logs
    environment:
      APACHE_LOG_DIR: /usr/local/apache2/conf/logs
    networks:
      - soa

  mysql:
    image: mysql:8
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: mydb
      MYSQL_USER: myuser
      MYSQL_PASSWORD: mypassword
    ports:
      - "3306:3306"
    volumes:
      - ./data/mysql-data:/var/lib/mysql
    networks:
      - soa

  redis:
    image: redis:7
    ports:
      - "6379:6379"
    networks:
      - soa


networks:
  soa:
    driver: bridge

