# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
#WORKDIR /src
COPY ["OpenArchival.docker.sln", "OpenArchival.sln"] 
COPY ["nuget.config", "."]
COPY ["OpenArchival.Blazor/OpenArchival.Blazor.csproj", "OpenArchival.Blazor/"]
COPY ["OpenArchival.DataAccess/OpenArchival.DataAccess.csproj", "OpenArchival.DataAccess/"]
COPY ["OpenArchival.Blazor.FileViewer/OpenArchival.Blazor.FileViewer.csproj", "OpenArchival.Blazor.FileViewer/"]
COPY ["OpenArchival.Blazor.CustomComponents/OpenArchival.Blazor.CustomComponents.csproj", "OpenArchival.Blazor.CustomComponents/"]
COPY ["OpenArchival.Blazor.AdminPages/OpenArchival.Blazor.AdminPages.csproj", "OpenArchival.Blazor.AdminPages/"]
COPY ["OpenArchival.Blazor.AdminPages.Shared/OpenArchival.Blazor.AdminPages.Shared.csproj", "OpenArchival.Blazor.AdminPages/"]
COPY ["OpenArchival.Blazor.Config/OpenArchival.Blazor.Config.csproj", "OpenArchival.Blazor.Config/"]
COPY ["OpenArchival.Blazor.ArchiveDisplay/OpenArchival.Blazor.ArchiveDisplay.csproj", "OpenArchival.Blazor.ArchiveDisplay/"]
COPY ["OpenArchival.Blazor.ArtifactGroupingDisplay/OpenArchival.Blazor.ArtifactGroupingDisplay.csproj", "OpenArchival.Blazor.ArtifactGroupingDisplay/"]
COPY ["OpenArchival.Blazor.Blog/OpenArchival.Blazor.Blog.csproj", "OpenArchival.Blazor.Blog/"]
COPY ["OpenArchival.Blazor.AdminPages.Shared/OpenArchival.Blazor.AdminPages.Shared.csproj", "OpenArchival.Blazor.AdminPages.Shared/"]
COPY ["OpenArchival.Blazor.Theme/OpenArchival.Blazor.Theme.csproj", "OpenArchival.Blazor.Theme/"]
COPY ["OpenArchival.DataAccess.FileAccessManager/OpenArchival.DataAccess.FileAccessManager.csproj", "OpenArchival.DataAccess.FileAccessManager/"]

RUN dotnet restore "/OpenArchival.sln"
COPY . .
WORKDIR "/OpenArchival.Blazor"
RUN dotnet build "./OpenArchival.Blazor.csproj" -c $BUILD_CONFIGURATION -o /app/build


# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./OpenArchival.Blazor.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .

# Create the folder that will be used to store uploads
RUN mkdir /app/OpenArchivalUploads

ENTRYPOINT ["dotnet", "OpenArchival.Blazor.dll"]