From 2f844d0f9e128d9bf43f0f21222aec9afdf79cc8 Mon Sep 17 00:00:00 2001 From: fustom Date: Thu, 5 Nov 2026 15:30:11 +0000 Subject: [PATCH 1/4] Create multi-stage Dockerfile --- .devcontainer/devcontainer.json | 6 +++++- Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fe67631..99d9abd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,6 +1,10 @@ { "name": "C# (.NET)", - "image": "mcr.microsoft.com/devcontainers/dotnet:10.0", + "build": { + "dockerfile": "../Dockerfile", + "context": "..", + "target": "dev" + }, "features": { "ghcr.io/devcontainers/features/github-cli:1": { "installDirectlyFromGitHubRelease": true, diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5cad165 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# --- Stage 1: Development Environment --- +FROM mcr.microsoft.com/devcontainers/dotnet:10.0 AS dev +WORKDIR /app + +# --- Stage 2: Build Stage for Production --- +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src + +# Copy the source code +COPY . . +RUN dotnet restore +RUN dotnet build -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false + +# --- Stage 3: Lean Production Runtime --- +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS production +WORKDIR /app +EXPOSE 8080 +USER app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "CloneDevOpsTemplate.dll"] \ No newline at end of file From 4dae0fe3a03edfde386f4c327a43a5b9146a0322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=BCst=C3=B6s=20Tam=C3=A1s?= Date: Fri, 6 Nov 2026 14:23:37 +0000 Subject: [PATCH 2/4] Simplify and use the small alpine image --- Dockerfile | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5cad165..1c8c22d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,23 @@ -# --- Stage 1: Development Environment --- +# Development stage, selected by devcontainer.json FROM mcr.microsoft.com/devcontainers/dotnet:10.0 AS dev WORKDIR /app -# --- Stage 2: Build Stage for Production --- -FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +# Production publish stage +FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS publish ARG BUILD_CONFIGURATION=Release WORKDIR /src -# Copy the source code COPY . . -RUN dotnet restore -RUN dotnet build -c $BUILD_CONFIGURATION -o /app/build +RUN dotnet restore CloneDevOpsTemplate/CloneDevOpsTemplate.csproj +RUN dotnet publish CloneDevOpsTemplate/CloneDevOpsTemplate.csproj \ + -c $BUILD_CONFIGURATION \ + -o /app/publish \ + /p:UseAppHost=false -FROM build AS publish -ARG BUILD_CONFIGURATION=Release -RUN dotnet publish -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false - -# --- Stage 3: Lean Production Runtime --- -FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS production +# Production runtime stage +FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS production WORKDIR /app EXPOSE 8080 USER app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "CloneDevOpsTemplate.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "CloneDevOpsTemplate.dll"] From b7046a93e0b3bf96f9dc1d48ab36ea3f65c6b5e1 Mon Sep 17 00:00:00 2001 From: fustom Date: Sat, 7 Nov 2026 10:44:45 +0000 Subject: [PATCH 3/4] Copy only the project folder --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1c8c22d..09bc963 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,9 +7,9 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS publish ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY . . -RUN dotnet restore CloneDevOpsTemplate/CloneDevOpsTemplate.csproj -RUN dotnet publish CloneDevOpsTemplate/CloneDevOpsTemplate.csproj \ +COPY CloneDevOpsTemplate . +RUN dotnet restore CloneDevOpsTemplate.csproj +RUN dotnet publish CloneDevOpsTemplate.csproj \ -c $BUILD_CONFIGURATION \ -o /app/publish \ /p:UseAppHost=false From 57750396d5c7ef4146ea844d6769dc63461eed8c Mon Sep 17 00:00:00 2001 From: fustom Date: Sat, 7 Nov 2026 10:45:50 +0000 Subject: [PATCH 4/4] Add dockerignore file --- .dockerignore | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c2720b3 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,29 @@ +# Git version control +.git +.gitignore +.gitattributes +.github/ + +# .NET Build outputs and local caches +**/bin/ +**/obj/ +**/publish/ +.vs/ +.vscode/ + +# Environment variables and secrets +.env +*.user +*.suo + +# Docker files themselves +Dockerfile +.dockerignore +docker-compose* +.devcontainer/ + +# OS specific files +.DS_Store +Thumbs.db + +CloneDevOpsTemplateTest/ \ No newline at end of file