diff --git a/README.md b/README.md index 1dcbc5e557..dcc73b0efd 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ This image contains the operating system with all of the native dependencies nee View [license information](https://github.com/dotnet/dotnet-docker/blob/master/LICENSE) for the software contained in this image. -The .NET Core Windows container images use the same license as the [Windows Server 2016 Nano Server base image](https://hub.docker.com/r/microsoft/nanoserver/), as follows: +The .NET Core Windows images use the same license as the [Windows Server 2016 Nano Server base image](https://hub.docker.com/r/microsoft/nanoserver/), as follows: MICROSOFT SOFTWARE SUPPLEMENTAL LICENSE TERMS diff --git a/samples/README.DockerHub.md b/samples/README.DockerHub.md index 4d57d694b9..044d80e60d 100644 --- a/samples/README.DockerHub.md +++ b/samples/README.DockerHub.md @@ -85,7 +85,7 @@ See the following related repos for other application types: View [license information](https://www.microsoft.com/net/dotnet_library_license.htm) for the software contained in this image. -The .NET Core Windows container images use the same license as the [Windows Server 2016 Nano Server base image](https://hub.docker.com/r/microsoft/nanoserver/), as follows: +The .NET Core Windows images use the same license as the [Windows Server 2016 Nano Server base image](https://hub.docker.com/r/microsoft/nanoserver/), as follows: MICROSOFT SOFTWARE SUPPLEMENTAL LICENSE TERMS diff --git a/samples/README.md b/samples/README.md index c9d0e65834..d7092e6261 100644 --- a/samples/README.md +++ b/samples/README.md @@ -19,6 +19,11 @@ docker run --rm microsoft/dotnet-samples * [.NET Core Docker Sample](dotnetapp/README.md) - This [sample](dotnetapp/Dockerfile) builds, tests, and runs the sample. It includes and builds multiple projects. * [ASP.NET Core Docker Sample](aspnetapp/README.md) - This [sample](aspnetapp/Dockerfile) demonstrates using Docker with an ASP.NET Core Web App. +## Develop .NET Core Apps in a Container + +* [Develop .NET Core Applications](dotnetapp/dotnet-docker-dev-in-container.md) - This sample shows how to develop and test .NET Core applications with Docker without the need to install the .NET Core SDK. +* [Develop ASP.NET Core Applications](aspnetapp/aspnet-docker-dev-in-container.md) - This sample shows how to develop and test ASP.NET Core applications with Docker without the need to install the .NET Core SDK. + ## Push Images to a Container Registry * [Push Docker Images to Azure Container Registry](dotnetapp/push-image-to-acr.md) diff --git a/samples/aspnetapp/Directory.build.props b/samples/aspnetapp/Directory.build.props new file mode 100644 index 0000000000..fc3ed9eede --- /dev/null +++ b/samples/aspnetapp/Directory.build.props @@ -0,0 +1,18 @@ + + + + $(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/* + $(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/* + + + + $(MSBuildProjectDirectory)/obj/container/ + $(MSBuildProjectDirectory)/bin/container/ + + + + $(MSBuildProjectDirectory)/obj/local/ + $(MSBuildProjectDirectory)/bin/local/ + + + \ No newline at end of file diff --git a/samples/aspnetapp/README.md b/samples/aspnetapp/README.md index ab3066d9fc..c7e454412b 100644 --- a/samples/aspnetapp/README.md +++ b/samples/aspnetapp/README.md @@ -6,8 +6,6 @@ The sample builds the application in a container based on the larger [.NET Core This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker). -The [.NET Core Docker Sample](../dotnetapp/README.md) demonstrates more functionality, including unit testing, publishing self-contained applications and using the Alpine base image. The same techniques can be applied to ASP.NET applications. - ## Try a pre-built ASP.NET Core Docker Image You can quickly try a pre-built [sample ASP.NET Core Docker image](https://hub.docker.com/r/microsoft/dotnet-samples/), based on this sample. @@ -15,7 +13,7 @@ You can quickly try a pre-built [sample ASP.NET Core Docker image](https://hub.d Type the following command to run a sample with [Docker](https://www.docker.com/products/docker): ```console -docker run --rm -p 8000:80 --name aspnetcore_sample microsoft/dotnet-samples:aspnetapp +docker run --name aspnetcore_sample --rm -it -p 8000:80 microsoft/dotnet-samples:aspnetapp ``` After the application starts, navigate to `http://localhost:8000` in your web browser. You need to navigate to the application via IP address instead of `localhost` for Windows containers, which is demonstrated in the [View the ASP.NET Core app in a running container on Windows](#view-the-aspnet-core-app-in-a-running-container-on-windows) section. @@ -38,13 +36,13 @@ You can build and run the sample in Docker using the following commands. The ins cd samples cd aspnetapp docker build --pull -t aspnetapp . -docker run --rm -p 8000:80 --name aspnetcore_sample aspnetapp +docker run --name aspnetcore_sample --rm -it -p 8000:80 aspnetapp ``` You should see the following console output as the application starts. ```console -C:\git\dotnet-docker\samples\aspnetapp>docker run --rm --name aspnetcore_sample aspnetapp +C:\git\dotnet-docker\samples\aspnetapp>docker run --name aspnetcore_sample --rm -it -p 8000:80 aspnetapp Hosting environment: Production Content root path: /app Now listening on: http://[::]:80 @@ -94,10 +92,24 @@ C:\git\dotnet-docker\samples\aspnetapp>docker inspect -f "{{ .NetworkSettings.Ne 172.25.157.148 ``` +## Deploying to Production vs Development + +The approach for running containers differs between development and production. + +In production, you will typically start your container with `docker run -d`. This argument starts the container as a service, without any console interaction. You then interact with it through other Docker commands or APIs exposed by the containerized application. + +In development, you will typically start containers with `docker run --rm -it`. These arguments enable you to see a console (important when there are errors), terminate the container with `CTRL-C` and cleans up all container resources when the container is termiantes. You also typically don't mind blocking the console. This approach is demonstrated in prior examples in this document. + +We recommend that you do not use `--rm` in production. It cleans up container resources, preventing you from collecting logs that may have been captured in a container that has either stopped or crashed. + ## Build and run the sample for Linux ARM32 with Docker You can build and run the sample for ARM32 and Raspberry Pi with [Build ASP.NET Core Applications for Raspberry Pi with Docker](aspnetcore-docker-arm32.md) instructions. +## Develop ASP.NET Core Applications in a container + +You can develop applications without a .NET Core installation on your machine with the [Develop ASP.NET Core applications in a container](aspnet-docker-dev-in-container.md) instructions. These instructions are also useful if your development and production environments do not match. + ## Build and run the sample locally You can build and run the sample locally with the [.NET Core 2.0 SDK](https://www.microsoft.com/net/download/core) using the following commands. The commands assume that you are in the root of the repository. diff --git a/samples/aspnetapp/aspnet-docker-dev-in-container.md b/samples/aspnetapp/aspnet-docker-dev-in-container.md new file mode 100644 index 0000000000..6f9460dcd1 --- /dev/null +++ b/samples/aspnetapp/aspnet-docker-dev-in-container.md @@ -0,0 +1,65 @@ +# Develop ASP.NET Core Applications in a Container + +You can use containers to establish a .NET Core development environment with only Docker and optionally a code editor installed on your machine. The environment can be made to match your local machine, production or both. If you support multiple operating systems, then this approach might become a key part of your development process. + +A common use case of Docker is to [containerize an application](README.md). You can define the environment necessary to run the application and even build the application itself within a Dockerfile. This document describes a much more iterative and dynamic use of Docker, defining the container environment primarily via the commandline. .NET Core includes a command called `dotnet watch` that can rerun your application or your tests on each code change. This document describes how to use the Docker CLI and `dotnet watch` to develop applications in a container. + +See [Develop .NET Core Applications in a Container](../dotnetapp/aspnet-docker-dev-in-container.md) for .NET Core-specific instructions. + +## Getting the sample + +The easiest way to get the sample is by cloning the samples repository with [git](https://git-scm.com/downloads), using the following instructions: + +```console +git clone https://github.com/dotnet/dotnet-docker/ +``` + +You can also [download the repository as a zip](https://github.com/dotnet/dotnet-docker/archive/master.zip). + +## Requirements + +The instructions below use .NET Core 2.1 Preview 2 images. It is possible to make this scenario work with .NET Core 2.0 but requires many extra steps and a bit of magic. You do not need to switch to .NET Core 2.1 on your local machine to try out these instructions. They will work fine with .NET Core 2.0 projects. + +It is recommended that you add a [Directory.Build.props](Directory.Build.props) file to your project to use different `obj` and `bin` folders for local and container use, to avoid conflicts between them. You should delete your existing obj and bin folders before making this change. You can also use `dotnet clean` for this purpose. + +This approach relies on [volume mounting](https://docs.docker.com/engine/admin/volumes/volumes/) (that's the `-v` argument in the following commands) to mount source into the container (without using a Dockerfile). You may need to [Enable shared drives (Windows)](https://docs.docker.com/docker-for-windows/#shared-drives) or [file sharing (macOS)](https://docs.docker.com/docker-for-mac/#file-sharing) first. + +## Run your application in a container while you Develop + +You can re-run your application in a container with every local code change. This scenario works for both console applications and websites. The syntax differs a bit for Windows and Linux containers. + +The instructions assume that you are in the root of the repository. You can use the following commands, given your environment: + +**Windows** using **Linux containers** + +```console +docker run --rm -it -p 8000:80 -v c:\git\dotnet-docker\samples\aspnetapp:/app/ -w /app/aspnetapp microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +Navigate to the site at `http://localhost:8000` in your browser. You can use CTRL-C to terminate `dotnet watch`. It can take up to 20s to terminate. + +**macOS or Linux** using **Linux containers** + +```console +docker run --rm -it -p 8000:80 -v ~/git/dotnet-docker/samples/aspnetapp:/app/ -w /app/aspnetapp microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +Navigate to the site at `http://localhost:8000` in your browser. You can use CTRL-C to terminate `dotnet watch`. It can take up to 20s to terminate. + +**Windows** using **Windows containers** + +`dotnet watch run` is not working correctly in containers at this time. The instructions are still documented while we work on enabling this scenario. + +```console +docker run --rm -it -p 8000:80 -v c:\git\dotnet-docker\samples\aspnetapp:c:\app\ -w \app\aspnetapp --name aspnetappsample microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +In another command window, type `docker exec aspnetappsample ipconfig`. Navigate to the IP address you see in your browser. + +### Updating the site while the container is running + +You can demo a relaunch of the site by changing the About controller method in `HomeController.cs`, waiting a few seconds for the site to recompile and then visit `http://localhost:8000/Home/About` + +## Test your application in a container while you develop + +You can retest your application in a container with every local code change. You can see this demonstrated in [Develop .NET Core Applications in a Container](../dotnetapp/dotnet-docker-dev-in-container.md). diff --git a/samples/aspnetapp/aspnetapp/aspnetapp.csproj b/samples/aspnetapp/aspnetapp/aspnetapp.csproj index 4888f7ce8e..e09b518702 100644 --- a/samples/aspnetapp/aspnetapp/aspnetapp.csproj +++ b/samples/aspnetapp/aspnetapp/aspnetapp.csproj @@ -22,6 +22,7 @@ + diff --git a/samples/dotnetapp/Directory.Build.props b/samples/dotnetapp/Directory.Build.props new file mode 100644 index 0000000000..fc3ed9eede --- /dev/null +++ b/samples/dotnetapp/Directory.Build.props @@ -0,0 +1,18 @@ + + + + $(DefaultItemExcludes);$(MSBuildProjectDirectory)/obj/**/* + $(DefaultItemExcludes);$(MSBuildProjectDirectory)/bin/**/* + + + + $(MSBuildProjectDirectory)/obj/container/ + $(MSBuildProjectDirectory)/bin/container/ + + + + $(MSBuildProjectDirectory)/obj/local/ + $(MSBuildProjectDirectory)/bin/local/ + + + \ No newline at end of file diff --git a/samples/dotnetapp/README.md b/samples/dotnetapp/README.md index 984dc6d11c..9498e012e2 100644 --- a/samples/dotnetapp/README.md +++ b/samples/dotnetapp/README.md @@ -6,8 +6,6 @@ The sample builds the application in a container based on the larger [.NET Core This sample requires [Docker 17.06](https://docs.docker.com/release-notes/docker-ce) or later of the [Docker client](https://www.docker.com/products/docker). -The [ASP.NET Core Docker Sample](../aspnetapp/README.md) demonstrates how to use ASP.NET Core and Docker together. - ## Try a pre-built .NET Core Docker Image You can quickly try a pre-built [sample .NET Core Docker image](https://hub.docker.com/r/microsoft/dotnet-samples/), based on this sample. @@ -15,7 +13,7 @@ You can quickly try a pre-built [sample .NET Core Docker image](https://hub.dock Type the following command to run a sample with [Docker](https://www.docker.com/products/docker): ```console -docker run --rm microsoft/dotnet-samples +docker run --rm -it microsoft/dotnet-samples ``` ## Getting the sample @@ -43,7 +41,7 @@ The commands above run unit tests as part `docker build`. You can also [run .NET ```console docker build --target testrunner -t dotnetapp:test . -docker run --rm dotnetapp:test +docker run --rm -it dotnetapp:test ``` You can mount a volume while running the image in order to save the test results to your local disk. The instructions to do that are provided in [Running Unit Tests with Docker](dotnet-docker-unit-testing.md) @@ -67,10 +65,10 @@ You can build and run the sample with [Alpine](https://hub.docker.com/_/alpine/) cd samples cd dotnetapp docker build --pull -t dotnetapp:alpine -f Dockerfile.alpine-x64 . -docker run --rm dotnetapp:alpine Hello .NET Core from Alpine +docker run --rm -it dotnetapp:alpine Hello .NET Core from Alpine ``` -[Globalization is disabled](https://github.com/dotnet/announcements/issues/20) by default with Alpine images in order to produce smaller container images. You can re-enable globalization if your application relies on it. [Dockerfile.alpine-x64-globalization](Dockerfile.alpine-x64-globalization) enables globalization for Alpine images, but produces larger images. +[Globalization is disabled](https://github.com/dotnet/announcements/issues/20) by default with Alpine images in order to produce smaller images. You can re-enable globalization if your application relies on it. [Dockerfile.alpine-x64-globalization](Dockerfile.alpine-x64-globalization) enables globalization for Alpine images, but produces larger images. > Related: [.NET Core Alpine Docker Image announcement](https://github.com/dotnet/dotnet-docker-nightly/issues/500) @@ -82,6 +80,10 @@ You can build and run the sample for ARM32 and Raspberry Pi with [Build .NET Cor You can build [Build .NET Core Self-Contained Applications with Docker](dotnet-docker-selfcontained.md). +## Develop ASP.NET Core Applications in a container + +You can develop applications without a .NET Core installation on your machine with the [Develop .NET Core applications in a container](dotnet-docker-dev-in-container.md) instructions. These instructions are also useful if your development and production environments do not match. + ## Run Docker Image on Another Device You can push the image to a container registry so that you can pull and run it on another device. Straightforward instructions are provided for pushing to both Azure Container Registry and DockerHub. diff --git a/samples/dotnetapp/dotnet-docker-dev-in-container.md b/samples/dotnetapp/dotnet-docker-dev-in-container.md new file mode 100644 index 0000000000..633ba5b531 --- /dev/null +++ b/samples/dotnetapp/dotnet-docker-dev-in-container.md @@ -0,0 +1,75 @@ +# Develop .NET Core Applications in a Container + +You can use containers to establish a .NET Core development environment with only Docker and optionally a code editor installed on your machine. The environment can be made to match your local machine, production or both. If you support multiple operating systems, then this approach might become a key part of your development process. + +A common use case of Docker is to [containerize an application](README.md). You can define the environment necessary to run the application and even build the application itself within a Dockerfile. This document describes a much more iterative and dynamic use of Docker, defining the container environment primarily via the commandline. .NET Core includes a command called `dotnet watch` that can rerun your application or your tests on each code change. This document describes how to use the Docker CLI and `dotnet watch` to develop applications in a container. + +See [Develop ASP.NET Core Applications in a Container](../aspnetapp/aspnet-docker-dev-in-container.md) for ASP.NET Core-specific instructions. + +## Getting the sample + +The easiest way to get the sample is by cloning the samples repository with [git](https://git-scm.com/downloads), using the following instructions: + +```console +git clone https://github.com/dotnet/dotnet-docker/ +``` + +You can also [download the repository as a zip](https://github.com/dotnet/dotnet-docker/archive/master.zip). + +## Requirements + +The instructions below use .NET Core 2.1 Preview 2 images. It is possible to make this scenario work with .NET Core 2.0 but requires many extra steps and a bit of magic. You do not need to switch to .NET Core 2.1 on your local machine to try out these instructions. They will work fine with .NET Core 2.0 projects. + +It is recommended that you add a [Directory.Build.props](Directory.Build.props) file to your project to use different `obj` and `bin` folders for local and container use, to avoid conflicts between them. You should delete your existing obj and bin folders before making this change. You can also use `dotnet clean` for this purpose. + +This approach relies on [volume mounting](https://docs.docker.com/engine/admin/volumes/volumes/) (that's the `-v` argument in the following commands) to mount source into the container (without using a Dockerfile). You may need to [Enable shared drives (Windows)](https://docs.docker.com/docker-for-windows/#shared-drives) or [file sharing (macOS)](https://docs.docker.com/docker-for-mac/#file-sharing) first. + +## Run your application in a container while you Develop + +You can rerun your application in a container with every local code change. This scenario works for both console applications and websites. The syntax differs a bit for Windows and Linux containers. + +The instructions assume that you are in the root of the repository. You can use the following commands, given your environment: + +**Windows** using **Linux containers** + +```console +docker run --rm -it -v c:\git\dotnet-docker\samples\dotnetapp:/app/ -w /app/dotnetapp microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +**Linux or macOS** using **Linux containers** + +```console +docker run --rm -it -v ~/git/dotnet-docker/samples/dotnetapp:/app/ -w /app/dotnetapp microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +**Windows** using **Windows containers** + +```console +docker run --rm -it -v c:\git\dotnet-docker\samples\dotnetapp:c:\app\ -w \app\dotnetapp microsoft/dotnet-nightly:2.1-sdk dotnet watch run +``` + +## Test your application in a container while you develop + +You can retest your application in a container with every local code change. This works for both console applications and websites. The syntax differs a bit for Windows and Linux containers. + +The instructions assume that you are in the root of the repository. You can use the following commands, given your environment: + +**Windows** using **Linux containers** + +```console +docker run --rm -it -v c:\git\dotnet-docker\samples\dotnetapp:/app/ -w /app/tests microsoft/dotnet-nightly:2.1-sdk dotnet watch test +``` + +**Linux or macOS** using **Linux containers** + +```console +docker run --rm -it -v ~/git/dotnet-docker/samples/dotnetapp:/app/ -w /app/tests microsoft/dotnet-nightly:2.1-sdk dotnet watch test +``` + +**Windows** using **Windows containers** + +```console +docker run --rm -it -v c:\git\dotnet-docker\samples\dotnetapp:c:\app\ -w \app\tests microsoft/dotnet-nightly:2.1-sdk dotnet watch test +``` + +The commands above log test results to the console. You can additionally log results as a TRX file by appending `--logger:trx` to the previous test commands, specifically `dotnet watch test --logger:trx`. TRX logging is also demonstrated in [Running .NET Core Unit Tests with Docker](dotnet-docker-unit-testing.md). diff --git a/samples/dotnetapp/dotnet-docker-unit-testing.md b/samples/dotnetapp/dotnet-docker-unit-testing.md index dbb3c93e7e..4613b144aa 100644 --- a/samples/dotnetapp/dotnet-docker-unit-testing.md +++ b/samples/dotnetapp/dotnet-docker-unit-testing.md @@ -8,6 +8,16 @@ Running tests via `docker run` is useful as a means of getting complete test res These instructions are based on the [.NET Core Docker Sample](README.md). +## Getting the sample + +The easiest way to get the sample is by cloning the samples repository with [git](https://git-scm.com/downloads), using the following instructions. + +```console +git clone https://github.com/dotnet/dotnet-docker/ +``` + +You can also [download the repository as a zip](https://github.com/dotnet/dotnet-docker/archive/master.zip). + ## Run unit tests as part of `docker build` You can run [unit tests](tests) as part of `docker build`, using the following commands. Running tests in this way is useful to get pass/fail results for building Docker images. The instructions assume that you are in the root of the repository. @@ -39,7 +49,13 @@ docker build -t dotnetapp . ### Run unit tests as part of `docker run` -You can run [unit tests](tests) as part of `docker run` using the following commands. Running tests in this way is useful to get complete tests results for Docker images. The [sample](Dockerfile) exposes multiple [Dockerfile stages](https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage-target) that you can separately target as part of `docker build` and run. The sample includes a `testrunner` stage with a separate `ENTRYPOINT` for unit testing, which is used in the following commands. The instructions assume that you are in the root of the repository. +You can run [unit tests](tests) as part of `docker run` using the following commands. Running tests in this way is useful to get complete tests results for Docker images. The [sample Dockerfile](Dockerfile) exposes multiple [Dockerfile stages](https://docs.docker.com/engine/reference/commandline/build/#specifying-target-build-stage-target) that you can separately target as part of `docker build` and run. The sample Dockerfile includes a `testrunner` stage with a separate `ENTRYPOINT` for unit testing, which is required to maintain a single Dockerfile. + +The following commands rely on [volume mounting](https://docs.docker.com/engine/admin/volumes/volumes/) (that's the `-v` argument in the following commands) to enable the test runner to write test log files to your local drive. Without that, running tests as part of `docker run` isn't as useful. You may need to [Enable shared drives (Windows)](https://docs.docker.com/docker-for-windows/#shared-drives) or [file sharing (macOS)](https://docs.docker.com/docker-for-mac/#file-sharing) first. + +#### Build the testrunner stage + +The instructions assume that you are in the root of the repository. ```console cd samples @@ -53,26 +69,30 @@ If you want to test with Alpine Linux, you can alternatively build with [Dockerf docker build --pull --target testrunner -t dotnetapp -f Dockerfile.alpine-x64 . ``` -The following commands rely on [volume mounting](https://docs.docker.com/engine/admin/volumes/volumes/) (that's the `-v` argument in the following commands) to enable the test runner to write test log files to your local drive. Without that, running tests as part of `docker run` isn't as useful. +#### Run the testrunner stage -You can run the sample on **Windows** using Windows containers using the following command. +Use the following commands, given your environment: + +**Windows** using **Linux containers** ```console -docker run --rm -v C:\git\dotnet-docker\samples\dotnetapp\TestResults:C:\app\tests\TestResults dotnetapp:test +docker run --rm -v C:\git\dotnet-docker\samples\dotnetapp\TestResults:/app/tests/TestResults dotnetapp:test ``` -You can run the sample on **Windows** using Linux containers using the following command. [Enable shared drives](https://docs.docker.com/docker-for-windows/#shared-drives) first. +**Linux or macOS** using **Linux containers** ```console -docker run --rm -v C:\git\dotnet-docker\samples\dotnetapp\TestResults:/app/tests/TestResults dotnetapp:test +docker run --rm -v "$(pwd)"/TestResults:/app/tests/TestResults dotnetapp:test ``` -You can run the sample on **macOS** or **Linux** using the following command. Enable [file sharing](https://docs.docker.com/docker-for-mac/#file-sharing) first. +**Windows** using **Windows containers** ```console -docker run --rm -v "$(pwd)"/TestResults:/app/tests/TestResults dotnetapp:test +docker run --rm -v C:\git\dotnet-docker\samples\dotnetapp\TestResults:C:\app\tests\TestResults dotnetapp:test ``` +#### Reading the Results + You should find a `.trx` file in the TestResults folder. You can open this file in Visual Studio to see the results of the test run, as you can see in the following image. You can open in Visual Studio (File -> Open -> File) or double-click on the TRX file (if you have Visual Studio installed). There are other TRX file viewers available as well that you can search for. ![Visual Studio Test Results](https://user-images.githubusercontent.com/2608468/35361940-2f5ab914-0118-11e8-9c40-4f252f4568f0.png) diff --git a/samples/dotnetapp/dotnetapp/Program.cs b/samples/dotnetapp/dotnetapp/Program.cs index 19016d8bf9..b9136d02d5 100644 --- a/samples/dotnetapp/dotnetapp/Program.cs +++ b/samples/dotnetapp/dotnetapp/Program.cs @@ -1,72 +1,94 @@ using System; using System.Runtime.InteropServices; -using Utils; using System.IO; +using System.Text; +using Utils; using static System.Console; public static class Program { - public static void Main(string[] args) - { - string message = "Hello .NET Core!"; + public static void Main(string[] args) + { + var defaultMessage = "Hello from .NET Core!"; + var bot = GetBot(); + var (message, withColor) = ParseArgs(args); + var output = message == string.Empty ? $" {defaultMessage}{bot}" : $" {message}{bot}"; + + if (withColor) + { + ConsoleUtils.PrintStringWithRandomColor(output); + } + else + { + WriteLine(output); + } - if (args.Length > 0) + WriteLine("**Environment**"); + WriteLine($"Platform: .NET Core"); + WriteLine($"OS: {RuntimeInformation.OSDescription}"); + WriteLine(); + } + + private static (string, bool) ParseArgs(string[] args) + { + var buffer = new StringBuilder(); + var withColor = false; + foreach(var s in args) + { + if (s == "--with-color") { - message = String.Join(" ",args); + withColor = true; + continue; } + buffer.Append(" "); + buffer.Append(s); + } - var bot = $" {message}{GetBot()}"; + return (buffer.ToString(), withColor); + } - ConsoleUtils.PrintStringWithRandomColor(bot); - - WriteLine("**Environment**"); - WriteLine($"Platform: .NET Core"); - WriteLine($"OS: {RuntimeInformation.OSDescription}"); - WriteLine(); - } - - public static string GetBot() - { - - return @" - __________________ - \ - \ - .... - ....' - .... - .......... - .............'..'.. - ................'..'..... - .......'..........'..'..'.... - ........'..........'..'..'..... - .'....'..'..........'..'.......'. - .'..................'... ...... - . ......'......... ..... - . ...... - .. . .. ...... - .... . ....... - ...... ....... ............ - ................ ...................... - ........................'................ - ......................'..'...... ....... - .........................'..'..... ....... - ........ ..'.............'..'.... .......... - ..'..'... ...............'....... .......... - ...'...... ...... .......... ...... ....... - ........... ....... ........ ...... -....... '...'.'. '.'.'.' .... -....... .....'.. ..'..... - .. .......... ..'........ - ............ .............. - ............. '.............. - ...........'.. .'.'............ - ............... .'.'............. - .............'.. ..'..'........... - ............... .'.............. - ......... .............. - ..... + private static string GetBot() + { + + return @" + __________________ + \ + \ + .... + ....' + .... + .......... + .............'..'.. + ................'..'..... + .......'..........'..'..'.... + ........'..........'..'..'..... + .'....'..'..........'..'.......'. + .'..................'... ...... + . ......'......... ..... + . ...... + .. . .. ...... + .... . ....... + ...... ....... ............ + ................ ...................... + ........................'................ + ......................'..'...... ....... + .........................'..'..... ....... + ........ ..'.............'..'.... .......... + ..'..'... ...............'....... .......... + ...'...... ...... .......... ...... ....... + ........... ....... ........ ...... + ....... '...'.'. '.'.'.' .... + ....... .....'.. ..'..... + .. .......... ..'........ + ............ .............. + ............. '.............. + ...........'.. .'.'............ + ............... .'.'............. + .............'.. ..'..'........... + ............... .'.............. + ......... .............. + ..... -"; - } + "; + } } diff --git a/samples/dotnetapp/push-image-to-acr.md b/samples/dotnetapp/push-image-to-acr.md index 0f245055cb..0e522aaced 100644 --- a/samples/dotnetapp/push-image-to-acr.md +++ b/samples/dotnetapp/push-image-to-acr.md @@ -1,6 +1,6 @@ # Push Docker Images to Azure Container Registry -This sample demonstrates how to push .NET Core container images to [Azure Container Registry (ACR)](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal). The instructions are based on the [.NET Core Docker Sample](README.md). +This sample demonstrates how to push .NET Core images to [Azure Container Registry (ACR)](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal). The instructions are based on the [.NET Core Docker Sample](README.md). These instructions use the [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) and the [Docker client](https://www.docker.com/products/docker). diff --git a/samples/dotnetapp/push-image-to-dockerhub.md b/samples/dotnetapp/push-image-to-dockerhub.md index ce44e7ba9f..1a1fd74d79 100644 --- a/samples/dotnetapp/push-image-to-dockerhub.md +++ b/samples/dotnetapp/push-image-to-dockerhub.md @@ -1,6 +1,6 @@ # Push Docker Images to Docker Hub -This sample demonstrates hot to push .NET Core container images to the [Docker Hub](https://hub.docker.com/) container registry. The instructions are based on the [.NET Core Docker Sample](README.md). +This sample demonstrates hot to push .NET Core images to the [Docker Hub](https://hub.docker.com/) container registry. The instructions are based on the [.NET Core Docker Sample](README.md). Similar instructions are also available to [push to Azure Container Registry](push-image-to-acr.md). diff --git a/samples/dotnetapp/tests/tests.csproj b/samples/dotnetapp/tests/tests.csproj index c23df3df30..8f5cff216d 100644 --- a/samples/dotnetapp/tests/tests.csproj +++ b/samples/dotnetapp/tests/tests.csproj @@ -11,6 +11,10 @@ + + + +