FROM mcr.microsoft.com/dotnet/aspnet:9.0.2-alpine3.21 AS base
USER root
RUN apk update && apk add --no-cache curl icu tzdata musl-locales musl-locales-lang
USER $APP_UID
WORKDIR /app
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:9.0.102 AS build
ARG BUILD_CONFIGURATION=Release
RUN apt update && apt install npm -y
WORKDIR /src
COPY ["Otchinslator.csproj", "Otchinslator.csproj"]
RUN dotnet restore "Otchinslator.csproj"
COPY . .
WORKDIR "/src"
RUN npm ci
RUN npx tailwindcss -i ./wwwroot/css/site.css -o ./wwwroot/css/styles.css --minify
RUN dotnet build "Otchinslator.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Otchinslator.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
# HEALTHCHECK --interval=5s --timeout=10s --retries=3 CMD curl --fail http://localhost:8000/health || exit 1
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Otchinslator.dll"]
