-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (44 loc) · 2.1 KB
/
Dockerfile
File metadata and controls
56 lines (44 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Build and run the LifeHacking WebAPI using multi-stage Docker build
# =========================================================
# 1) Runtime image (small, optimized for running the API)
# =========================================================
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
WORKDIR /app
# Use a non-privileged HTTP port inside the container
EXPOSE 8080
ENV ASPNETCORE_URLS=http://+:8080
# Environment variables used by WebAPI configuration
# These can be overridden at `docker run` time with `-e` flags.
#
# =========================================================
# 2) Build image (contains SDK and tooling)
# =========================================================
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
# Copy project files first (for better layer caching)
COPY ["lifehacking/WebAPI/WebAPI.csproj", "WebAPI/"]
COPY ["lifehacking/Application/Application.csproj", "Application/"]
COPY ["lifehacking/Domain/Domain.csproj", "Domain/"]
COPY ["lifehacking/Infrastructure/Infrastructure.csproj", "Infrastructure/"]
COPY ["lifehacking/Tests/Application.Tests/Application.Tests.csproj", "Tests/Application.Tests/"]
COPY ["lifehacking/Tests/Infrastructure.Tests/Infrastructure.Tests.csproj", "Tests/Infrastructure.Tests/"]
COPY ["lifehacking/Tests/WebAPI.Tests/WebAPI.Tests.csproj", "Tests/WebAPI.Tests/"]
COPY ["lifehacking.slnx", "."]
RUN dotnet restore "WebAPI/WebAPI.csproj"
# Copy the rest of the source
COPY lifehacking/. .
# Optional: run tests as part of the Docker build. Uncomment if desired.
# This will cause `docker build` to fail if tests fail.
# RUN dotnet test lifehacking.slnx --configuration Release --no-build
# Publish the WebAPI project
WORKDIR "/src/WebAPI"
RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
# =========================================================
# 3) Final image (runtime + published app only)
# =========================================================
FROM base AS final
WORKDIR /app
# Copy published output from build stage
COPY --from=build /app/publish .
# Start the Web API
ENTRYPOINT ["dotnet", "WebAPI.dll"]