FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build

ENV StressRunDuration=0
ARG DEBIAN_FRONTEND=noninteractive

# Setup for nodejs
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash -

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libunwind-dev \
    nodejs \
    git

ARG gitBranch=main

WORKDIR /src
ADD https://api.github.com/repos/dotnet/aspnetcore/git/ref/heads/${gitBranch} /aspnetcore.commit

RUN git init \
    && git fetch https://github.com/aspnet/aspnetcore ${gitBranch} \
    && git reset --hard FETCH_HEAD \
    && git submodule update --init \
    && git remote add origin https://github.com/aspnet/aspnetcore

RUN ./restore.sh
RUN .dotnet/dotnet publish -c Release --no-restore -o /app ./src/Components/benchmarkapps/Wasm.Performance/Driver/Wasm.Performance.Driver.csproj
RUN chmod +x /app/Wasm.Performance.Driver

WORKDIR /app
FROM selenium/standalone-chrome:120.0 as final
COPY --from=build ./app ./
COPY ./exec.sh ./

ENTRYPOINT [ "bash", "./exec.sh" ]
