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

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

ADD . /opt/csi-service

# Add Scanner package
WORKDIR /opt/csi-service/Source
RUN for D in *; do if [ -d "${D}" ] && [ "$(echo $D | grep -c Test)" -eq "0" ]; then (cd /opt/csi-service/Source/$D && dotnet add package Twitch.Security.Code.Scanner --no-restore); fi; done

# Build & scan
WORKDIR /opt/csi-service
RUN dotnet restore --verbosity q
RUN ["dotnet", "build", "-c", "Debug", "-o", "dist", "/flp:NoSummary;Verbosity=q;LogFile=/opt/csi-service/scan.log", "/property:TreatWarningsAsErrors=False"]

CMD ["rsync", "-a", "--delete", "--numeric-ids", "--chown", "15000:15000", "/opt/csi-service/scan.log", "/dist/scan.log"]
