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,41 +1,10 @@
#
# Application Settings
#
# Set this to the url moonlight is accessible through the internet
MOONLIGHT_URL=http://localhost:9069
# This defines the port moonlight should run on
MOONLIGHT_PORT=9069
# Here you can adjust where the moonlight instance will save
# the application and database data
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
#
# 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 'always'
MOONLIGHT_PULL_POLICY=build
# 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
DATABASE_HOST=database
DATABASE_PORT=5432
DATABASE_USERNAME=moonlight
DATABASE_PASSWORD=super-secret-password
DATABASE_DATABASE=moonlight
OIDC_AUTHORITY=http://localhost:8092
OIDC_AUTHORITY=http://localhost:8092
OIDC_CLIENT_ID=client_id
OIDC_CLIENT_SECRET=client_secret
OIDC_REQUIRE_HTTPS_METADATA=false

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"]

View File

@@ -1,6 +0,0 @@
<Project>
<ItemGroup>
<!-- Put your plugin references here -->
<!-- E.g. <PackageReference Include="MoonlightServers.ApiServer" Version="2.1.0" /> -->
</ItemGroup>
</Project>

View File

@@ -1,6 +0,0 @@
<Project>
<ItemGroup>
<!-- Put your plugin references here -->
<!-- E.g. <PackageReference Include="MoonlightServers.Frontend" Version="2.1.0" /> -->
</ItemGroup>
</Project>

View File

@@ -1,49 +1,70 @@
services:
api-server:
user: 0:0
restart: always
image: ${MOONLIGHT_IMAGE}
services:
app:
# Meta
image: moonlight-deploy
# Build
pull_policy: build
build:
context: .
dockerfile: ./Dockerfile
dockerfile: Dockerfile
args:
- MOONLIGHT_REPO=${MOONLIGHT_REPOSITORY}
- MOONLIGHT_BRANCH=${MOONLIGHT_BRANCH}
- MOONLIGHT_GITHUB_TOKEN=${MOONLIGHT_GITHUB_TOKEN}
- MOONLIGHT_NUGET_SOURCE=${MOONLIGHT_NUGET_SOURCE}
ports:
- "${MOONLIGHT_PORT}:8080"
HTTP_PROXY: ${HTTP_PROXY}
HTTPS_PROXY: ${HTTPS_PROXY}
# Requirements
depends_on:
db:
database:
condition: service_healthy
# Networks
networks:
- moonlight
ports:
- "8080:8080"
# Env Settings
environment:
- MOONLIGHT_DATABASE_HOST=db
- MOONLIGHT_DATABASE_PORT=5432
- MOONLIGHT_DATABASE_USERNAME=${MOONLIGHT_DATABASE_USER}
- MOONLIGHT_DATABASE_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD}
- MOONLIGHT_DATABASE_DATABASE=${MOONLIGHT_DATABASE_NAME}
- MOONLIGHT_PUBLICURL=${MOONLIGHT_URL}
- MOONLIGHT_AUTHENTICATION_OAUTH2_ACCESSENDPOINT=http://localhost:8080/oauth2/handle # Use this when moonlight is using local oauth2 and a different port as the public url
env_file:
- path: "additional.env"
required: false
volumes:
- ${MOONLIGHT_DATA}/moonlight:/app/storage
links:
- db
pull_policy: ${MOONLIGHT_PULL_POLICY}
# Database settings
- "Moonlight__Database__Host=${DATABASE_HOST}"
- "Moonlight__Database__Port=${DATABASE_PORT}"
- "Moonlight__Database__Username=${DATABASE_USERNAME}"
- "Moonlight__Database__Password=${DATABASE_PASSWORD}"
- "Moonlight__Database__Database=${DATABASE_DATABASE}"
# OIDC
- "Moonlight__OIDC__Authority=${OIDC_AUTHORITY}"
- "Moonlight__OIDC__ClientId=${OIDC_CLIENT_ID}"
- "Moonlight__OIDC__ClientSecret=${OIDC_CLIENT_SECRET}"
- "Moonlight__OIDC__RequireHttpsMetadata=${OIDC_REQUIRE_HTTPS_METADATA:-true}"
- "Moonlight__OIDC__Scopes__0=openid"
- "Moonlight__OIDC__Scopes__1=identify"
- "Moonlight__OIDC__Scopes__2=email"
# Logging
- "Logging__LogLevel__Default=Information"
- "Logging__LogLevel__Microsoft.AspNetCore=Warning"
db:
image: postgres:latest
restart: always
database:
image: postgres:18.1
networks:
- moonlight
environment:
- POSTGRES_USER=${MOONLIGHT_DATABASE_USER}
- POSTGRES_DB=${MOONLIGHT_DATABASE_NAME}
- POSTGRES_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD}
- "POSTGRES_USER=${DATABASE_USERNAME}"
- "POSTGRES_PASSWORD=${DATABASE_PASSWORD}"
- "POSTGRES_DB=${DATABASE_DATABASE}"
- "PGDATA=/pgdata"
volumes:
- ${MOONLIGHT_DATA}/database:/var/lib/postgresql/data
- ./data/database:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
test: [ "CMD", "pg_isready", "-q", "-d", $DATABASE_DATABASE, "-U", $DATABASE_USERNAME]
interval: 10s
timeout: 5s
retries: 5
networks:
moonlight:

7
nuget.config Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Build Server" value="https://git.battlestati.one/api/packages/Moonlight-Panel/nuget/index.json" />
</packageSources>
</configuration>

View File

@@ -1,48 +0,0 @@
#!/bin/bash
set -e
source .env
echo "[i] Updating your moonlight instance"
echo "[i] Checking for updates on deploy repo"
# Fetch remote updates
git fetch
# Get current branch name
branch=$(git rev-parse --abbrev-ref HEAD)
# Compare local and remote branch
local_commit=$(git rev-parse "$branch")
remote_commit=$(git rev-parse "origin/$branch")
if [ "$local_commit" != "$remote_commit" ]; then
echo "[i] The deploy repository has updates. Fetching changes"
git pull
echo "[i] Updated deploy tools. Please rerun the update.sh"
exit 0
else
echo "[i] No update of the deploy repository available"
fi
if [ "$MOONLIGHT_PULL_POLICY" == "build" ]; then
echo "[i] Rebuilding the docker image"
docker compose build
echo "[i] Rebuild done"
fi
if [ "$MOONLIGHT_PULL_POLICY" == "always" ]; then
echo "[i] Pulling the latest docker image"
docker compose pull
echo "[i] Pulling completed"
fi
echo "[i] Stopping containers"
docker compose down
echo "[i] Starting containers"
docker compose up -d
echo "[i] Update done :>"