# Based on Microsoft's docker samples for dotnet core
# available at https://github.com/dotnet/dotnet-docker/tree/master/samples/aspnetapp
FROM mcr.microsoft.com/dotnet/sdk:9.0-noble AS build

WORKDIR /app

# Restore dependencies of .net core projects taking advantage of docker layer caching
COPY src/*/*.csproj ./src/
COPY src/client/*/*.csproj ./src/client/
COPY Directory.Packages.props Directory.Packages.props
RUN for file in $(ls src/client/*.csproj); do mkdir -p ${file%.*} && mv $file ${file%.*}; done
RUN dotnet restore "src/client/<%= pascalizedBaseName %>.Client/<%= pascalizedBaseName %>.Client.csproj"
RUN dotnet tool install -g Microsoft.Web.LibraryManager.Cli
RUN dotnet tool install -g Excubo.WebCompiler
ENV PATH="${PATH}:/root/.dotnet/tools"

# Copy everything else and build app
COPY . .
WORKDIR src/client/<%= pascalizedBaseName %>.Client
RUN dotnet publish "<%= pascalizedBaseName %>.Client.csproj" -c Release -o /app/out

FROM nginx:alpine AS final
WORKDIR /usr/share/nginx/html
ENV PORT 80
ENV ServerUrl="https://localhost:8080"
COPY --from=build /app/out/wwwroot .
COPY ./nginx.conf /etc/nginx/
COPY ./default.conf /etc/nginx/conf.d/
COPY ./docker-entrypoint-front.sh /docker-entrypoint.d/
