Revamped Dockerfile and compose for updated architectur

This commit is contained in:
2026-01-21 14:52:19 +01:00
parent c758c236f1
commit 4401d67f2d
7 changed files with 124 additions and 185 deletions

View File

@@ -1,71 +1,73 @@
# Prepare runtime docker image
FROM cgr.dev/chainguard/aspnet-runtime:latest AS base
#
# Prepare build image for building moonlight
#
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
# Prepare build image
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-moonlight
# Install required packages
RUN apt-get update; apt-get install nodejs npm -y; apt-get clean
# === Heavy download/install tasks ===
# should be put here for caching reasons
#
# Build & publish projects
#
FROM build AS publish
# Install nodejs and npm so we can build tailwind
RUN apt-get update && apt-get install nodejs npm git -y && apt-get clean
# === Configuration options ===
# Usefull for custom forks
ARG BUILD_CONFIGURATION=Release
ARG MOONLIGHT_REPO=https://github.com/Moonlight-Panel/Moonlight
ARG MOONLIGHT_BRANCH=v2_ChangeArchitecture
ARG MOONLIGHT_NUGET_SOURCE=https://nuget.pkg.github.com/Moonlight-Panel/index.json
ARG MOONLIGHT_GITHUB_TOKEN=unset
# === Small preparations ===
# Prepare directories
RUN mkdir -p /src
ARG GIT_REPOSITORY=https://git.battlestati.one/Moonlight-Panel/Moonlight
ARG GIT_BRANCH=v2.1
# Setup nuget package source
RUN dotnet nuget add source --username Build --password $MOONLIGHT_GITHUB_TOKEN --store-password-in-clear-text --name nuget-moonlight $MOONLIGHT_NUGET_SOURCE
COPY ["nuget.config", "/context/nuget.config"]
# Clone source code
WORKDIR /src
RUN git clone -b $GIT_BRANCH --single-branch $GIT_REPOSITORY .
# === Building ===
# Save hash of commit
WORKDIR /src
RUN mkdir -p "/output" && git log -1 --pretty=format:"%H" > /output/version
# Clone the main moonlight repo
RUN git clone --branch $MOONLIGHT_BRANCH $MOONLIGHT_REPO /src/.
# TODO: Implement plugin loading here
# Install npm packages
WORKDIR /src/Moonlight.Client.Runtime/Styles
RUN npm i
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"
# Copying plugin references to src
COPY Plugins.ApiServer.props /src/Moonlight.ApiServer.Runtime/Plugins.props
COPY Plugins.Frontend.props /src/Moonlight.Client.Runtime/Plugins.props
# 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
# Build solution so every build task ran. Especially for tailwind class names etc
RUN dotnet build -c $BUILD_CONFIGURATION
WORKDIR "/src/Hosts/Moonlight.Frontend.Host/Styles"
RUN npm run build
# Build tailwind
WORKDIR /src/Moonlight.Client.Runtime/Styles
RUN npm run tailwind-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
# Build moonlight with the built tailwind assets
WORKDIR "/src/Moonlight.ApiServer.Runtime"
RUN dotnet build "Moonlight.ApiServer.Runtime.csproj" -c $BUILD_CONFIGURATION -o /app/build/
WORKDIR "/src/Hosts/Moonlight.Frontend.Host"
RUN dotnet build --no-restore "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /output/build-frontend
# Publish application
FROM build-moonlight AS publish
# 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
ARG BUILD_CONFIGURATION=Release
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
RUN dotnet publish "Moonlight.ApiServer.Runtime.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Create final minimal image
FROM base AS final
#
# Construct final docker image
#
FROM cgr.dev/chainguard/aspnet-runtime:latest AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Moonlight.ApiServer.Runtime.dll"]
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"]