FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine

RUN apk update
RUN apk add --no-cache rsync curl bash

ARG TEAMCITY_VERSION
ARG TEAMCITY_BUILD_BRANCH
ARG TEAMCITY_BUILD_ID
ARG TEAMCITY_BUILD_URL
ARG TEAMCITY_BUILD_COMMIT
ARG TEAMCITY_BUILD_REPOSITORY
ARG BUILD_NUMBER
ARG TEAMCITY_PROJECT_NAME=AuditLogService

ADD . /opt/audit-log-service

# Test Audit Log Service
WORKDIR /opt/audit-log-service/Source/Twitch.AuditLogService.Tests
RUN dotnet restore
RUN dotnet test --logger:"console;verbosity=normal" /p:CollectCoverage=true /p:Include=\"[Twitch.AuditLogService.Web]*,[Twitch.AuditLogService]*\" /p:CoverletOutputFormat=\"cobertura,teamcity\" /p:CoverletOutput=/opt/audit-log-service/
# Report Test Coverage
WORKDIR /opt/audit-log-service
RUN curl -s https://codecov.internal.justin.tv/bash > codecov
RUN chmod +x codecov
RUN bash codecov -f "coverage.cobertura.xml" -t ghe -y codecov.yml -n $BUILD_NUMBER

WORKDIR /opt/audit-log-service/Source/Twitch.AuditLogService.Web
RUN dotnet restore && \
    dotnet publish -c Release -o dist

CMD ["rsync", "-a", "--delete", "--numeric-ids", "--chown", "15000:15000", "/opt/audit-log-service/Source/Twitch.AuditLogService.Web/dist/", "/dist/"]