I am working on implementing a solution for a sonar scanner inside a docker container for the .net core application in azure DevOps.
Currently, the sonarqube installed was on a sonarqube namespace in the AKS cluster and our dot net application is containerized in a different namespace in the same cluster. I'm struggling with the following error: The temporary analysis directory (usually .sonarqube) doesn't exist. The "begin" step was probably not executed. Is there any sample or working Docker file which implements this type of logic? I tried to follow the steps described in this blog post but the result is the same.
Here is my Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
RUN apt-get update && apt-get install -y openjdk-11-jdk
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global dotnet-reportgenerator-globaltool
RUN dotnet tool install --global coverlet.console
## Set the dotnet tools folder in the PATH env variable
ENV PATH="$PATH:/root/.dotnet/tools"
## Start scanner
RUN dotnet sonarscanner begin \
/k:"my-token" \
/o:"my-org" \
/d:sonar.host.url="sonar-host" \
/d:sonar.login="sonar-token" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml
COPY my-project/*.csproj ./my-project/
COPY . .
WORKDIR /src/my-project
RUN dotnet restore
RUN dotnet build -c Release -o /app/build --no-restore
RUN dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="/coverage"
## Stop scanner
RUN dotnet sonarscanner end /d:sonar.login="sonar-token"
FROM build AS publish
WORKDIR /src/my-project
RUN dotnet publish -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "my-project.dll"]
I believe your issue may be running dotnet restore after the sonarscanner begin. If you re-arrange those steps, you should be OK.
Related
Since container is not building with the full project I commented docker file as bellow . then I executed manually dotnet build command inside container. it failed like below. But when I build the container from outside from the visual studio it is building fine.
Determining projects to restore...
All projects are up-to-date for restore.
myapp -> /app/build/myapp.dll
myapp -> /app/build/myapp.Views.dll
/bin/sh: 2: /tmp/tmped91456469694a38bc5ed8e7d4b423b1.exec.cmd: docker: not found
/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/1.11.1/build/Container.targets(97,5): error : Docker is not installed or is not in the current PATH. [/src/myapp/myapp.csproj]
Build FAILED.
/root/.nuget/packages/microsoft.visualstudio.azure.containers.tools.targets/1.11.1/build/Container.targets(97,5): error : Docker is not installed or is not in the current PATH. [/src/myapp/myapp.csproj]
0 Warning(s)
1 Error(s)
Here is the my Dockerfile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
RUN apt-get update && \
apt-get install -y wget && \
apt-get install -y gnupg2 && \
wget -qO- https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y build-essential nodejs
COPY ["myapp/myapp.csproj", "myapp/"]
COPY ["myapp/NuGet.Config", "myapp/"]
RUN dotnet restore "myapp/myapp.csproj" --configfile myapp/NuGet.Config
COPY . .
WORKDIR "/src/myapp"
#RUN dotnet build "myapp.csproj" -c Release -o /app/build
#FROM build AS publish
#RUN dotnet publish "myapp.csproj" -c Release -o /app/publish
#FROM base AS final
#WORKDIR /app
#COPY --from=publish /app/publish .
#ENTRYPOINT ["dotnet", "myapp.dll"]
ENTRYPOINT ["tail", "-f", "/dev/null"]
Here is a Dockerfile and I wonder why with a slight change in C# code rebuilding the image takes a lot of time compared to Python. I read all tips and still no chance. Is there a way to improve it?
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
RUN apt-get update && apt-get install -y libldap-2.4-2
RUN apt-get install curl -y
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["test/testAdmin.csproj", "test/"]
COPY ["testDal/testDal.csproj", "testDal/"]
COPY ["testCore/testCore.csproj", "testCore/"]
RUN dotnet restore "test/testAdmin.csproj"
COPY . .
WORKDIR "/src/testAdmin"
RUN pwd
RUN ls
RUN mv appsettings.json appsettings.json
RUN dotnet build "testAdmin.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "testAdmin.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "testAdmin.dll"]
For production environment this is OK but for testing we need faster builds for every pull.
I want to host aspnet 6.0 application in docker container on AlmaLinux (or any centos compatible destro). The application also needs to have maprdrill odbc client that is available only in rpm package. Problem is the base images Microsoft provides are based on debian, alpine and ubuntu only (see here) and none of them let me install rpm package.
I also tried to convert the rpm to deb using alien, conversion was success and package was installed but due to some unknown reason the installation created a layer of 400mb that takes only 80mb on centos and the client appears to not work as well.
What other options I've to install rpm package in aspnet 6 app docker image?
Here is my docker file that understandably fails on line 29:
# base
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
# build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["HelloWorld/HelloWorld.csproj", "HelloWorld/"]
RUN dotnet restore "HelloWorld/HelloWorld.csproj"
COPY . .
WORKDIR "/src/HelloWorld"
RUN dotnet build "HelloWorld.csproj" -c Release -r rhel-x64 --self-contained false -o /app/build
# publish
FROM build AS publish
RUN dotnet publish "HelloWorld.csproj" -c Release -r rhel-x64 --self-contained false -o /app/publish
FROM base AS final
RUN apt update
WORKDIR /app
COPY --from=publish /app/publish .
WORKDIR /mapr
RUN apt-get -yq install wget
RUN wget http://package.mapr.com/tools/MapR-ODBC/MapR_Drill/MapRDrill_odbc_v1.5.1.1002/maprdrill-1.5.1.1002-1.el7.x86_64.rpm
RUN rpm -i maprdrill-1.5.1.1002-1.el7.x86_64.rpm
ENTRYPOINT ["dotnet", "HelloWorld.dll"]
I have an application in .net core 3.1 and I am building a docker file to put the application in a container, when I try to build the image I get the following error:
The command '/bin/sh -c dotnet restore "ApiDigitalGamesMx/ApiDigitalGamesMx.csproj"' returned a non-
zero code: 1
I run this command:
docker build -t image-netcore:1.0 .
And this is my dockerFile:
FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["ApiDigitalGamesMx/ApiDigitalGamesMx.csproj", "./"]
RUN dotnet restore "ApiDigitalGamesMx/ApiDigitalGamesMx.csproj"
COPY ["ApiProducts.Library/ApiProducts.Library.csproj", "./"]
RUN dotnet restore "ApiProducts.Library/ApiProducts.Library.csproj"
COPY . .
RUN dotnet build "ApiDigitalGamesMx/ApiDigitalGamesMx.csproj" -c Release -o /app/build
RUN dotnet build "ApiProducts.Library/ApiProducts.Library.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "ApiDigitalGamesMx/ApiDigitalGamesMx.csproj" -c Release -o /app/publish
RUN dotnet publish "ApiProducts.Library/ApiProducts.Library.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ApiDigitalGamesMx.dll"]
Is there any kind of solution that I can implement?
Need to containerize the Solution Build on Microsoft Information Protection SDK 1.6 in linux Container Architecture. Always receiving common error of dllNotFound.
Error Received while executing MIP Initialization: MIP.Initialize(MipComponent.File);
Unable to load shared library 'kernel32.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libkernel32.dll: cannot open shared object file: No such file or directory
at Microsoft.InformationProtection.Utils.UnsafeKernel32NativeMethods.LoadLibrary(String dllToLoad)
at Microsoft.InformationProtection.Utils.Loader.LoadDlls(String dllFolder, String dllName, String[] dllDependencies)
at Microsoft.InformationProtection.MIP.Initialize(MipComponent mipComponent, String path)
at MIPSolution.Program.Main(String[] args) in /src/Program.cs:line 55
Dockerfile to Execute the Application:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY ["MIPSolution.csproj", "./"]
RUN dotnet restore "MIPSolution.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "MIPSolution.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MIPSolution.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
# RUN dotnet --info
RUN echo "Build number: $buildno"
ENTRYPOINT ["dotnet", "MIPSolution.dll"]
All suggestions to make this application working will be very helpful.
Thanks