From 82c10649b711a6ce1c600a92617ac06a3b4dd4d8 Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Tue, 20 Oct 2020 15:56:47 +0200 Subject: [PATCH 1/6] Added sample for .NET Core application The sample includes a basic console application and a Dockerfile --- samples/NetCore/Dockerfile | 17 ++++++++ samples/NetCore/NetCore.sln | 39 +++++++++++++++++++ .../NetCore/src/ConsoleApp/ConsoleApp.csproj | 8 ++++ samples/NetCore/src/ConsoleApp/Program.cs | 17 ++++++++ 4 files changed, 81 insertions(+) create mode 100644 samples/NetCore/Dockerfile create mode 100644 samples/NetCore/NetCore.sln create mode 100644 samples/NetCore/src/ConsoleApp/ConsoleApp.csproj create mode 100644 samples/NetCore/src/ConsoleApp/Program.cs diff --git a/samples/NetCore/Dockerfile b/samples/NetCore/Dockerfile new file mode 100644 index 0000000..c3b1d4f --- /dev/null +++ b/samples/NetCore/Dockerfile @@ -0,0 +1,17 @@ +# escape=` +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build +WORKDIR /src +COPY src/ ./ +RUN dotnet restore ConsoleApp/ConsoleApp.csproj +RUN dotnet publish ConsoleApp/ConsoleApp.csproj -c Release -o /out + +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS runtime +WORKDIR /app +COPY --from=build /out . +ENV PATH="/root/.dotnet/tools:${PATH}" ` + DotNetEnsureUnique__S3__BucketName= ` + DotNetEnsureUnique__S3__FilePrefix= + +RUN dotnet tool install -g EMG.Tools.EnsureUnique + +ENTRYPOINT dotnet ensure-unique exe ./ConsoleApp diff --git a/samples/NetCore/NetCore.sln b/samples/NetCore/NetCore.sln new file mode 100644 index 0000000..79ad384 --- /dev/null +++ b/samples/NetCore/NetCore.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{116B4950-3300-47B4-A4F2-533CA24D966F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "src\ConsoleApp\ConsoleApp.csproj", "{FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|x64.ActiveCfg = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|x64.Build.0 = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|x86.ActiveCfg = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Debug|x86.Build.0 = Debug|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|Any CPU.Build.0 = Release|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|x64.ActiveCfg = Release|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|x64.Build.0 = Release|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|x86.ActiveCfg = Release|Any CPU + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {FA79C93C-D5A6-4FC3-969D-09A05E50AE8A} = {116B4950-3300-47B4-A4F2-533CA24D966F} + EndGlobalSection +EndGlobal diff --git a/samples/NetCore/src/ConsoleApp/ConsoleApp.csproj b/samples/NetCore/src/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/samples/NetCore/src/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/samples/NetCore/src/ConsoleApp/Program.cs b/samples/NetCore/src/ConsoleApp/Program.cs new file mode 100644 index 0000000..f5aab97 --- /dev/null +++ b/samples/NetCore/src/ConsoleApp/Program.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; + +namespace ConsoleApp +{ + class Program + { + static async Task Main(string[] args) + { + Console.WriteLine("Loading..."); + + await Task.Delay(TimeSpan.FromSeconds(10)); + + Console.WriteLine("Bye!"); + } + } +} From 2694961718d95b4ecbc866a0f94ba2f997343ec5 Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Wed, 21 Oct 2020 10:38:21 +0200 Subject: [PATCH 2/6] Reworked Dockerfile to be able to use dotnet/core/runtime image --- samples/NetCore/Dockerfile | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/samples/NetCore/Dockerfile b/samples/NetCore/Dockerfile index c3b1d4f..9406ec3 100644 --- a/samples/NetCore/Dockerfile +++ b/samples/NetCore/Dockerfile @@ -1,17 +1,24 @@ # escape=` + +# BUILDER FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build WORKDIR /src COPY src/ ./ RUN dotnet restore ConsoleApp/ConsoleApp.csproj RUN dotnet publish ConsoleApp/ConsoleApp.csproj -c Release -o /out -FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS runtime +# TOOLS +FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS tools +ENV PATH="/root/.dotnet/tools:${PATH}" +RUN dotnet tool install -g EMG.Tools.EnsureUnique + +# RUNNER +FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS runtime WORKDIR /app +COPY --from=tools /root/.dotnet/tools/ /opt/bin +ENV PATH="/opt/bin:${PATH}" COPY --from=build /out . ENV PATH="/root/.dotnet/tools:${PATH}" ` DotNetEnsureUnique__S3__BucketName= ` DotNetEnsureUnique__S3__FilePrefix= - -RUN dotnet tool install -g EMG.Tools.EnsureUnique - -ENTRYPOINT dotnet ensure-unique exe ./ConsoleApp +ENTRYPOINT dotnet-ensure-unique exe ./ConsoleApp \ No newline at end of file From 3747d720e62c6aef4a0cdbd9300a53f3652f05e8 Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Wed, 21 Oct 2020 10:40:20 +0200 Subject: [PATCH 3/6] Endline --- samples/NetCore/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/NetCore/Dockerfile b/samples/NetCore/Dockerfile index 9406ec3..d9446b3 100644 --- a/samples/NetCore/Dockerfile +++ b/samples/NetCore/Dockerfile @@ -21,4 +21,4 @@ COPY --from=build /out . ENV PATH="/root/.dotnet/tools:${PATH}" ` DotNetEnsureUnique__S3__BucketName= ` DotNetEnsureUnique__S3__FilePrefix= -ENTRYPOINT dotnet-ensure-unique exe ./ConsoleApp \ No newline at end of file +ENTRYPOINT dotnet-ensure-unique exe ./ConsoleApp From 9b2dea2c161c1564a733495848fa99a8d8eb7cf3 Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Wed, 21 Oct 2020 13:18:51 +0200 Subject: [PATCH 4/6] Fix netcore sample --- samples/NetCore/Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/NetCore/Dockerfile b/samples/NetCore/Dockerfile index d9446b3..d51d8ad 100644 --- a/samples/NetCore/Dockerfile +++ b/samples/NetCore/Dockerfile @@ -16,9 +16,8 @@ RUN dotnet tool install -g EMG.Tools.EnsureUnique FROM mcr.microsoft.com/dotnet/core/runtime:3.1 AS runtime WORKDIR /app COPY --from=tools /root/.dotnet/tools/ /opt/bin -ENV PATH="/opt/bin:${PATH}" COPY --from=build /out . -ENV PATH="/root/.dotnet/tools:${PATH}" ` +ENV PATH="/opt/bin:${PATH}" ` DotNetEnsureUnique__S3__BucketName= ` DotNetEnsureUnique__S3__FilePrefix= ENTRYPOINT dotnet-ensure-unique exe ./ConsoleApp From af7407b04a12584492125351564f59232f4f063e Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Wed, 21 Oct 2020 15:03:42 +0200 Subject: [PATCH 5/6] Added sample for .NET Framework --- samples/NetFx/Dockerfile | 23 +++++++++++ samples/NetFx/NetFx.sln | 39 +++++++++++++++++++ .../NetFx/src/ConsoleApp/ConsoleApp.csproj | 8 ++++ samples/NetFx/src/ConsoleApp/Program.cs | 17 ++++++++ 4 files changed, 87 insertions(+) create mode 100644 samples/NetFx/Dockerfile create mode 100644 samples/NetFx/NetFx.sln create mode 100644 samples/NetFx/src/ConsoleApp/ConsoleApp.csproj create mode 100644 samples/NetFx/src/ConsoleApp/Program.cs diff --git a/samples/NetFx/Dockerfile b/samples/NetFx/Dockerfile new file mode 100644 index 0000000..d638745 --- /dev/null +++ b/samples/NetFx/Dockerfile @@ -0,0 +1,23 @@ +# escape=` + +# BUILDER +FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 as build +WORKDIR /src +COPY src/ ./ +RUN dotnet restore ConsoleApp/ConsoleApp.csproj +RUN dotnet publish ConsoleApp/ConsoleApp.csproj -c Release -o /out + +# RUNNER +FROM mcr.microsoft.com/dotnet/framework/runtime:4.8 AS runtime +ADD https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 C:\temp\ +RUN powershell C:\temp\dotnet-install.ps1 -Channel LTS +ARG DOTNET_PATH=C:\Users\ContainerAdministrator\AppData\Local\Microsoft\dotnet\ +RUN SETX DOTNET_ROOT %DOTNET_PATH% +RUN SETX PATH %PATH%;%DOTNET_PATH% +ENV DotNetEnsureUnique__S3__BucketName= ` + DotNetEnsureUnique__S3__FilePrefix= ` + DOTNET_CLI_TELEMETRY_OPTOUT=1 +RUN dotnet tool install -g EMG.Tools.EnsureUnique +WORKDIR /app +COPY --from=build /out . +ENTRYPOINT ["dotnet", "ensure-unique", "exe", "ConsoleApp.exe"] diff --git a/samples/NetFx/NetFx.sln b/samples/NetFx/NetFx.sln new file mode 100644 index 0000000..58fa36e --- /dev/null +++ b/samples/NetFx/NetFx.sln @@ -0,0 +1,39 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26124.0 +MinimumVisualStudioVersion = 15.0.26124.0 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{83044FA3-B259-483F-BAA0-E2134E96BA9C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "src\ConsoleApp\ConsoleApp.csproj", "{5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|x64.ActiveCfg = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|x64.Build.0 = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|x86.ActiveCfg = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Debug|x86.Build.0 = Debug|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|Any CPU.Build.0 = Release|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|x64.ActiveCfg = Release|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|x64.Build.0 = Release|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|x86.ActiveCfg = Release|Any CPU + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {5BF52843-F63E-4A48-B9C1-2616CE4D5AF0} = {83044FA3-B259-483F-BAA0-E2134E96BA9C} + EndGlobalSection +EndGlobal diff --git a/samples/NetFx/src/ConsoleApp/ConsoleApp.csproj b/samples/NetFx/src/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..0dc116f --- /dev/null +++ b/samples/NetFx/src/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,8 @@ + + + + Exe + net48 + + + diff --git a/samples/NetFx/src/ConsoleApp/Program.cs b/samples/NetFx/src/ConsoleApp/Program.cs new file mode 100644 index 0000000..f5aab97 --- /dev/null +++ b/samples/NetFx/src/ConsoleApp/Program.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; + +namespace ConsoleApp +{ + class Program + { + static async Task Main(string[] args) + { + Console.WriteLine("Loading..."); + + await Task.Delay(TimeSpan.FromSeconds(10)); + + Console.WriteLine("Bye!"); + } + } +} From 5d5cbea0b8f7942b3c4fb3c0bbbb6151f5f4debc Mon Sep 17 00:00:00 2001 From: Renato Golia Date: Wed, 21 Oct 2020 16:54:29 +0200 Subject: [PATCH 6/6] Added alternative strategy for .NET Framework sample --- samples/NetFx/Dockerfile | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/samples/NetFx/Dockerfile b/samples/NetFx/Dockerfile index d638745..664ab49 100644 --- a/samples/NetFx/Dockerfile +++ b/samples/NetFx/Dockerfile @@ -7,17 +7,39 @@ COPY src/ ./ RUN dotnet restore ConsoleApp/ConsoleApp.csproj RUN dotnet publish ConsoleApp/ConsoleApp.csproj -c Release -o /out -# RUNNER +# Option 1 +# TOOLS +FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 as tools +RUN dotnet tool install EMG.Tools.EnsureUnique --tool-path C:\tools + +# RUNNER -- Shared 5.27 GB -- unique 113 MB FROM mcr.microsoft.com/dotnet/framework/runtime:4.8 AS runtime ADD https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 C:\temp\ -RUN powershell C:\temp\dotnet-install.ps1 -Channel LTS -ARG DOTNET_PATH=C:\Users\ContainerAdministrator\AppData\Local\Microsoft\dotnet\ +RUN powershell C:\temp\dotnet-install.ps1 -Channel LTS -Runtime dotnet -InstallDir C:\dotnet +ARG DOTNET_PATH=C:\dotnet\ +ARG DOTNET_TOOLS_PATH=C:\tools\ RUN SETX DOTNET_ROOT %DOTNET_PATH% -RUN SETX PATH %PATH%;%DOTNET_PATH% +RUN SETX PATH %PATH%;%DOTNET_PATH%;%DOTNET_TOOLS_PATH% ENV DotNetEnsureUnique__S3__BucketName= ` DotNetEnsureUnique__S3__FilePrefix= ` DOTNET_CLI_TELEMETRY_OPTOUT=1 -RUN dotnet tool install -g EMG.Tools.EnsureUnique +COPY --from=tools C:\tools\ C:\tools\ WORKDIR /app COPY --from=build /out . -ENTRYPOINT ["dotnet", "ensure-unique", "exe", "ConsoleApp.exe"] +ENTRYPOINT ["dotnet-ensure-unique", "exe", "ConsoleApp.exe"] + +# Option 2 +# # RUNNER +# FROM mcr.microsoft.com/dotnet/framework/runtime:4.8 AS runtime +# ADD https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 C:\temp\ +# ARG DOTNET_PATH=C:\dotnet\ +# RUN powershell C:\temp\dotnet-install.ps1 -Channel LTS -InstallDir %DOTNET_PATH% +# RUN SETX DOTNET_ROOT %DOTNET_PATH% +# RUN SETX PATH %PATH%;%DOTNET_PATH% +# ENV DotNetEnsureUnique__S3__BucketName= ` +# DotNetEnsureUnique__S3__FilePrefix= ` +# DOTNET_CLI_TELEMETRY_OPTOUT=1 +# RUN dotnet tool install -g EMG.Tools.EnsureUnique +# WORKDIR /app +# COPY --from=build /out . +# ENTRYPOINT ["dotnet", "ensure-unique", "exe", "ConsoleApp.exe"] \ No newline at end of file