FROM public.ecr.aws/lambda/dotnet:7 AS base

FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim as build
WORKDIR /src
COPY ["ServerlessWebApiNet7.csproj", "ServerlessWebApiNet7/"]
RUN dotnet restore "ServerlessWebApiNet7/ServerlessWebApiNet7.csproj"

WORKDIR "/src/ServerlessWebApiNet7"
COPY . .
RUN dotnet build "ServerlessWebApiNet7.csproj" --configuration Release --output /app/build

FROM build AS publish
RUN dotnet publish "ServerlessWebApiNet7.csproj" \
            --configuration Release \ 
            --runtime linux-x64 \
            --self-contained false \ 
            --output /app/publish \
            -p:PublishReadyToRun=true  

FROM base AS final
WORKDIR /var/task
COPY --from=publish /app/publish .
