FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build-env
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
RUN git clone --depth 1 --single-branch https://github.com/artempyanykh/marksman.git /app
WORKDIR /app
ARG MARKSMAN_VERSION
RUN git fetch origin tag "${MARKSMAN_VERSION}" \
    && git switch --detach "${MARKSMAN_VERSION}" \
    && sed -e 's/--dirty/--tag/g' -i Marksman/Marksman.fsproj
RUN dotnet restore
RUN dotnet publish -c Release -o out Marksman/Marksman.fsproj

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine
RUN adduser -D -s /sbin/nologin -h /app marksman
USER marksman
WORKDIR /app
COPY --from=build-env /app/out .
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
ENTRYPOINT ["/app/marksman"]
