120 lines
3.6 KiB
Docker
120 lines
3.6 KiB
Docker
ARG PROJECT=Strata.RxNorm
|
|
ARG VERSION=0.0.0
|
|
ARG SONARURL=''
|
|
ARG SONARLOGIN=''
|
|
ARG SONARBRANCH=''
|
|
|
|
##############
|
|
# Base image #
|
|
##############
|
|
FROM ecr.ops.stratanetwork.net/strata.microsoft.dotnet.aspnet:8.0 AS base
|
|
|
|
# Add TMZ files for CST
|
|
RUN cp /usr/share/zoneinfo/America/Chicago "/usr/share/zoneinfo/Central Standard Time"
|
|
|
|
###############
|
|
# Build image #
|
|
###############
|
|
FROM ecr.ops.stratanetwork.net/strata.microsoft.dotnet.sdk:8.0 AS build
|
|
ARG PROJECT
|
|
ARG VERSION
|
|
ARG SONARURL
|
|
ARG SONARLOGIN
|
|
ARG SONARBRANCH
|
|
|
|
# Add TMZ files for CST
|
|
RUN cp /usr/share/zoneinfo/America/Chicago "/usr/share/zoneinfo/Central Standard Time"
|
|
|
|
WORKDIR /src
|
|
|
|
# Copy project files and restore
|
|
COPY ["${PROJECT}.sln", "${PROJECT}.sln"]
|
|
COPY src/**/*.csproj ./
|
|
RUN for file in $(ls *.csproj); do mkdir -p src/${file%.*}/ && mv $file src/${file%.*}/; done
|
|
COPY tests/**/*.csproj ./
|
|
RUN for file in $(ls *.csproj); do mkdir -p tests/${file%.*}/ && mv $file tests/${file%.*}/; done
|
|
|
|
RUN dotnet restore "${PROJECT}.sln" \
|
|
--source https://api.nuget.org/v3/index.json \
|
|
--source https://proget.sdt.local/nuget/nuget/v3/index.json
|
|
|
|
|
|
# Copy files and build
|
|
COPY . .
|
|
|
|
RUN if [ "${SONARLOGIN}" != "" ] ; then dotnet sonarscanner begin \
|
|
/k:"${PROJECT}" \
|
|
/d:sonar.scm.provider=git \
|
|
/d:sonar.host.url="${SONARURL}" \
|
|
${SONARBRANCH} \
|
|
/d:sonar.login="${SONARLOGIN}" \
|
|
/d:sonar.cs.opencover.reportsPaths="/test-results/cover.xml" \
|
|
/d:sonar.cs.vstest.reportsPaths="/test-results/*.trx" \
|
|
/d:sonar.dependencyCheck.jsonReportPath=/src/buildlogs/dependency-check-report.json \
|
|
/d:sonar.dependencyCheck.htmlReportPath=/src/buildlogs/dependency-check-report.html \
|
|
/v:sonar.projectVersion="${VERSION}"; fi
|
|
|
|
|
|
RUN dotnet build "${PROJECT}.sln" \
|
|
--configuration Release \
|
|
--no-restore
|
|
|
|
# Run tests
|
|
RUN dotnet test "tests/${PROJECT}.Biz.Test.Unit/${PROJECT}.Biz.Test.Unit.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--verbosity=normal \
|
|
-p:CollectCoverage=true \
|
|
-p:CoverletOutputFormat="opencover" \
|
|
-p:CoverletOutput=/test-results/cover.xml
|
|
|
|
# Publish project
|
|
RUN dotnet publish "src/${PROJECT}.Api/${PROJECT}.Api.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--output /app
|
|
|
|
# Pack client project
|
|
RUN dotnet pack "src/${PROJECT}.Client/${PROJECT}.Client.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--include-symbols \
|
|
--include-source \
|
|
--output /pack \
|
|
-property:PackageVersion=${VERSION}
|
|
|
|
RUN mkdir -p /src/buildlogs
|
|
|
|
RUN if [ "${SONARLOGIN}" != "" ] ; then \
|
|
/dc/dependency-check/bin/dependency-check.sh -f JSON -f HTML -s . -o ./buildlogs \
|
|
--suppression ./sonarsuppressions.xml \
|
|
--noupdate --nodeAuditSkipDevDependencies --disableNodeJS --disableRetireJS --ossIndexRemoteErrorWarnOnly true \
|
|
--dbDriverName "com.microsoft.sqlserver.jdbc.SQLServerDriver" \
|
|
--connectionString "jdbc:sqlserver://ddensqldevops01.sdt.local;Database=DependencyCheck;encrypt=true;trustServerCertificate=true;" \
|
|
--dbUser "dcuser" --dbPassword "${SONARLOGIN}" && \
|
|
dotnet sonarscanner end /d:sonar.login="${SONARLOGIN}"; \
|
|
fi
|
|
|
|
RUN touch /src/buildlogs/dependency-check-report.html
|
|
|
|
###############
|
|
# Final image #
|
|
###############
|
|
FROM base AS final
|
|
ARG PROJECT
|
|
WORKDIR /app
|
|
ARG PROJECT
|
|
ENV PROJECTDLL=${PROJECT}.Api.dll
|
|
ENV DOTNET_ENVIRONMENT=Development
|
|
ENV ASPNETCORE_ENVIRONMENT=Development
|
|
|
|
COPY --from=build /app /app
|
|
COPY --from=build /pack /pack
|
|
COPY --from=build /test-results /test-results
|
|
COPY --from=build /src/buildlogs/dependency-check-report.html /dc/dependency-check-report.html
|
|
|
|
ENTRYPOINT dotnet ${PROJECTDLL}
|