Files
Deploy/Dockerfile

73 lines
2.3 KiB
Docker

#
# Prepare build image for building moonlight
#
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
# Install required packages
RUN apt-get update; apt-get install nodejs npm -y; apt-get clean
#
# Build & publish projects
#
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
ARG GIT_REPOSITORY=https://git.battlestati.one/Moonlight-Panel/Moonlight
ARG GIT_BRANCH=v2.1
# Setup nuget package source
COPY ["nuget.config", "/context/nuget.config"]
# Clone source code
WORKDIR /src
RUN git clone -b $GIT_BRANCH --single-branch $GIT_REPOSITORY .
# Save hash of commit
WORKDIR /src
RUN mkdir -p "/output" && git log -1 --pretty=format:"%H" > /output/version
# TODO: Implement plugin loading here
# Install npm packages
WORKDIR /src/Hosts/Moonlight.Frontend.Host/Styles
RUN npm install
# Install nuget packages
WORKDIR /src
RUN dotnet restore --configfile /context/nuget.config "Hosts/Moonlight.Api.Host/Moonlight.Api.Host.csproj"
RUN dotnet restore --configfile /context/nuget.config "Hosts/Moonlight.Frontend.Host/Moonlight.Frontend.Host.csproj"
# Build styles
# - We need to build the frontend before the tailwind build, so the class lists get generated
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
RUN dotnet build --no-restore "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /output/build-frontend
WORKDIR "/src/Hosts/Moonlight.Frontend.Host/Styles"
RUN npm run build
# Build projects
WORKDIR "/src/Hosts/Moonlight.Api.Host"
RUN dotnet build --no-restore "./Moonlight.Api.Host.csproj" -c $BUILD_CONFIGURATION -o /output/build-api
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
RUN dotnet build --no-restore "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /output/build-frontend
# Publish projects
WORKDIR "/src/Hosts/Moonlight.Api.Host"
RUN dotnet publish --no-restore "./Moonlight.Api.Host.csproj" -c $BUILD_CONFIGURATION -o /output/publish-api /p:UseAppHost=false
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
RUN dotnet publish --no-restore "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /output/publish-frontend /p:UseAppHost=false
#
# Construct final docker image
#
FROM cgr.dev/chainguard/aspnet-runtime:latest AS final
WORKDIR /app
COPY --from=publish /output/publish-api .
COPY --from=publish /output/publish-frontend/wwwroot ./wwwroot
COPY --from=publish /output/version .
ENTRYPOINT ["dotnet", "Moonlight.Api.Host.dll"]