# Migrations runner
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# Install EF Core tools
RUN dotnet tool install --global dotnet-ef
ENV PATH="$PATH:/root/.dotnet/tools"

# Copy solution and project files
COPY RealCV.sln ./
COPY src/RealCV.Domain/RealCV.Domain.csproj src/RealCV.Domain/
COPY src/RealCV.Application/RealCV.Application.csproj src/RealCV.Application/
COPY src/RealCV.Infrastructure/RealCV.Infrastructure.csproj src/RealCV.Infrastructure/
COPY src/RealCV.Web/RealCV.Web.csproj src/RealCV.Web/

# Restore dependencies
RUN dotnet restore

# Copy all source code
COPY src/ src/

# Build the project
RUN dotnet build src/RealCV.Web/RealCV.Web.csproj -c Release

# Run migrations on startup
ENTRYPOINT ["dotnet", "ef", "database", "update", "--project", "src/RealCV.Infrastructure", "--startup-project", "src/RealCV.Web", "--no-build", "-c", "Release"]
