# syntax=docker/dockerfile:1

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

COPY ["FileAccessAgent.sln", "./"]
COPY ["src/FileAccessAgent.Api/FileAccessAgent.Api.csproj", "src/FileAccessAgent.Api/"]
COPY ["src/FileAccessAgent.Application/FileAccessAgent.Application.csproj", "src/FileAccessAgent.Application/"]
COPY ["src/FileAccessAgent.Domain/FileAccessAgent.Domain.csproj", "src/FileAccessAgent.Domain/"]
COPY ["src/FileAccessAgent.Infrastructure/FileAccessAgent.Infrastructure.csproj", "src/FileAccessAgent.Infrastructure/"]
RUN dotnet restore "src/FileAccessAgent.Api/FileAccessAgent.Api.csproj"

COPY . .
WORKDIR /src/src/FileAccessAgent.Api
RUN dotnet publish "FileAccessAgent.Api.csproj" \
    -c "$BUILD_CONFIGURATION" \
    -o /app/publish \
    --no-restore \
    /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:8080 \
    DOTNET_RUNNING_IN_CONTAINER=true
EXPOSE 8080

RUN mkdir -p /app/data/storage && chown -R "$APP_UID:$APP_UID" /app/data
USER $APP_UID

COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "FileAccessAgent.Api.dll"]
