# syntax=docker/dockerfile:1

# Build:  docker build -t datatransfer .
# Run:    docker run -d --name datatransfer --restart unless-stopped -p 8080:8080 \
#           -e AllowedHosts=transfer.example.ch \
#           -e ForwardedHeaders__KnownNetworks__0=172.16.0.0/12 \
#           datatransfer
#
# Put a reverse proxy with HTTPS in front of the container: browsers only allow the end-to-end encryption on HTTPS
# pages. Any setting of appsettings.json can be overridden with environment variables ("Section__Key").

# The build runs on the build machine's architecture. Its output is portable .NET code, so the same Dockerfile also
# produces arm64 images, e.g. for a Raspberry Pi: docker buildx build --platform linux/arm64 -t datatransfer .
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src

# Restore first, so the package layer stays cached until a project file changes. The SDK only restores the package with
# blazor.web.js when it sees .razor files, which are not copied yet, so it is requested explicitly.
COPY DataTransfer/DataTransfer.csproj DataTransfer/
COPY DataTransfer.Client/DataTransfer.Client.csproj DataTransfer.Client/
RUN dotnet restore DataTransfer/DataTransfer.csproj -p:RequiresAspNetWebAssets=true

COPY . .
RUN dotnet publish DataTransfer/DataTransfer.csproj -c Release -o /app --no-restore -p:UseAppHost=false

# Minimal runtime image: no shell or package manager, runs as the non-root user "app".
FROM mcr.microsoft.com/dotnet/aspnet:10.0-noble-chiseled AS final
WORKDIR /app
COPY --from=build /app .

# The base image sets ASPNETCORE_HTTP_PORTS=8080 and ASPNETCORE_ENVIRONMENT defaults to Production.
USER $APP_UID
EXPOSE 8080
ENTRYPOINT ["dotnet", "DataTransfer.dll"]
