# RESTler, built natively for the host architecture.
#
# The upstream repo publishes no GitHub releases at all, so there is no prebuilt
# binary to download on any architecture. It does ship a build script, and both
# base images below publish linux/arm64 manifests, so an Apple-silicon host can
# build this natively rather than under emulation. The compiler is .NET 8 (the
# repo's global.json pins the SDK) and the fuzzing engine is pure Python.
#
# Pinned to a tag; the built image digest and the clone SHA both get recorded
# into the results so a run is reproducible.
ARG RESTLER_TAG=v9.3.1

FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS builder
ARG RESTLER_TAG
RUN apk add --no-cache python3 py3-pip git
RUN git clone --depth 1 --branch ${RESTLER_TAG} https://github.com/microsoft/restler-fuzzer /src
WORKDIR /src
# Record what we actually built, for the versions manifest.
RUN git rev-parse HEAD > /restler-commit.txt
RUN python3 build-restler.py --dest_dir /build

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS target
RUN apk add --no-cache python3 py3-pip curl bash
# The engine imports these at runtime; Alpine's Python needs a venv for pip.
RUN python3 -m venv /venv && /venv/bin/pip install --no-cache-dir applicationinsights requests
ENV PATH="/venv/bin:$PATH"
COPY --from=builder /build /RESTler
COPY --from=builder /restler-commit.txt /RESTler/restler-commit.txt
WORKDIR /work
