Added build instructions using the new helpers. Removed old python script. Added test compose file

This commit is contained in:
2025-05-13 22:08:19 +02:00
parent 7a73cfc493
commit 7794ed65d2
4 changed files with 94 additions and 87 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
**/.idea/**
**/data/**

View File

@@ -1,5 +1,5 @@
# Prepare runtime docker image
FROM cgr.dev/chainguard/dotnet-runtime:latest AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-noble-chiseled AS base
WORKDIR /app
# Prepare build image
@@ -9,11 +9,12 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# should be put here for caching reasons
# Install nodejs and npm so we can build tailwind
RUN apt-get update && apt-get install nodejs npm git python3 -y && apt-get clean
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
@@ -23,19 +24,29 @@ ARG MOONLIGHT_BRANCH=v2_ChangeArchitecture
RUN mkdir -p /src && \
mkdir -p /src/Moonlight && \
mkdir -p /src/Plugins && \
mkdir /src/nuget && \
mkdir -p /src/build_scripts
mkdir -p /src/pluginNuget && \
mkdir -p /src/moonlightNuget
WORKDIR /src
# === Building ===
# Copying build scripts
COPY build_scripts/* /src/build_scripts
# Clone the main moonlight repo
RUN git clone --branch $MOONLIGHT_BRANCH $MOONLIGHT_REPO /src/Moonlight
# Install npm packages
WORKDIR /src/Moonlight/Moonlight.Client/Styles
RUN npm i
WORKDIR /src
# Build moonlight as nuget packages
RUN dotnet run --project Moonlight/Resources/Scripts/Scripts.csproj -- 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
@@ -45,6 +56,35 @@ RUN grep -v '^#' plugins.txt | \
git clone "$repo" /src/Plugins/$(basename "$repo" .git); \
done
# Build plugins as source only nuget packages
WORKDIR /src/Plugins
RUN python3 /src/build_scripts/prepare_nuget.py
# Build plugin nuget packages
RUN dotnet run --project Moonlight/Resources/Scripts/Scripts.csproj -- 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 run --project Moonlight/Resources/Scripts/Scripts.csproj -- prebuild /src/Moonlight /src/pluginNuget
# Build tailwind
WORKDIR /src/Moonlight/Moonlight.Client/Styles
RUN npm run tailwind
# Build moonlight
WORKDIR "/src/Moonlight/Moonlight.ApiServer"
RUN dotnet build "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/build/
# Publish application
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "Moonlight.ApiServer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# Create final minimal image
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Moonlight.ApiServer.dll"]

View File

@@ -1,75 +0,0 @@
#!/bin/python3
import os
import xml.etree.ElementTree as ET
import subprocess
from pathlib import Path
OUTPUT_DIR = Path("/src/nuget")
MOONLIGHT_DIR = Path("/src/Moonlight")
TARGET_PROJECTS = {
"api server": MOONLIGHT_DIR / "Moonlight.ApiServer.csproj",
"frontend": MOONLIGHT_DIR / "Moonlight.Client.csproj",
"shared": MOONLIGHT_DIR / "Moonlight.Shared.csproj",
}
def get_version_and_tags(csproj_path):
tree = ET.parse(csproj_path)
root = tree.getroot()
ns = {"msbuild": "http://schemas.microsoft.com/developer/msbuild/2003"}
version = None
tags = ""
for elem in root.iter():
tag_name = elem.tag.split("}")[-1]
if tag_name == "Version":
version = elem.text.strip()
if tag_name in ("PackageTags", "Tags"):
tags = elem.text.strip().lower()
return version, tags
def pack_project(csproj_path):
subprocess.run([
"dotnet", "pack", str(csproj_path), "-o", str(OUTPUT_DIR)
], check=True, stdout=subprocess.DEVNULL)
def add_package_reference(project_path, package_id, version):
tree = ET.parse(project_path)
root = tree.getroot()
# Ensure there's at least one ItemGroup
item_groups = [e for e in root.findall(".//") if e.tag.endswith("ItemGroup")]
if not item_groups:
item_group = ET.SubElement(root, "ItemGroup")
else:
item_group = item_groups[0]
pkg_ref = ET.SubElement(item_group, "PackageReference", Include=package_id, Version=version)
comment = ET.Comment(" Added by script ")
item_group.insert(list(item_group).index(pkg_ref), comment)
ET.indent(tree, space=" ", level=0)
tree.write(project_path, encoding="utf-8", xml_declaration=True)
def main():
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".csproj") and not str(Path(root, file)).startswith(str(MOONLIGHT_DIR)):
csproj_path = Path(root) / file
version, tags = get_version_and_tags(csproj_path)
if version:
print(f"Packing {csproj_path}")
pack_project(csproj_path)
package_id = csproj_path.stem
for keyword, target_proj in TARGET_PROJECTS.items():
if keyword in tags:
print(f"→ Adding {package_id} to {target_proj}")
add_package_reference(target_proj, package_id, version)
if __name__ == "__main__":
main()

41
compose.yml Normal file
View File

@@ -0,0 +1,41 @@
services:
api-server:
user: 0:0
restart: always
image: moonlightpanel/panel:custom
build:
context: .
dockerfile: ./Moonlight.ApiServer/Dockerfile
ports:
- "9069:8080"
depends_on:
db:
condition: service_healthy
environment:
- MOONLIGHT_DATABASE_HOST=db
- MOONLIGHT_DATABASE_PORT=5432
- MOONLIGHT_DATABASE_USERNAME=moonlight
- MOONLIGHT_DATABASE_PASSWORD=s3cret
- MOONLIGHT_DATABASE_DATABASE=moonlight
- MOONLIGHT_PUBLICURL=http://localhost:9069
- MOONLIGHT_AUTHENTICATION_OAUTH2_ACCESSENDPOINT=http://localhost:8080 # Use this when moonlight is using local oauth2 and a different port as the public url
volumes:
- ./data/moonlight:/app/storage
links:
- db
pull_policy: never
db:
image: postgres:latest
restart: always
environment:
- POSTGRES_USER=moonlight
- POSTGRES_DB=moonlight
- POSTGRES_PASSWORD=s3cret
volumes:
- ./data/database:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5