services:
  landing-fe:
    image: nginx:1.27-alpine
    depends_on:
      - gitea-fe
      - crashes-fe
      - build-fe
    ports:
      - "${LANDING_HTTP_PORT}:8080"
    volumes:
      - ../:/workspace:ro
      - ./nginx/landing.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - appnet
    restart: unless-stopped

  gitea-fe:
    image: nginx:1.27-alpine
    depends_on:
      - gitea
    ports:
      - "${GITEA_FE_PORT}:8080"
    volumes:
      - ./nginx/gitea-fe.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - appnet
    restart: unless-stopped

  crashes-fe:
    image: nginx:1.27-alpine
    depends_on:
      - crash-php
    ports:
      - "${CRASHES_FE_PORT}:8080"
    volumes:
      - ../:/workspace
      - ./nginx/crashes-fe.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - appnet
    restart: unless-stopped

  build-fe:
    image: nginx:1.27-alpine
    depends_on:
      - build-php
    ports:
      - "${BUILD_FE_PORT}:8080"
    volumes:
      - ../:/workspace
      - ./nginx/build-fe.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - appnet
    restart: unless-stopped

  build-php:
    build:
      context: .
      dockerfile: images/build-php-fpm/Dockerfile
    depends_on:
      - mariadb
    volumes:
      - ../:/workspace
      - /var/run/docker.sock:/var/run/docker.sock
      - ./runtime/build-config.php:/workspace/examples/build_console/backend/config/config.php
      - ./runtime/ota-artifacts:/workspace/orchestration/runtime/ota-artifacts
    networks:
      - appnet
    restart: unless-stopped

  crash-php:
    build:
      context: .
      dockerfile: images/crash-php-fpm/Dockerfile
    depends_on:
      - mariadb
    volumes:
      - ../:/workspace
      - ./runtime/crash-config.php:/workspace/examples/crash_reporter/backend/config/config.php
    networks:
      - appnet
    restart: unless-stopped

  mariadb:
    image: mariadb:11.4
    environment:
      MARIADB_ROOT_PASSWORD: "${MARIADB_ROOT_PASSWORD}"
      MARIADB_DATABASE: "${MARIADB_DATABASE}"
      MARIADB_USER: "${MARIADB_USER}"
      MARIADB_PASSWORD: "${MARIADB_PASSWORD}"
    command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]
    volumes:
      - mariadb-data:/var/lib/mysql
      - ./runtime/db-init:/docker-entrypoint-initdb.d:ro
    networks:
      - appnet
    restart: unless-stopped

  gitea:
    image: gitea/gitea:1.22
    environment:
      USER_UID: "1000"
      USER_GID: "1000"
      GITEA__server__ROOT_URL: "http://localhost:${GITEA_FE_PORT}/"
      GITEA__server__DOMAIN: "localhost"
      GITEA__server__HTTP_PORT: "3000"
      GITEA__server__PROTOCOL: "http"
      GITEA__security__INSTALL_LOCK: "true"
      GITEA__service__DISABLE_REGISTRATION: "true"
      GITEA__database__DB_TYPE: "sqlite3"
    volumes:
      - gitea-data:/data
    networks:
      - appnet
    restart: unless-stopped

networks:
  appnet:
    driver: bridge
    ipam:
      config:
        - subnet: 10.203.0.0/24

volumes:
  mariadb-data:
  gitea-data:
