# Android Cast — Docker build + OTA staging publish
#
#   export OTA_BASE_URL=https://apps.f0xx.org
#   docker compose -f docker-compose.build.yml run --rm android-build
#
# Outputs on the host: ./out/android_cast-latest.apk  ./out/ota/v0/...
#
# Publish APK only from an existing build (skip compile):
#   docker compose -f docker-compose.build.yml run --rm ota-publish-only

services:
  android-build:
    build:
      context: .
      dockerfile: Dockerfile
    image: androidcast-ci:latest
    working_dir: /workspace
    volumes:
      - .:/workspace
      - gradle-cache:/root/.gradle
    environment:
      OTA_BASE_URL: ${OTA_BASE_URL:-}
      OTA_CHANNEL: ${OTA_CHANNEL:-staging}
      GRADLE_TASK: ${GRADLE_TASK:-assembleDebug}
      SKIP_NATIVE: ${SKIP_NATIVE:-0}
      SKIP_TESTS: ${SKIP_TESTS:-0}
      RELEASE_NOTES: ${RELEASE_NOTES:-}
      OUT_DIR: /workspace/out
    command: ["./scripts/ci-build-and-publish-ota.sh"]

  ota-publish-only:
    image: androidcast-ci:latest
    working_dir: /workspace
    volumes:
      - .:/workspace
    environment:
      OTA_BASE_URL: ${OTA_BASE_URL:?set OTA_BASE_URL}
      OTA_CHANNEL: ${OTA_CHANNEL:-staging}
      APK_PATH: ${APK_PATH:-/workspace/app/build/outputs/apk/debug/app-debug.apk}
      RELEASE_NOTES: ${RELEASE_NOTES:-}
    entrypoint: ["/bin/bash", "-c"]
    command:
      - |
        set -euo pipefail
        ./scripts/generate-ota-v0.sh "$${APK_PATH}" "$${OTA_BASE_URL}" /workspace/out/ota-publish "$${OTA_CHANNEL}"
        mkdir -p /workspace/out/ota
        cp -rf /workspace/out/ota-publish/v0 /workspace/out/ota/
        cp -f "$${APK_PATH}" /workspace/out/android_cast-latest.apk
        echo "Published to /workspace/out/ota/v0/ota/channel/$${OTA_CHANNEL}.json"

volumes:
  gradle-cache:
