157 lines
4.9 KiB
Docker
157 lines
4.9 KiB
Docker
ARG PROJECT=Strata.Stratasphere
|
|
ARG VERSION=0.0.0
|
|
ARG SONARURL=''
|
|
ARG SONARLOGIN=''
|
|
ARG SONARBRANCH=''
|
|
ARG STRATASPHERE_TESTS_AWS_ACCESS_KEY_ID=''
|
|
ARG STRATASPHERE_TESTS_AWS_SECRET_ACCESS_KEY=''
|
|
|
|
##############
|
|
# Base image #
|
|
##############
|
|
FROM ecr.ops.stratanetwork.net/strata.microsoft.dotnet.aspnet:6.0 AS base
|
|
|
|
# Add TMZ files for CST
|
|
RUN cp /usr/share/zoneinfo/America/Los_Angeles "/usr/share/zoneinfo/Pacific Standard Time"
|
|
RUN cp /usr/share/zoneinfo/America/Chicago "/usr/share/zoneinfo/Central Standard Time"
|
|
|
|
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
|
|
|
|
RUN apt-get update --allow-releaseinfo-change \
|
|
&& apt-get install -y \
|
|
libc6-dev \
|
|
libgdiplus \
|
|
libx11-dev \
|
|
ttf-mscorefonts-installer \
|
|
fontconfig \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
###############
|
|
# Build image #
|
|
###############
|
|
FROM ecr.ops.stratanetwork.net/strata.microsoft.dotnet.sdk:6.0 as build
|
|
ARG PROJECT
|
|
ARG VERSION
|
|
ARG SONARURL
|
|
ARG SONARLOGIN
|
|
ARG SONARBRANCH
|
|
ARG STRATASPHERE_TESTS_AWS_ACCESS_KEY_ID
|
|
ARG STRATASPHERE_TESTS_AWS_SECRET_ACCESS_KEY
|
|
|
|
ENV AWS_ACCESS_KEY_ID=${STRATASPHERE_TESTS_AWS_ACCESS_KEY_ID}
|
|
ENV AWS_SECRET_ACCESS_KEY=${STRATASPHERE_TESTS_AWS_SECRET_ACCESS_KEY}
|
|
ENV AWS_DEFAULT_REGION=us-east-1
|
|
|
|
COPY ["awsconfig", "/root/.aws/config"]
|
|
|
|
# Add TMZ files for CST
|
|
RUN cp /usr/share/zoneinfo/America/Los_Angeles "/usr/share/zoneinfo/Pacific Standard Time"
|
|
RUN cp /usr/share/zoneinfo/America/Chicago "/usr/share/zoneinfo/Central Standard Time"
|
|
|
|
RUN apt-get update --allow-releaseinfo-change \
|
|
&& apt-get install -y \
|
|
libc6-dev \
|
|
libgdiplus \
|
|
libx11-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
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="/src/cover.xml" \
|
|
/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}.Api.APITests/${PROJECT}.Api.APITests.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--verbosity=normal \
|
|
--logger "trx;LogFileName=/test-results/api-api-tests.trx" \
|
|
-p:CollectCoverage=true \
|
|
-p:CoverletOutputFormat="json" \
|
|
-p:CoverletOutput=/test-results/cover.json \
|
|
|| true
|
|
|
|
RUN dotnet test "tests/${PROJECT}.Api.UnitTests/${PROJECT}.Api.UnitTests.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--verbosity=normal \
|
|
--logger "trx;LogFileName=/test-results/api-unit-tests.trx" \
|
|
-p:CollectCoverage=true \
|
|
-p:CoverletOutputFormat="json" \
|
|
-p:CoverletOutput=/test-results/cover-apiUnit.json \
|
|
-p:MergeWith=/test-results/cover.json \
|
|
|| true
|
|
|
|
RUN dotnet test "tests/${PROJECT}.Biz.UnitTests/${PROJECT}.Biz.UnitTests.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--verbosity=normal \
|
|
--logger "trx;LogFileName=/test-results/unit-tests.trx" \
|
|
-p:CollectCoverage=true \
|
|
-p:CoverletOutputFormat="opencover" \
|
|
-p:CoverletOutput=/test-results/cover.xml \
|
|
-p:MergeWith=/test-results/cover-apiUnit.json \
|
|
|| true
|
|
|
|
# Publish project
|
|
RUN dotnet publish "src/${PROJECT}.Api/${PROJECT}.Api.csproj" \
|
|
--configuration Release \
|
|
--no-restore \
|
|
--no-build \
|
|
--output /app
|
|
|
|
RUN if [ "${SONARLOGIN}" != "" ] ; then \
|
|
(/dc/dependency-check/bin/dependency-check.sh -f JSON -f HTML -s . -o ./buildlogs \
|
|
--suppression ./sonarsuppressions.xml \
|
|
--noupdate --nodeAuditSkipDevDependencies --disableNodeJS \
|
|
--dbDriverName "com.microsoft.sqlserver.jdbc.SQLServerDriver" \
|
|
--connectionString "jdbc:sqlserver://ddensqldevops01.sdt.local;Database=DependencyCheck;encrypt=true;trustServerCertificate=true;" \
|
|
--dbUser "dcuser" --dbPassword "${SONARLOGIN}" || true) && \
|
|
dotnet sonarscanner end /d:sonar.login="${SONARLOGIN}"; \
|
|
fi
|
|
|
|
###############
|
|
# 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 /test-results /test-results
|
|
|
|
ENTRYPOINT dotnet ${PROJECTDLL}
|