FROM mirror.gcr.io/library/debian:bookworm-20250811 AS base

ENV DEBIAN_FRONTEND=noninteractive
ENV OVERRIDE_BAZEL_WRAPPER_DOWNLOAD_DIR=/tmp/cw_bazel

RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y sudo systemd init systemd-journal-remote nginx jq adb

RUN groupadd kvm
COPY tools/testutils/cw/setup.service /etc/systemd/system/setup.service
RUN systemctl enable setup

FROM base AS with_bazel

RUN --mount=source=.,target=/mnt,type=bind \
  /mnt/tools/buildutils/installbazel.sh

FROM with_bazel AS with_cuttlefish_packages

RUN --mount=source=.,target=/mnt,type=bind apt-get install -y \
  /mnt/cuttlefish-base_*_*64.deb \
  /mnt/cuttlefish-metrics_*_*64.deb \
  /mnt/cuttlefish-user_*_*64.deb \
  /mnt/cuttlefish-orchestration_*_*64.deb

FROM with_cuttlefish_packages

RUN usermod -aG kvm root
RUN usermod -aG cvdnetwork root

# User used on Github CI using rootfull podman.
RUN useradd -m "testrunner"
RUN usermod -aG kvm testrunner
RUN usermod -aG cvdnetwork testrunner

CMD [ "/usr/sbin/init" ]

