FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
WORKDIR /src
COPY src/TcpEcho/TcpEcho.csproj TcpEcho/
RUN dotnet restore TcpEcho/TcpEcho.csproj
COPY src/TcpEcho/ TcpEcho/
RUN dotnet publish TcpEcho/TcpEcho.csproj -c Release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine
ARG VERSION=dev
ARG REVISION=unknown
ARG CREATED=""
# OCI labels: Gitea's package registry displays these on the package page and, when
# image.source matches a repository URL, links the package to that repository.
LABEL org.opencontainers.image.title="tcp-echo-server" \
      org.opencontainers.image.description="Minimal .NET 8 TCP echo server that prefixes every reply with its instance identifier. Deployed as two instances behind Traefik on ports 9098 and 9099." \
      org.opencontainers.image.source="https://gitea.eitczech.com/public/tcp-echo-server" \
      org.opencontainers.image.url="https://gitea.eitczech.com/public/tcp-echo-server" \
      org.opencontainers.image.documentation="https://gitea.eitczech.com/public/tcp-echo-server/src/branch/main/README.md" \
      org.opencontainers.image.vendor="eitczech" \
      org.opencontainers.image.licenses="MIT" \
      org.opencontainers.image.version="${VERSION}" \
      org.opencontainers.image.revision="${REVISION}" \
      org.opencontainers.image.created="${CREATED}"
WORKDIR /app
COPY --from=build /app .
ENV PORT=9099
EXPOSE 9099
USER 1654
ENTRYPOINT ["dotnet", "TcpEcho.dll"]
