#######################################################
# Step 1: Build the application in a container #
#######################################################
# Download the official ASP.NET Core SDK image
# to build the project while creating the docker image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG SONAR_OGRANIZAION_KEY=[Redacted]
ARG SONAR_PROJECT_KEY=[Redacted]
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN=[Redacted]
WORKDIR /app
EXPOSE 80
# Install Sonar Scanner, Coverlet and Java (required for Sonar Scanner)
RUN apt-get update && apt-get install -y openjdk-17-jdk-headless
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global coverlet.console
ENV PATH="$PATH:/root/.dotnet/tools"
# Start Sonar Scanner
RUN dotnet sonarscanner begin \
/k:"$SONAR_PROJECT_KEY" \
/o:"$SONAR_OGRANIZAION_KEY" \
/d:sonar.host.url="$SONAR_HOST_URL" \
/d:sonar.login="$SONAR_TOKEN" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml
# Restore NuGet packages
COPY . .
RUN dotnet restore
# Build and test the application
RUN dotnet publish --output /app/out/
RUN dotnet test \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover
# End Sonar Scanner
RUN dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
# Copy the rest of the files over
COPY . .
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "DotNet.Docker.dll"]
ALM used: Azure DevOps
CI system: Azure DevOps
Scanner command: RUN dotnet sonarscanner end /d:sonar.login=“$SONAR_TOKEN”
#######################################################
# Step 1: Build the application in a container #
#######################################################
# Download the official ASP.NET Core SDK image
# to build the project while creating the docker image
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG SONAR_OGRANIZAION_KEY=[Redacted]
ARG SONAR_PROJECT_KEY=[Redacted]
ARG SONAR_HOST_URL=https://sonarcloud.io
ARG SONAR_TOKEN=[Redacted]
ARG PULLREQUEST_ID
ARG SOURCE_BRANCH_NAME
ARG TARGET_BRANCH_NAME
ARG PROJECT
ARG REPOSITORY
ARG INSTANCEURL
WORKDIR /app
RUN echo ${PROJECT}
RUN echo ${REPOSITORY}
RUN echo ${INSTANCEURL}
RUN echo ${PULLREQUEST_ID}
RUN echo ${SOURCE_BRANCH_NAME}
RUN echo ${TARGET_BRANCH_NAME}
RUN echo ${SONAR_PROJECT_KEY}
EXPOSE 80
# Install Sonar Scanner, Coverlet and Java (required for Sonar Scanner)
RUN apt-get update && apt-get install -y openjdk-17-jdk-headless
RUN dotnet tool install --global dotnet-sonarscanner
RUN dotnet tool install --global coverlet.console
ENV PATH="$PATH:/root/.dotnet/tools"
# Start Sonar Scanner
RUN dotnet sonarscanner begin \
/k:"${SONAR_PROJECT_KEY}" \
/o:"${SONAR_OGRANIZAION_KEY}" \
/d:sonar.host.url="${SONAR_HOST_URL}" \
/d:sonar.login="${SONAR_TOKEN}" \
/d:sonar.cs.opencover.reportsPaths=/coverage.opencover.xml\
/d:sonar.pullrequest.key=${PULLREQUEST_ID}\
/d:sonar.pullrequest.branch=${SOURCE_BRANCH_NAME}\
/d:sonar.pullrequest.base=${TARGET_BRANCH_NAME}\
/d:sonar.pullrequest.vsts.project=${PROJECT}\
/d:sonar.pullrequest.vsts.repository=${REPOSITORY}\
/d:sonar.pullrequest.vsts.instanceUrl=${INSTANCEURL}
# Restore NuGet packages
COPY . .
RUN dotnet restore
# Build and test the application
RUN dotnet publish --output /app/out/
RUN dotnet test \
/p:CollectCoverage=true \
/p:CoverletOutputFormat=opencover
# End Sonar Scanner
RUN dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}"
# Copy the rest of the files over
COPY . .
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "layoutboards.dll"]