version: '3.7'
services:
  nginx:
    image: nginxinc/nginx-unprivileged:1.25
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
      - ./cert.pem:/etc/nginx/cert.pem
      - ./key.pem:/etc/nginx/key.pem
    ports:
      - 443:443
    depends_on:
      - backend
    # For linux users
    extra_hosts:
      - 'host.docker.internal:host-gateway'

  database-agent:
    image: mysql:5
    volumes:
      - ./db_data:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: ${DATABASE_PASSWORD}
      MYSQL_DATABASE: ${DATABASE_NAME}
    healthcheck:
      test: mysqladmin ping -h 127.0.0.1 -u root --password=$$MYSQL_ROOT_PASSWORD
      interval: 5s
      timeout: 10s
      retries: 60

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    depends_on:
      - database-agent
    ports:
      - 8008:80
    environment:
      PMA_HOST: database-agent

  backend:
    # --When using yarn local-up build backoffice service image with: docker build . -t backoffice-server
    image: backoffice-server
    depends_on:
      database-agent:
        condition: service_healthy
    restart: unless-stopped
    volumes:
      - ./mnt:/app/mnt
    ports:
      - ${HTTPS_PORT}:${HTTPS_PORT}
      - 8090:8090
    environment:
      - HOSTNAME=${HOSTNAME}
      - HTTPS_PORT=${HTTPS_PORT}
      - ANIMATOR_ROLE=${ANIMATOR_ROLE}
      - ADMIN_ROLE=${ADMIN_ROLE}
      - REDIRECT_URL=${REDIRECT_URL}
      - CLIENT_ID=${CLIENT_ID}
      - CLIENT_SECRET=${CLIENT_SECRET}
      - AUTH_URL=${AUTH_URL}
      - TOKEN_URL=${TOKEN_URL}
      - USERINFO_URL=${USERINFO_URL}
      - DEBUG_MODE=${DEBUG_MODE}
      - DATABASE_USER=${DATABASE_USER}
      - DATABASE_NAME=${DATABASE_NAME}
      - DATABASE_PASSWORD=${DATABASE_PASSWORD}
      - DATABASE_HOST=database-agent
      - MOCK_OAUTH2=${MOCK_OAUTH2}
      - IMAGE_FOLDER=${IMAGE_FOLDER}
      - SGE_API_TOKEN=${SGE_API_TOKEN}
