# syntax=docker.io/docker/dockerfile:1.7-labs
# Copyright 2025 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

ARG SMOKE_TEST=0
ARG IMAGE_PREFIX=local/
ARG IMAGE_TAG=latest
FROM ${IMAGE_PREFIX}syz-cluster-build:${IMAGE_TAG} AS builder

# Regular setup (SMOKE_TEST=0)
FROM debian:bookworm AS setup-0
RUN apt-get update && \
    apt-get install -y qemu-system openssh-client curl cpp gcc git

# Install clang tools.
RUN apt-get install -y -q gnupg software-properties-common apt-transport-https
RUN curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN echo "deb http://apt.llvm.org/bookworm/ llvm-toolchain-bookworm-20 main" | tee /etc/apt/sources.list.d/llvm-20.list
RUN apt-get update --allow-releaseinfo-change
RUN apt-get install -y -q --no-install-recommends llvm-20 clang-20 clang-format-20
RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-20 100
RUN update-alternatives --install /usr/bin/llvm-addr2line llvm-addr2line /usr/bin/llvm-addr2line-20 100
RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-20 100

# Smoke test setup (SMOKE_TEST=1)
FROM debian:bookworm-slim AS setup-1
# Skip heavy installs for smoke test
RUN echo "Smoke test mode: skipping dependencies"

FROM setup-${SMOKE_TEST} AS final

# pkg/osutil uses syzkaller user for sandboxing.
RUN useradd --create-home syzkaller
RUN git config --system --add safe.directory '*'

COPY --from=builder /build/bin/ /syzkaller/bin/
COPY --from=builder /build/syz-cluster/bin/fuzz-action /bin/fuzz-action
COPY sys/linux/test /syzkaller/sys/linux/test

ENTRYPOINT ["/bin/fuzz-action"]
