From 507b9bf5a7be7ba715a2300fd34363a5e1dd9b2a Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Sun, 10 Aug 2025 16:33:33 +0200 Subject: [PATCH] Updated docker file for building using the new and simplified plugin system and the cleaner architecture. Added config files to specify which plugins to compile into --- .dockerignore | 5 +++ .env.example | 42 +++++++++++++++--------- Dockerfile | 71 ++++++++++++----------------------------- Plugins.ApiServer.props | 6 ++++ Plugins.Frontend.props | 6 ++++ compose.yml | 6 ++-- plugins.txt | 1 - 7 files changed, 69 insertions(+), 68 deletions(-) create mode 100644 .dockerignore create mode 100644 Plugins.ApiServer.props create mode 100644 Plugins.Frontend.props delete mode 100644 plugins.txt diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e1f904e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +**/.git/** +**/.idea/** +**/.env +**/update.sh +**/compose.yml \ No newline at end of file diff --git a/.env.example b/.env.example index ba41321..1241f0f 100644 --- a/.env.example +++ b/.env.example @@ -1,17 +1,6 @@ -# This defines the way to get the moonlight docker image -# By default moonlight will build the image locally. To pull -# it from the registry, set the value to 'pull' -MOONLIGHT_BUILD=build - -# This defines the image name to use when building/pulling -# the moonlight docker image -MOONLIGHT_IMAGE=moonlightpanel/panel:2.1 - -# Specify where the fetch the moonlight source code when building -# Uncomment this if you want to select a specific version of moonlight -# Or you want to deploy a custom fork -# MOONLIGHT_REPOSITORY=https://github.com/Moonlight-Panel/Moonlight -# MOONLIGHT_BRANCH=v2_ChangeArchitecture +# +# Application Settings +# # Set this to the url moonlight is accessible through the internet MOONLIGHT_URL=http://localhost:9069 @@ -26,4 +15,27 @@ MOONLIGHT_DATA=./data # With the following settings you can adjust the database configuration MOONLIGHT_DATABASE_USER=moonlight MOONLIGHT_DATABASE_PASSWORD=s3cret -MOONLIGHT_DATABASE_NAME=moonlight \ No newline at end of file +MOONLIGHT_DATABASE_NAME=moonlight + +# +# Build Settings +# + +# This defines the way to get the moonlight docker image +# By default moonlight will build the image locally. To pull +# it from the registry, set the value to 'pull' +MOONLIGHT_BUILD=pull + +# This defines the image name to use when building/pulling +# the moonlight docker image +MOONLIGHT_IMAGE=moonlightpanel/panel:2.1 + +# Moonlight uses githubs nuget registry for development packages +# Due to githubs restrictions you need an access token (classic) with the +# read.packages permission +MOONLIGHT_GITHUB_TOKEN=your-github-access-token-goes-here +MOONLIGHT_NUGET_SOURCE=https://nuget.pkg.github.com/Moonlight-Panel/index.json + +# Specify where the fetch the moonlight source code when building +MOONLIGHT_REPOSITORY=https://github.com/Moonlight-Panel/Moonlight +MOONLIGHT_BRANCH=v2_ChangeArchitecture \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3263f45..68e38f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,85 +11,56 @@ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-moonlight 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 PACK_BUILD_CONFIGURATION=Debug 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 && \ - mkdir -p /src/Moonlight && \ - mkdir -p /src/Plugins && \ - mkdir -p /src/pluginNuget && \ - mkdir -p /src/toolNuget && \ - mkdir -p /src/moonlightNuget +RUN mkdir -p /src + +# 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 WORKDIR /src # === Building === # Clone the main moonlight repo -RUN git clone --branch $MOONLIGHT_BRANCH $MOONLIGHT_REPO /src/Moonlight +RUN git clone --branch $MOONLIGHT_BRANCH $MOONLIGHT_REPO /src/. # Install npm packages -WORKDIR /src/Moonlight/Moonlight.Client/Styles +WORKDIR /src/Moonlight.Client.Runtime/Styles RUN npm i WORKDIR /src -# Install the scripts project as a dotnet tool and set the env for the dotnet cli to find -RUN dotnet pack --output /src/toolNuget Moonlight/Resources/Scripts/Scripts.csproj && \ - dotnet tool install --add-source /src/toolNuget --global dotnet-moonlight +# 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 -ENV PATH="$PATH:~/.dotnet/tools" - -FROM build-moonlight AS build-plugins - -# Build moonlight as nuget packages -RUN dotnet moonlight pack /src/Moonlight /src/moonlightNuget --build-configuration $PACK_BUILD_CONFIGURATION - -# Make the moonlight nuget accessible for the compilation -RUN dotnet nuget add source /src/moonlightNuget -n moonlightNuget - -# Copy plugin links -COPY plugins.txt /src/plugins.txt - -# Clone plugins -RUN grep -v '^#' plugins.txt | \ - while read -r repo; \ - do \ - git clone "$repo" /src/Plugins/$(basename "$repo" .git); \ - done - -# Build plugin nuget packages -RUN dotnet moonlight pack /src/Plugins /src/pluginNuget --build-configuration $PACK_BUILD_CONFIGURATION - -# Make the plugin nuget accessible for the compilation and remove the moonlight nuget source -RUN dotnet nuget remove source moonlightNuget -RUN dotnet nuget add source /src/pluginNuget -n pluginNuget - -# Prepare moonlight for compilation -RUN dotnet moonlight prebuild /src/Moonlight /src/pluginNuget - -FROM build-plugins AS build-final +# Build solution so every build task ran. Especially for tailwind class names etc +RUN dotnet build -c $BUILD_CONFIGURATION # Build tailwind -WORKDIR /src/Moonlight/Moonlight.Client/Styles +WORKDIR /src/Moonlight.Client.Runtime/Styles RUN npm run tailwind-build -# Build moonlight -WORKDIR "/src/Moonlight/Moonlight.ApiServer" -RUN dotnet build "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/build/ +# 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/ # Publish application -FROM build-final AS publish +FROM build-moonlight AS publish ARG BUILD_CONFIGURATION=Release -RUN dotnet publish "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /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 @@ -97,4 +68,4 @@ FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Moonlight.ApiServer.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "Moonlight.ApiServer.Runtime.dll"] \ No newline at end of file diff --git a/Plugins.ApiServer.props b/Plugins.ApiServer.props new file mode 100644 index 0000000..64d3507 --- /dev/null +++ b/Plugins.ApiServer.props @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Plugins.Frontend.props b/Plugins.Frontend.props new file mode 100644 index 0000000..384e727 --- /dev/null +++ b/Plugins.Frontend.props @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/compose.yml b/compose.yml index 40b948f..fa5368f 100644 --- a/compose.yml +++ b/compose.yml @@ -7,8 +7,10 @@ services: context: . dockerfile: ./Dockerfile args: - - MOONLIGHT_REPO=${MOONLIGHT_REPOSITORY:-https://github.com/Moonlight-Panel/Moonlight} - - MOONLIGHT_BRANCH=${MOONLIGHT_BRANCH:-v2_ChangeArchitecture} + - MOONLIGHT_REPO=${MOONLIGHT_REPOSITORY} + - MOONLIGHT_BRANCH=${MOONLIGHT_BRANCH} + - MOONLIGHT_GITHUB_TOKEN=${MOONLIGHT_GITHUB_TOKEN} + - MOONLIGHT_NUGET_SOURCE=${MOONLIGHT_NUGET_SOURCE} ports: - "${MOONLIGHT_PORT}:8080" depends_on: diff --git a/plugins.txt b/plugins.txt deleted file mode 100644 index 399d369..0000000 --- a/plugins.txt +++ /dev/null @@ -1 +0,0 @@ -https://github.com/Moonlight-Panel/Servers \ No newline at end of file