Skip to content

Commit 83f8f03

Browse files
refactor: parameterize Dockerfile to improve maintainability and flexibility
1 parent 9550fbe commit 83f8f03

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,26 @@ EXPOSE 8080
77
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
88
WORKDIR /workdir
99

10+
ARG BUILD_CONFIGURATION=Release
11+
ARG SOLUTION=HttpsRichardy.Federation
12+
1013
# copy only csproj and sln to restore as early as possible
11-
COPY ["Source/HttpsRichardy.Federation.WebApi/HttpsRichardy.Federation.WebApi.csproj", "HttpsRichardy.Federation.WebApi/"]
12-
COPY ["HttpsRichardy.Federation.sln", "./"]
14+
COPY ["Source/${SOLUTION}.WebApi/${SOLUTION}.WebApi.csproj", "${SOLUTION}.WebApi/"]
15+
COPY ["${SOLUTION}.sln", "./"]
1316

1417
# restore dependencies
15-
RUN dotnet restore "HttpsRichardy.Federation.WebApi/HttpsRichardy.Federation.WebApi.csproj"
18+
RUN dotnet restore "${SOLUTION}.WebApi/${SOLUTION}.WebApi.csproj"
1619

1720
# copy the rest of the source code
1821
COPY Source/ ./Source/
1922

20-
WORKDIR "/workdir/Source/HttpsRichardy.Federation.WebApi"
23+
WORKDIR "/workdir/Source/${SOLUTION}.WebApi"
2124

2225
# build in Release mode
23-
RUN dotnet build "HttpsRichardy.Federation.WebApi.csproj" -c Release -o /artifacts/build
26+
RUN dotnet build "${SOLUTION}.WebApi.csproj" -c $BUILD_CONFIGURATION -o /artifacts/build
2427

2528
# publish the project for production
26-
RUN dotnet publish "HttpsRichardy.Federation.WebApi.csproj" -c Release -o /artifacts/publish /p:UseAppHost=false
29+
RUN dotnet publish "${SOLUTION}.WebApi.csproj" -c $BUILD_CONFIGURATION -o /artifacts/publish /p:UseAppHost=false
2730

2831
# final image to run the app
2932
FROM base AS final

0 commit comments

Comments
 (0)