<%#
 Copyright 2019-2025 the original author or authors from the JHipster project.
 This file is part of the JHipster project, see https://www.jhipster.tech/
 for more information.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-%>
# 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
# First install nodejs - required to build generated client app
WORKDIR /app
RUN apt-get update -yq && apt-get install -yq curl
RUN curl -sL https://deb.nodesource.com/setup_22.x | bash - && \
    apt-get update && \
    apt-get install -yq nodejs && \
    rm -rf /var/lib/apt/lists/*

<%_ if(!skipClient && clientFramework === "Blazor") { _%>
# install blazor build tools only if INCLUDE_BLAZOR is set to true
ARG INCLUDE_BLAZOR=false
RUN if [ "$INCLUDE_BLAZOR" = "true" ]; then dotnet tool install -g Microsoft.Web.LibraryManager.Cli ; fi
RUN if [ "$INCLUDE_BLAZOR" = "true" ]; then dotnet tool install -g Excubo.WebCompiler ; fi
ENV PATH="${PATH}:/root/.dotnet/tools"
<%_ } _%>
# Restore dependencies of .net core projects taking advantage of docker layer caching
COPY src/*/*.csproj ./src/
COPY Directory.Packages.props Directory.Packages.props
RUN for file in $(ls src/*.csproj); do mkdir -p ${file%.*} && mv $file ${file%.*}; done
<%_ if(!skipClient && clientFramework === "Blazor") { _%>
COPY src/client/*/*.csproj ./src/client/
RUN for file in $(ls src/client/*.csproj); do mkdir -p ${file%.*} && mv $file ${file%.*}; done
<%_ } _%>
RUN dotnet restore "src/<%= mainProjectDir %><%= pascalizedBaseName %>.csproj"

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

# Final stage/image
FROM mcr.microsoft.com/dotnet/aspnet:9.0-noble AS runtime
EXPOSE 8080
WORKDIR /app
COPY docker-entrypoint-back.sh .
RUN chmod +x /app/docker-entrypoint-back.sh
COPY --from=build /app/out .
ENV ASPNETCORE_ENVIRONMENT=Production
<%_ if(!skipClient && clientFramework === "Blazor") { _%>
ARG INCLUDE_BLAZOR=false
ENV INCLUDE_BLAZOR $INCLUDE_BLAZOR
ENV ServerUrl="https://localhost:8080"
<%_ } _%>

ENTRYPOINT ["./docker-entrypoint-back.sh"]
