﻿FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["ImageGallery.csproj", "ImageGallery/"]
RUN dotnet restore "ImageGallery/ImageGallery.csproj"
COPY [".", "ImageGallery/"] 
WORKDIR "/src/ImageGallery"
RUN dotnet build "ImageGallery.csproj" -c $BUILD_CONFIGURATION -o /app/build

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

FROM mcr.microsoft.com/dotnet/aspnet:9.0-alpine AS final
WORKDIR /app
EXPOSE 80
COPY --from=publish /app/publish .
RUN sed -i 's#https\?://dl-cdn.alpinelinux.org/alpine#https://mirrors.ustc.edu.cn/alpine#g' /etc/apk/repositories
RUN apk update && apk add chromium nginx openrc bash
RUN mkdir -p /var/cache/nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY --chmod=755 start.sh /start.sh

ENTRYPOINT ["/start.sh"]