# Dockerfile.ci — Lightweight CI test container for social-bot integration tests.
#
# Does NOT include GPU AI deps (whisper/LLM/TTS/TensorRT).
# Runs the core ROS2 stack with mock sensors only — no real hardware required.
#
# Build:
#   docker build -f docker/Dockerfile.ci \
#     -t saltybot/social-tests-ci:latest \
#     ../../../../     # context = saltylab-firmware root
#
# Run (via compose):
#   docker compose -f docker/docker-compose.ci.yml up --exit-code-from test-runner

FROM ros:humble-ros-base-jammy

LABEL maintainer="sl-jetson"
LABEL description="social-bot integration tests — CI mode (no GPU, mock sensors)"

ENV DEBIAN_FRONTEND=noninteractive
ENV ROS_DISTRO=humble
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# ── System deps ───────────────────────────────────────────────────────────────
RUN apt-get update && apt-get install -y --no-install-recommends \
    python3-dev python3-pip python3-setuptools python3-wheel \
    python3-pytest \
    ros-humble-launch-testing \
    ros-humble-launch-testing-ament-cmake \
    ros-humble-launch-testing-ros \
    ros-humble-rosbag2 \
    ros-humble-rosbag2-storage-default-plugins \
    ros-humble-vision-msgs \
    ros-humble-tf2-ros \
    ros-humble-tf2-geometry-msgs \
    ros-humble-cv-bridge \
    ros-humble-nav-msgs \
    ros-humble-geometry-msgs \
    ros-humble-sensor-msgs \
    ros-humble-std-srvs \
    procps \
    && rm -rf /var/lib/apt/lists/*

# ── Python test deps ──────────────────────────────────────────────────────────
RUN pip3 install --no-cache-dir \
    "pytest>=7.0" \
    "pytest-timeout>=2.1" \
    "pytest-xdist>=3.0"

# ── Workspace ─────────────────────────────────────────────────────────────────
RUN mkdir -p /ros2_ws/src
WORKDIR /ros2_ws

# Copy only the packages needed for the social-bot integration tests
COPY jetson/ros2_ws/src/saltybot_social_msgs  /ros2_ws/src/saltybot_social_msgs/
COPY jetson/ros2_ws/src/saltybot_social       /ros2_ws/src/saltybot_social/
COPY jetson/ros2_ws/src/saltybot_social_face  /ros2_ws/src/saltybot_social_face/
COPY jetson/ros2_ws/src/saltybot_social_nav   /ros2_ws/src/saltybot_social_nav/
COPY jetson/ros2_ws/src/saltybot_social_enrollment /ros2_ws/src/saltybot_social_enrollment/
COPY jetson/ros2_ws/src/saltybot_social_tracking   /ros2_ws/src/saltybot_social_tracking/
COPY jetson/ros2_ws/src/saltybot_social_personality /ros2_ws/src/saltybot_social_personality/
COPY jetson/ros2_ws/src/saltybot_social_tests  /ros2_ws/src/saltybot_social_tests/

# ── Build ─────────────────────────────────────────────────────────────────────
SHELL ["/bin/bash", "-c"]
RUN source /opt/ros/humble/setup.bash && \
    cd /ros2_ws && \
    colcon build \
      --packages-select \
        saltybot_social_msgs \
        saltybot_social \
        saltybot_social_face \
        saltybot_social_nav \
        saltybot_social_enrollment \
        saltybot_social_tracking \
        saltybot_social_personality \
        saltybot_social_tests \
      --symlink-install \
      --cmake-args -DBUILD_TESTING=ON \
    && echo "Build complete"

# ── Test entrypoint ───────────────────────────────────────────────────────────
COPY jetson/ros2_ws/src/saltybot_social_tests/docker/entrypoint-ci.sh /entrypoint-ci.sh
RUN chmod +x /entrypoint-ci.sh

# CI env defaults (all can be overridden via docker-compose environment:)
ENV SOCIAL_TEST_FULL=0
ENV SOCIAL_TEST_SPEECH=0
ENV SOCIAL_STACK_RUNNING=0
ENV ROS_DOMAIN_ID=108

ENTRYPOINT ["/entrypoint-ci.sh"]
CMD ["pytest", "/ros2_ws/src/saltybot_social_tests/test/", "-v", "--timeout=120"]
