FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

# Copy Common project
COPY ["src/LiquidCode.Tester.Common/LiquidCode.Tester.Common.csproj", "src/LiquidCode.Tester.Common/"]

# Copy Gateway project
COPY ["src/LiquidCode.Tester.Gateway/LiquidCode.Tester.Gateway.csproj", "src/LiquidCode.Tester.Gateway/"]

# Restore dependencies
RUN dotnet restore "src/LiquidCode.Tester.Gateway/LiquidCode.Tester.Gateway.csproj"

# Copy all source files
COPY . .

# Build
WORKDIR "/src/src/LiquidCode.Tester.Gateway"
RUN dotnet build "./LiquidCode.Tester.Gateway.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./LiquidCode.Tester.Gateway.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# Create directory for package downloads
RUN mkdir -p /tmp/packages

ENV ASPNETCORE_URLS=http://+:8080

ENTRYPOINT ["dotnet", "LiquidCode.Tester.Gateway.dll"]
