FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["OpenWarehouse.auth.api/OpenWarehouse.auth.api.csproj", "OpenWarehouse.auth.api/"]
COPY ["OpenWarehouse.auth.lib/OpenWarehouse.auth.lib.csproj", "OpenWarehouse.auth.lib/"]
COPY ["OpenWarehouse.Common.Lib/OpenWarehouse.Common.Lib.csproj", "OpenWarehouse.Common.Lib/"]
COPY ["Kafka.Lib/Kafka.Lib.csproj", "Kafka.Lib/"]
RUN dotnet restore "OpenWarehouse.auth.api/OpenWarehouse.auth.api.csproj"
COPY . .
WORKDIR "/src/OpenWarehouse.auth.api"
RUN dotnet build "OpenWarehouse.auth.api.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "OpenWarehouse.auth.api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "OpenWarehouse.auth.api.dll"]

USER root
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*

USER $APP_UID

