version: '3.8'

services:
  # Test service - runs tests only
  test:
    build:
      context: .
      dockerfile: Dockerfile
      target: test
    container_name: jellytau-test
    volumes:
      - .:/app
    environment:
      - RUST_BACKTRACE=1
    command: bash -c "bun run test && cd src-tauri && cargo test && cd .. && echo 'All tests passed!'"

  # Android build service - builds APK after tests pass
  android-build:
    build:
      context: .
      dockerfile: Dockerfile
      target: android-build
    container_name: jellytau-android-build
    volumes:
      - .:/app
      - android-cache:/root/.cargo
      - android-bun-cache:/root/.bun
    environment:
      - RUST_BACKTRACE=1
      - ANDROID_HOME=/opt/android-sdk
    depends_on:
      - test
    ports:
      - "5172:5172"  # In case you want to run dev server

  # Linux desktop packages - deb + rpm + pacman into ./dist
  desktop-linux-build:
    build:
      context: .
      dockerfile: Dockerfile
      target: desktop-linux-build
      args:
        # Defaults to the registry builder (Dockerfile's ARG). Point at a locally
        # built builder with: BUILDER_IMAGE=jellytau-builder:latest docker compose ...
        BUILDER_IMAGE: ${BUILDER_IMAGE:-gitea.tourolle.paris/dtourolle/jellytau-builder:latest}
    container_name: jellytau-desktop-linux-build
    volumes:
      - .:/app
      - cargo-cache:/root/.cargo
      - bun-cache:/root/.bun
    environment:
      - RUST_BACKTRACE=1
      - OUTPUT_DIR=/app/dist
    command: bash -c "OUTPUT_DIR=/app/dist scripts/build-desktop-linux.sh"

  # Arch Linux package (.pkg.tar.zst via makepkg) into ./dist
  arch-build:
    build:
      context: .
      dockerfile: Dockerfile.arch
    container_name: jellytau-arch-build
    volumes:
      - ./dist:/out
    environment:
      - RUST_BACKTRACE=1
      - OUTPUT_DIR=/out

  # Windows cross-compile (MSVC via cargo-xwin). Emits NSIS installer + .exe to
  # ./dist. Override WIN_BUNDLES=none for exe-only.
  windows-cross:
    build:
      context: .
      dockerfile: Dockerfile
      target: windows-cross
      args:
        BUILDER_IMAGE: ${BUILDER_IMAGE:-gitea.tourolle.paris/dtourolle/jellytau-builder:latest}
    container_name: jellytau-windows-cross
    volumes:
      - .:/app
      - cargo-cache:/root/.cargo
      - bun-cache:/root/.bun
    environment:
      - RUST_BACKTRACE=1
      - OUTPUT_DIR=/app/dist
      - WIN_BUNDLES=${WIN_BUNDLES:-nsis}
    command: bash -c "OUTPUT_DIR=/app/dist WIN_BUNDLES=${WIN_BUNDLES:-nsis} scripts/build-windows-cross.sh"

  # Development container - for interactive development
  dev:
    build:
      context: .
      dockerfile: Dockerfile
      target: builder
    container_name: jellytau-dev
    volumes:
      - .:/app
      - cargo-cache:/root/.cargo
      - bun-cache:/root/.bun
      - node-modules:/app/node_modules
    environment:
      - RUST_BACKTRACE=1
      - ANDROID_HOME=/opt/android-sdk
      - NDK_HOME=/opt/android-sdk/ndk/27.0.11902837
    working_dir: /app
    stdin_open: true
    tty: true
    command: /bin/bash

volumes:
  cargo-cache:
  bun-cache:
  android-cache:
  android-bun-cache:
  node-modules:
