Created
June 29, 2024 15:37
-
-
Save HamidMolareza/a62e534cbdfa942e4c39c3ed1c9cc527 to your computer and use it in GitHub Desktop.
dockerfile template for ASP project + test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ["./src/Api/ApiApp.csproj", "./"] | |
RUN dotnet restore "ApiApp.csproj" | |
COPY ./src/Api/ . | |
WORKDIR "/src/" | |
RUN dotnet build "ApiApp.csproj" -c $BUILD_CONFIGURATION -o /app/build | |
# Test stage | |
FROM build AS test | |
COPY ./src/TestsProject ./TestsProject | |
WORKDIR "/src/TestsProject" | |
RUN dotnet test "TestProject.csproj" -c $BUILD_CONFIGURATION | |
FROM build AS publish | |
ARG BUILD_CONFIGURATION=Release | |
RUN dotnet publish "ApiApp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false | |
FROM base AS final | |
WORKDIR /app | |
COPY --from=publish /app/publish . | |
ENTRYPOINT ["dotnet", "ApiApp.dll"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment