FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /App

# Copy everything
COPY . ./
# Restore as distinct layers
RUN dotnet restore
# Build and publish a release
RUN dotnet publish -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /App
COPY --from=build-env /App/out .

RUN apt-get update 
RUN apt-get -y install curl

HEALTHCHECK --interval=5s --timeout=1s --start-period=20s --retries=3 CMD curl --silent --fail http://localhost/_health/live || exit 1
ENTRYPOINT ["dotnet", "Api.dll"]
EXPOSE 80