Started implementing building of the docker image (especially the source only nuget packages)

This commit is contained in:
2025-05-06 22:56:32 +02:00
commit 7a73cfc493
4 changed files with 127 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
**/.idea/**

50
Dockerfile Normal file
View File

@@ -0,0 +1,50 @@
# Prepare runtime docker image
FROM cgr.dev/chainguard/dotnet-runtime:latest AS base
WORKDIR /app
# Prepare build image
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
# === Heavy download/install tasks ===
# 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
# === Configuration options ===
# Usefull for custom forks
ARG BUILD_CONFIGURATION=Release
ARG MOONLIGHT_REPO=https://github.com/Moonlight-Panel/Moonlight
ARG MOONLIGHT_BRANCH=v2_ChangeArchitecture
# === Small preparations ===
# Prepare directories
RUN mkdir -p /src && \
mkdir -p /src/Moonlight && \
mkdir -p /src/Plugins && \
mkdir /src/nuget && \
mkdir -p /src/build_scripts
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
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 plugins as source only nuget packages
WORKDIR /src/Plugins
RUN python3 /src/build_scripts/prepare_nuget.py

View File

@@ -0,0 +1,75 @@
#!/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()

1
plugins.txt Normal file
View File

@@ -0,0 +1 @@
https://github.com/Moonlight-Panel/Servers