FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC
ENV PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig

RUN dpkg --add-architecture i386 && apt-get update && apt-get install -y --no-install-recommends \
        git cmake ninja-build gperf ccache dfu-util device-tree-compiler \
        wget python3 python3-dev python3-pip python3-venv python3-setuptools \
        python3-tk python3-wheel xz-utils file make gcc \
        gcc-multilib g++-multilib libc6-dev-i386 \
        libsdl2-dev:i386 libsdl2-image-dev:i386 \
        libmagic1 mtools pkg-config ca-certificates unzip \
        protobuf-compiler sudo \
    && rm -rf /var/lib/apt/lists/*

# Remove the default ubuntu:24.04 'ubuntu' user (UID 1000) so 'dev' can take
# UID 1000 — required for --userns=keep-id to map host UID 1000 to 'dev'.
RUN userdel -r ubuntu 2>/dev/null || true \
 && useradd -m -u 1000 -s /bin/bash dev \
 && echo 'dev ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/dev \
 && chmod 440 /etc/sudoers.d/dev
USER dev
WORKDIR /home/dev

RUN python3 -m venv /home/dev/.venv
ENV PATH="/home/dev/.venv/bin:${PATH}"
RUN pip install --no-cache-dir west pytest pyelftools pyyaml intelhex protobuf grpcio-tools

# The repo is expected to be bind-mounted here at runtime:
#   podman run -v ~/circuitpython:/home/dev/circuitpython:Z --userns=keep-id ...
# On first run, inside the container do:
#   cd ~/circuitpython/ports/zephyr-cp
#   west init -l zephyr-config
#   west update
#   west zephyr-export
#   pip install -r zephyr/scripts/requirements.txt
#   pip install -r ../../requirements-dev.txt
#   west sdk install -t x86_64-zephyr-elf
#   python ../../tools/ci_fetch_deps.py zephyr-cp
WORKDIR /home/dev/circuitpython/ports/zephyr-cp
CMD ["/bin/bash"]
