From 752ab33c4ce518516743815de0b232c4061d23ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gil=20Assun=C3=A7=C3=A3o?= Date: Wed, 30 Oct 2019 16:11:06 +0000 Subject: [PATCH] Updated DotNetCore v3 dotnet-sonar image and Readme file --- Dockerfile | 24 +++++-- README.md | 183 +++++++++++++++++++++++++++-------------------------- 2 files changed, 114 insertions(+), 93 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab677ac..13ad6a6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,15 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.0.100 -# reviewing this choice -ENV SONAR_SCANNER_MSBUILD_VERSION 4.7.1.2311 +# Dockerfile meta-information +LABEL maintainer="NOS Inovação S.A." \ + app_name="dotnet-sonar" -ENV DOCKER_VERSION 5:19.03.2~3-0~debian-buster -ENV CONTAINERD_VERSION 1.2.6-3 +# Reviewing this choices +ENV SONAR_SCANNER_MSBUILD_VERSION=4.7.1.2311 \ + DOTNETCORE_SDK=3.0.100 \ + DOTNETCORE_RUNTIME=2.2.7 \ + DOCKER_VERSION=5:19.03.2~3-0~debian-buster \ + CONTAINERD_VERSION=1.2.6-3 RUN apt-get update \ && apt-get dist-upgrade -y @@ -37,6 +42,16 @@ RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - \ libtool \ nasm +# Register Microsoft key and feed +RUN wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ + && dpkg -i packages-microsoft-prod.deb + +# Install DotNetCore 2.1 Runtime-Only for SonarScanner +RUN apt-get update -y \ + && apt-get install apt-transport-https -y \ + && apt-get update -y \ + && apt-get install aspnetcore-runtime-2.2 -y + # Install Sonar Scanner RUN apt-get install -y unzip \ && wget https://github.com/SonarSource/sonar-scanner-msbuild/releases/download/$SONAR_SCANNER_MSBUILD_VERSION/sonar-scanner-msbuild-$SONAR_SCANNER_MSBUILD_VERSION-netcoreapp2.0.zip \ @@ -48,3 +63,4 @@ RUN apt-get install -y unzip \ RUN apt-get -q autoremove \ && apt-get -q clean -y \ && rm -rf /var/lib/apt/lists/* /var/cache/apt/*.bin + diff --git a/README.md b/README.md index 958186f..e5ffed6 100644 --- a/README.md +++ b/README.md @@ -7,62 +7,52 @@ It also allows you to run Docker in Docker using a docker.sock mount. ---- This latest image was built with the following components: -* dotnet-sdk-3.0.100 +* dotnetcore-sdk-3.0.100 +* dotnetcore-runtime-2.2.7 (required by Sonar Scanner) * SonarQube MSBuild Scanner 4.7.1.2311 -* OpenJDK Java 11 (required by Sonar Scanner) +* OpenJDK Java Runtime 11 (required by Sonar Scanner) * Docker binaries 19.03.1 (for running Docker in Docker using the docker.sock mount) * NodeJS 11 [![Docker Build Status](https://img.shields.io/docker/build/nosinovacao/dotnet-sonar.svg)](dotnet-sonar) -## Tags - -Tags are written using the following pattern: `dotnet-sonar:..` - -* dotnet-sonar:19.10.0 - * With: - * DotNetCore SDK 3.0.100 - * SonarScanner 4.7.1.2311 -* dotnet-sonar:19.09.0 - * With: - * DotNetCore SDK 2.2.402 - * SonarScanner 4.7.1.2311 -* dotnet-sonar:19.08.0 - * With: - * DotNetCore SDK 2.2.401 - * SonarScanner 4.6.2.2108 -* dotnet-sonar:19.01.0 - * With: - * DotNetCore SDK 2.2.103 - * SonarScanner 4.5.0.1761 -* dotnet-sonar:18.12.1 - * With: - * DotNetCore SDK 2.2.100 - * SonarScanner 4.4.2.1543 -* dotnet-sonar:18.09.0 - * With: - * DotNetCore SDK 2.1.401 - * SonarScanner 4.3.1.1372 -* dotnet-sonar:18.07.0 - * With: - * DotNetCore SDK 2.1 - * SonarScanner 4.3.1.1372 -* dotnet-sonar:18.05.0 - * With: - * DotNetCore SDK 2.0.7 - * SonarScanner 4.2.0.1214 -* dotnet-sonar:18.03.1 - * With: - * DotNetCore SDK 2.0 - * SonarScanner 4.1.0.1148 -* dotnet-sonar:18.03.0 - * With: - * DotNetCore SDK 2.0 - * SonarScanner 4.0.2.892 -* dotnet-sonar:2-4.0.2 - * With: - * DotNetCore SDK 2 - * SonarScanner 4.0.2.892 +## Supported tags and respective `Dockerfile` links + +> Tags are written using the following pattern: `dotnet-sonar:..` + +* `19.10.1`, `latest` [(19.10.1/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/19.10.1/Dockerfile) + * DotNetCore SDK 3.0.100 + * SonarScanner 4.7.1.2311 +* `19.09.0` [(19.09-0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/19.09.0/Dockerfile) + * DotNetCore SDK 2.2.402 + * SonarScanner 4.7.1.2311 +* `19.08.0` [(19.08.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/19.08.0/Dockerfile) + * DotNetCore SDK 2.2.401 + * SonarScanner 4.6.2.2108 +* `19.01.0` [(19.01.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/19.01.0/Dockerfile) + * DotNetCore SDK 2.2.103 + * SonarScanner 4.5.0.1761 +* `18.12.1` [(18.12.1/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.12.1/Dockerfile) + * DotNetCore SDK 2.2.100 + * SonarScanner 4.4.2.1543 +* `18.09.0` [(18.09.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.09.0/Dockerfile) + * DotNetCore SDK 2.1.401 + * SonarScanner 4.3.1.1372 +* `18.07.0` [(18.07.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.07.0/Dockerfile) + * DotNetCore SDK 2.1 + * SonarScanner 4.3.1.1372 +* `18.05.0` [(18.05.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.05.0/Dockerfile) + * DotNetCore SDK 2.0.7 + * SonarScanner 4.2.0.1214 +* `18.03.1` [(18.03.1/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.03.1/Dockerfile) + * DotNetCore SDK 2.0 + * SonarScanner 4.1.0.1148 +* `18.03.0` [(18.03.0/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/18.03.0/Dockerfile) + * DotNetCore SDK 2.0 + * SonarScanner 4.0.2.892 +* `2-4.0.2` [(2-4.0.2/Dockerfile)](https://github.com/nosinovacao/dotnet-sonar/blob/2-4.0.2/Dockerfile) + * DotNetCore SDK 2 + * SonarScanner 4.0.2.892 More info on docker hub: @@ -77,54 +67,55 @@ Full documentation: :/source nosinovacao/dotnet-sonar:latest bash -c "cd source \ -&& dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin /k:sonarProjectKey /name:sonarProjectName /version:buildVersion \ -&& dotnet restore \ -&& dotnet build -c Release \ -&& dotnet /sonar-scanner/SonarScanner.MSBuild.dll end" +$ docker run -it --rm -v :/source nosinovacao/dotnet-sonar:latest bash -c "cd source \ + && dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin /k:sonarProjectKey /name:sonarProjectName /version:buildVersion \ + && dotnet restore \ + && dotnet build -c Release \ + && dotnet /sonar-scanner/SonarScanner.MSBuild.dll end" ``` Advance Usage: ```bash -docker run -it --rm \ --v :/source \ --v :/nuget \ -dotnet-sonar:19.10.0 \ -bash -c \ -"cd source \ -&& dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin \ -/k: /name: /version: \ -/d:sonar.host.url="" \ -/d:sonar.login="" \ -/d:sonar.password="" \ -/d:sonar.cs.opencover.reportsPaths='tests/**/coverage.opencover.xml' \ -&& dotnet restore --configfile /nuget/NuGet.Config \ -&& dotnet build -c Release \ -&& dotnet publish -c Release -r linux-x64 -o deployment \ -&& dotnet test --no-build -c Release --filter "Category=Unit" --logger trx --results-directory testResults /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover\" \ -&& dotnet /sonar-scanner/SonarScanner.MSBuild.dll end \ -/d:sonar.login="" \ -/d:sonar.password=""" +$ docker run -it --rm \ + -v :/source \ + -v :/nuget \ +$ dotnet-sonar:19.10.1 \ +$ bash -c \ + "cd source \ + && dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin \ + /k: /name: /version: \ + /d:sonar.host.url="" \ + /d:sonar.login="" \ + /d:sonar.password="" \ + /d:sonar.cs.opencover.reportsPaths='tests/**/coverage.opencover.xml' \ + && dotnet restore --configfile /nuget/NuGet.Config \ + && dotnet build -c Release \ + && dotnet publish -c Release -r linux-x64 -o deployment \ + && dotnet test --no-build -c Release --filter "Category=Unit" --logger trx --results-directory testResults /p:CollectCoverage=true / p:CoverletOutputFormat=\"opencover\" \ + && dotnet /sonar-scanner/SonarScanner.MSBuild.dll end \ + /d:sonar.login="" \ + /d:sonar.password=""" ``` The script above does the following: + * Mounts your project folder to the container's /source folder * Mounts your nuget config to the container's /nuget folder (optional if no private nuget server is used) * Begins the sonarscanner with the sonarqube server credentials @@ -147,11 +138,21 @@ The following pipeline code will: *Note that in order for coverage analysis to work, you need to add the coverlet NuGet package to the unit test project.* ```groovy -node('somenode-with-docker') { - withSonarQubeEnv('my-jenkins-configured-sonar-environment') { - docker.image('nosinovacao/dotnet-sonar:latest').inside() { - withEnv(['HOME=/tmp/home','DOTNET_CLI_TELEMETRY_OPTOUT=1']) { - stage('build') { +def envVariables = [ + 'HOME=/tmp/home', + 'DOTNET_CLI_TELEMETRY_OPTOUT=1' +] + +node('somenode-with-docker') +{ + withSonarQubeEnv('my-jenkins-configured-sonar-environment') + { + docker.image('nosinovacao/dotnet-sonar:latest').inside() + { + withEnv(envVariables) + { + stage('build') + { checkout scm sh "dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin /k:someKey /name:someName /version:someVersion /d:sonar.cs.opencover.reportsPaths='tests/**/coverage.opencover.xml'" sh "dotnet build -c Release /property:Version=someVersion" @@ -167,9 +168,11 @@ node('somenode-with-docker') { } } -timeout(time: 1, unit: 'HOURS') { +timeout(time: 1, unit: 'HOURS') +{ def qualityGate = waitForQualityGate() - if (qualityGate.status == 'ERROR') { + if (qualityGate.status == 'ERROR') + { currentBuild.result = 'UNSTABLE' } } @@ -182,9 +185,11 @@ Please note that if you want to use Docker inside Docker (DinD) you need to perf **The following actions will expose your host to several security vulnerabilities** and therefore this should only be used when you absolutely must to: ```groovy -docker.image('nosinovacao/dotnet-sonar:latest').inside("--group-add docker -v /var/run/docker.sock:/var/run/docker.sock") { +docker.image('nosinovacao/dotnet-sonar:latest').inside("--group-add docker -v /var/run/docker.sock:/var/run/docker.sock") +{ // Some stuff - docker.image.('hello-world:latest').inside() { + docker.image.('hello-world:latest').inside() + { sh "echo 'hello from docker inside docker'" } }