Skip to content

Commit d99d1a9

Browse files
authored
Merge pull request #374 from meysamhadeli/refactor/refactor-docker-files
refactor: refactor dockerfiles
2 parents a882b3c + 6e1fe61 commit d99d1a9

File tree

11 files changed

+144
-444
lines changed

11 files changed

+144
-444
lines changed

deployments/docker-compose/docker-compose.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ services:
355355
args:
356356
Version: "1"
357357
context: ../../
358-
dockerfile: src/ApiGateway/dev.Dockerfile
358+
dockerfile: src/ApiGateway/Dockerfile
359359
container_name: api-gateway
360360
ports:
361361
- "5001:80"
@@ -382,7 +382,7 @@ services:
382382
args:
383383
Version: "1"
384384
context: ../../
385-
dockerfile: src/Services/Flight/dev.Dockerfile
385+
dockerfile: src/Services/Flight/Dockerfile
386386
container_name: flight
387387
ports:
388388
- 5004:80
@@ -408,7 +408,7 @@ services:
408408
args:
409409
Version: "1"
410410
context: ../../
411-
dockerfile: src/Services/Identity/dev.Dockerfile
411+
dockerfile: src/Services/Identity/Dockerfile
412412
container_name: identity
413413
ports:
414414
- 6005:80
@@ -435,7 +435,7 @@ services:
435435
args:
436436
Version: "1"
437437
context: ../../
438-
dockerfile: src/Services/Passenger/dev.Dockerfile
438+
dockerfile: src/Services/Passenger/Dockerfile
439439
container_name: passenger
440440
ports:
441441
- 6012:80
@@ -462,7 +462,7 @@ services:
462462
args:
463463
Version: "1"
464464
context: ../../
465-
dockerfile: src/Services/Booking/dev.Dockerfile
465+
dockerfile: src/Services/Booking/Dockerfile
466466
container_name: booking
467467
ports:
468468
- 6010:80

src/ApiGateway/Dockerfile

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,38 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS builder
2-
WORKDIR /
1+
# ---------- Build Stage ----------
2+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
3+
WORKDIR /src
34

4-
COPY ./.editorconfig ./
5-
COPY ./global.json ./
6-
COPY ./Directory.Build.props ./
5+
# Copy solution-level files
6+
COPY .editorconfig .
7+
COPY global.json .
8+
COPY Directory.Build.props .
79

8-
# Setup working directory for the project
9-
COPY ./src/BuildingBlocks/BuildingBlocks.csproj ./building-blocks/
10-
COPY ./src/ApiGateway/src/ApiGateway.csproj ./src/ApiGateway/src/
11-
COPY ./src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj ./src/Aspire/src/ServiceDefaults/
10+
# Copy project files first (better Docker caching)
11+
COPY src/BuildingBlocks/BuildingBlocks.csproj src/BuildingBlocks/
12+
COPY src/ApiGateway/src/ApiGateway.csproj src/ApiGateway/src/
13+
COPY src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj src/Aspire/src/ServiceDefaults/
1214

13-
# Restore nuget packages
14-
RUN dotnet restore ./src/ApiGateway/src/ApiGateway.csproj
15+
# Restore dependencies
16+
RUN dotnet restore src/ApiGateway/src/ApiGateway.csproj
1517

16-
# Copy project files
17-
COPY ./src/BuildingBlocks ./src/BuildingBlocks/
18-
COPY ./src/ApiGateway/src ./src/ApiGateway/src/
19-
COPY ./src/Aspire/src/ServiceDefaults/ ./src/Aspire/src/ServiceDefaults/
18+
# Copy the rest of the source code
19+
COPY src ./src
2020

21-
# Build project with Release configuration
22-
# and no restore, as we did it already
21+
# Publish (build included)
22+
RUN dotnet publish src/ApiGateway/src/ApiGateway.csproj \
23+
-c Release \
24+
-o /app/publish \
25+
--no-restore
2326

24-
RUN ls
25-
RUN dotnet build -c Release --no-restore ./src/ApiGateway/src/ApiGateway.csproj
27+
# ---------- Runtime Stage ----------
28+
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
29+
WORKDIR /app
2630

27-
WORKDIR /src/ApiGateway/src
31+
COPY --from=build /app/publish .
2832

29-
# Publish project to output folder
30-
# and no build, as we did it already
31-
RUN dotnet publish -c Release --no-build -o out
32-
33-
FROM mcr.microsoft.com/dotnet/aspnet:10.0
34-
35-
# Setup working directory for the project
36-
WORKDIR /
37-
COPY --from=builder /src/ApiGateway/src/out .
38-
39-
ENV ASPNETCORE_URLS https://*:443, http://*:80
40-
ENV ASPNETCORE_ENVIRONMENT docker
33+
ENV ASPNETCORE_URLS=http://+:80
34+
ENV ASPNETCORE_ENVIRONMENT=docker
4135

4236
EXPOSE 80
43-
EXPOSE 443
44-
45-
ENTRYPOINT ["dotnet", "ApiGateway.dll"]
4637

38+
ENTRYPOINT ["dotnet", "ApiGateway.dll"]

src/ApiGateway/dev.Dockerfile

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/Services/Booking/Dockerfile

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS builder
2-
WORKDIR /
1+
# ---------- Build Stage ----------
2+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
3+
WORKDIR /src
34

4-
COPY ./.editorconfig ./
5-
COPY ./global.json ./
6-
COPY ./Directory.Build.props ./
5+
# Copy solution-level files
6+
COPY .editorconfig .
7+
COPY global.json .
8+
COPY Directory.Build.props .
79

8-
# Setup working directory for the project
9-
COPY ./src/BuildingBlocks/BuildingBlocks.csproj ./src/BuildingBlocks/
10-
COPY ./src/Services/Booking/src/Booking/Booking.csproj ./src/Services/Booking/src/Booking/
11-
COPY ./src/Services/Booking/src/Booking.Api/Booking.Api.csproj ./src/Services/Booking/src/Booking.Api/
12-
COPY ./src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj ./src/Aspire/src/ServiceDefaults/
10+
# Copy project files first (for Docker layer caching)
11+
COPY src/BuildingBlocks/BuildingBlocks.csproj src/BuildingBlocks/
12+
COPY src/Services/Booking/src/Booking/Booking.csproj src/Services/Booking/src/Booking/
13+
COPY src/Services/Booking/src/Booking.Api/Booking.Api.csproj src/Services/Booking/src/Booking.Api/
14+
COPY src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj src/Aspire/src/ServiceDefaults/
1315

14-
# Restore nuget packages
15-
RUN dotnet restore ./src/Services/Booking/src/Booking.Api/Booking.Api.csproj
16+
# Restore dependencies
17+
RUN dotnet restore src/Services/Booking/src/Booking.Api/Booking.Api.csproj
1618

17-
# Copy project files
18-
COPY ./src/BuildingBlocks ./src/BuildingBlocks/
19-
COPY ./src/Services/Booking/src/Booking/ ./src/Services/Booking/src/Booking/
20-
COPY ./src/Services/Booking/src/Booking.Api/ ./src/Services/Booking/src/Booking.Api/
21-
COPY ./src/Aspire/src/ServiceDefaults/ ./src/Aspire/src/ServiceDefaults/
19+
# Copy the rest of the source
20+
COPY src ./src
2221

23-
# Build project with Release configuration
24-
# and no restore, as we did it already
22+
# Publish (build included)
23+
RUN dotnet publish src/Services/Booking/src/Booking.Api/Booking.Api.csproj \
24+
-c Release \
25+
-o /app/publish \
26+
--no-restore
2527

26-
RUN ls
27-
RUN dotnet build -c Release --no-restore ./src/Services/Booking/src/Booking.Api/Booking.Api.csproj
28+
# ---------- Runtime Stage ----------
29+
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
30+
WORKDIR /app
2831

29-
WORKDIR /src/Services/Booking/src/Booking.Api
32+
COPY --from=build /app/publish .
3033

31-
# Publish project to output folder
32-
# and no build, as we did it already
33-
RUN dotnet publish -c Release --no-build -o out
34-
35-
FROM mcr.microsoft.com/dotnet/aspnet:10.0
36-
37-
# Setup working directory for the project
38-
WORKDIR /
39-
COPY --from=builder /src/Services/Booking/src/Booking.Api/out .
40-
41-
ENV ASPNETCORE_URLS https://*:443, http://*:80
42-
ENV ASPNETCORE_ENVIRONMENT docker
34+
ENV ASPNETCORE_URLS=http://+:80
35+
ENV ASPNETCORE_ENVIRONMENT=docker
4336

4437
EXPOSE 80
45-
EXPOSE 443
46-
47-
ENTRYPOINT ["dotnet", "Booking.Api.dll"]
4838

39+
ENTRYPOINT ["dotnet", "Booking.Api.dll"]

src/Services/Booking/dev.Dockerfile

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/Services/Flight/Dockerfile

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS builder
2-
WORKDIR /
1+
# ---------- Build Stage ----------
2+
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
3+
WORKDIR /src
34

4-
COPY ./.editorconfig ./
5-
COPY ./global.json ./
6-
COPY ./Directory.Build.props ./
5+
# Copy solution-level files
6+
COPY .editorconfig .
7+
COPY global.json .
8+
COPY Directory.Build.props .
79

8-
# Setup working directory for the project
9-
COPY ./src/BuildingBlocks/BuildingBlocks.csproj ./src/BuildingBlocks/
10-
COPY ./src/Services/Flight/src/Flight/Flight.csproj ./src/Services/Flight/src/Flight/
11-
COPY ./src/Services/Flight/src/Flight.Api/Flight.Api.csproj ./src/Services/Flight/src/Flight.Api/
12-
COPY ./src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj ./src/Aspire/src/ServiceDefaults/
10+
# Copy project files first (better layer caching)
11+
COPY src/BuildingBlocks/BuildingBlocks.csproj src/BuildingBlocks/
12+
COPY src/Services/Flight/src/Flight/Flight.csproj src/Services/Flight/src/Flight/
13+
COPY src/Services/Flight/src/Flight.Api/Flight.Api.csproj src/Services/Flight/src/Flight.Api/
14+
COPY src/Aspire/src/ServiceDefaults/ServiceDefaults.csproj src/Aspire/src/ServiceDefaults/
1315

14-
# Restore nuget packages
15-
RUN dotnet restore ./src/Services/Flight/src/Flight.Api/Flight.Api.csproj
16+
# Restore dependencies
17+
RUN dotnet restore src/Services/Flight/src/Flight.Api/Flight.Api.csproj
1618

17-
# Copy project files
18-
COPY ./src/BuildingBlocks ./src/BuildingBlocks/
19-
COPY ./src/Services/Flight/src/Flight/ ./src/Services/Flight/src/Flight/
20-
COPY ./src/Services/Flight/src/Flight.Api/ ./src/Services/Flight/src/Flight.Api/
21-
COPY ./src/Aspire/src/ServiceDefaults/ ./src/Aspire/src/ServiceDefaults/
19+
# Copy remaining source code
20+
COPY src ./src
2221

23-
# Build project with Release configuration
24-
# and no restore, as we did it already
22+
# Publish (build included)
23+
RUN dotnet publish src/Services/Flight/src/Flight.Api/Flight.Api.csproj \
24+
-c Release \
25+
-o /app/publish \
26+
--no-restore
2527

26-
RUN ls
27-
RUN dotnet build -c Release --no-restore ./src/Services/Flight/src/Flight.Api/Flight.Api.csproj
28+
# ---------- Runtime Stage ----------
29+
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime
30+
WORKDIR /app
2831

29-
WORKDIR /src/Services/Flight/src/Flight.Api
32+
COPY --from=build /app/publish .
3033

31-
# Publish project to output folder
32-
# and no build, as we did it already
33-
RUN dotnet publish -c Release --no-build -o out
34-
35-
FROM mcr.microsoft.com/dotnet/aspnet:10.0
36-
37-
# Setup working directory for the project
38-
WORKDIR /
39-
COPY --from=builder /src/Services/Flight/src/Flight.Api/out .
40-
41-
42-
ENV ASPNETCORE_URLS https://*:443, http://*:80
43-
ENV ASPNETCORE_ENVIRONMENT docker
34+
ENV ASPNETCORE_URLS=http://+:80
35+
ENV ASPNETCORE_ENVIRONMENT=docker
4436

4537
EXPOSE 80
46-
EXPOSE 443
47-
48-
ENTRYPOINT ["dotnet", "Flight.Api.dll"]
4938

39+
ENTRYPOINT ["dotnet", "Flight.Api.dll"]

0 commit comments

Comments
 (0)