# Standalone P10 host image. The run coordinator supplies SOURCE_REVISION from
# the current checkout and uses a run-scoped image name in compose.yml.
# Grpc.Tools linux_arm64 protoc exits139 under Apple Silicon Docker.
# Build portable IL on amd64; the Host runtime remains native, as in docker-dev.
FROM --platform=linux/amd64 mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore src/Server/ZB.MOM.WW.OtOpcUa.Host/ZB.MOM.WW.OtOpcUa.Host.csproj --disable-parallel -m:1
ARG SOURCE_REVISION
ARG SOURCE_TREE_HASH
RUN test -n "$SOURCE_REVISION" && test -n "$SOURCE_TREE_HASH" && dotnet publish \
    src/Server/ZB.MOM.WW.OtOpcUa.Host/ZB.MOM.WW.OtOpcUa.Host.csproj \
    -c Release -o /app --no-restore -m:1 -p:SourceRevisionId="$SOURCE_REVISION"
RUN printf '{"revision":"%s","tree_hash":"%s"}\n' "$SOURCE_REVISION" "$SOURCE_TREE_HASH" > /app/grpc-data-source.json

# These fixture projects are intentionally outside the solution. Restore their
# already-cached dependency graph explicitly and serialize emulated MSBuild.
# Vulnerability auditing belongs to the normal solution restore, not a second
# network audit of identical dependencies during fixture packaging.
RUN dotnet restore scripts/validation/grpc-data/node-probe/GrpcDataNodeProbe.csproj --disable-parallel -m:1 -p:NuGetAudit=false
RUN dotnet publish scripts/validation/grpc-data/node-probe/GrpcDataNodeProbe.csproj -c Release -o /node-probe --no-restore -m:1

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
WORKDIR /app
COPY --from=build /app ./
# Preserve Host-resolved dependency versions; this fixture assembly has no extra packages.
COPY --from=build /node-probe/GrpcDataNodeProbe.dll ./
COPY --from=build /node-probe/GrpcDataNodeProbe.deps.json ./
EXPOSE 9000 4053 4055 4056 4057 4840 9001
ENTRYPOINT ["dotnet", "OtOpcUa.Host.dll"]

FROM build AS migrator
RUN dotnet tool install --global dotnet-ef --version 10.0.7
ENV PATH="${PATH}:/root/.dotnet/tools"
WORKDIR /src
ENTRYPOINT ["dotnet", "ef", "database", "update", \
    "--no-build", "--configuration", "Release", \
    "--project", "src/Core/ZB.MOM.WW.OtOpcUa.Configuration", \
    "--startup-project", "src/Core/ZB.MOM.WW.OtOpcUa.Configuration"]

FROM build AS seed-build
RUN dotnet restore scripts/validation/grpc-data/seed/GrpcDataSeed.csproj --disable-parallel -m:1 -p:NuGetAudit=false
RUN dotnet publish scripts/validation/grpc-data/seed/GrpcDataSeed.csproj -c Release -o /seed --no-restore -m:1

FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS seeder
WORKDIR /seed
COPY --from=seed-build /seed ./
ENTRYPOINT ["dotnet", "GrpcDataSeed.dll"]
