FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

# A/B test host for Mikulas's dm_setup_md_queue table_devices_lock fix.
# Kernel is built at `docker run` time (not during `docker build`).

RUN apt-get update && apt-get install -y --no-install-recommends \
        bc \
        bison \
        build-essential \
        ca-certificates \
        cpio \
        curl \
        dwarves \
        e2fsprogs \
        flex \
        libelf-dev \
        libssl-dev \
        mmdebstrap \
        openssh-client \
        patch \
        qemu-system-x86 \
        qemu-utils \
        rsync \
        util-linux \
        xz-utils \
    && curl -fsSL -o /tmp/debian-archive-keyring.deb \
        https://deb.debian.org/debian/pool/main/d/debian-archive-keyring/debian-archive-keyring_2025.1_all.deb \
    && dpkg -i /tmp/debian-archive-keyring.deb \
    && rm -f /tmp/debian-archive-keyring.deb \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /work
COPY poc.c run.sh create-image-userns.sh repro.sh build-kernel.sh test-patch.sh \
     0001-dm-fix-race-when-loading-and-unloading-a-table.patch ./
RUN chmod +x run.sh create-image-userns.sh repro.sh build-kernel.sh test-patch.sh

RUN mkdir -p /artifacts /kernel

ENV OUTPUT_DIR=/artifacts \
    KERNEL_VERSION=6.6.144 \
    VM_PORT=10057 \
    RUN_TIMEOUT_SEC=240

CMD ["./test-patch.sh"]
