services:
  disk-image:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        USER_ID: ${USER_ID:-1000}
        GROUP_ID: ${GROUP_ID:-1000}
    container_name: disk-image
    hostname: disk-image
    working_dir: /workspace
    network_mode: "host"
    volumes:
      - ./:/workspace
      - ../:/repo
    tty: true
    stdin_open: true
    command: >
      bash -c "
      source /workspace/yocto/poky/oe-init-build-env /workspace/build &&
      cp /workspace/conf/* /workspace/build/conf/ &&
      bitbake fcb-looper-image &&
      echo 'Build complete. Image files available in output directory.'
      "

  qemu-server:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        USER_ID: ${USER_ID:-1000}
        GROUP_ID: ${GROUP_ID:-1000}
        KVM_GID: ${KVM_GID:-992}
    container_name: qemu-server
    hostname: qemu-server
    working_dir: /workspace
    network_mode: "host"
    volumes:
      - ./:/workspace
      - ../:/repo
    devices:
      - /dev/kvm:/dev/kvm
    tty: true
    stdin_open: true
    command: >
      bash -c "
      echo 'Starting QEMU with host networking...' &&
      echo 'VNC will be available on localhost:5901' &&
      echo 'SSH will be available on localhost:2222' &&
      echo 'QEMU monitor on localhost:4444' &&
      qemu-system-x86_64 -accel kvm -cpu host -m 4096 -smp 4 -kernel /workspace/build/tmp/deploy/images/genericx86-64/bzImage -drive file=/workspace/build/tmp/deploy/images/genericx86-64/fcb-looper-image-genericx86-64.rootfs.ext4,if=virtio,format=raw,cache=writeback -netdev user,id=net0,hostfwd=tcp:127.0.0.1:2222-:22,hostfwd=tcp:127.0.0.1:8080-:8080 -device virtio-net-pci,netdev=net0 -device virtio-vga -vnc 127.0.0.1:1 -monitor telnet:127.0.0.1:4444,server,nowait -serial stdio -append 'root=/dev/vda rw console=ttyS0 console=tty0'
      "