FROM ubuntu:22.04

# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive

# Install dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    chrpath \
    cpio \
    debianutils \
    diffstat \
    file \
    gawk \
    gcc \
    git \
    iputils-ping \
    less \
    libacl1 \
    liblz4-tool \
    locales \
    ovmf \
    python3 \
    python3-git \
    python3-jinja2 \
    python3-pexpect \
    python3-pip \
    python3-subunit \
    qemu-system-data \
    qemu-system-x86 \
    qemu-utils \
    socat \
    sudo \
    texinfo \
    tree \
    unzip \
    vim \
    wget \
    xz-utils \
    zstd \
    && rm -rf /var/lib/apt/lists/*

# Set up locale
RUN locale-gen en_US.UTF-8
ENV LANG=en_US.UTF-8
ENV LANGUAGE=en_US:en
ENV LC_ALL=en_US.UTF-8

# Create build user matching host UID/GID
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG KVM_GID=992
RUN groupadd -g ${GROUP_ID} builder && \
    useradd -u ${USER_ID} -g ${GROUP_ID} -ms /bin/bash builder && \
    groupadd -g ${KVM_GID} kvm && \
    usermod -a -G kvm builder

# Enable compiler cache for performance
ENV USE_CCACHE=1
ENV CCACHE_DIR=/workspace/.ccache

# Set working directory
WORKDIR /workspace

# Change ownership of workspace to yocto user
RUN chown -R builder:builder /workspace

# Switch to yocto user
USER builder

# Default command to start interactive shell
CMD ["/bin/bash"]