Revamped Dockerfile and compose for updated architectur
This commit is contained in:
51
.env.example
51
.env.example
@@ -1,41 +1,10 @@
|
|||||||
#
|
DATABASE_HOST=database
|
||||||
# Application Settings
|
DATABASE_PORT=5432
|
||||||
#
|
DATABASE_USERNAME=moonlight
|
||||||
|
DATABASE_PASSWORD=super-secret-password
|
||||||
# Set this to the url moonlight is accessible through the internet
|
DATABASE_DATABASE=moonlight
|
||||||
MOONLIGHT_URL=http://localhost:9069
|
OIDC_AUTHORITY=http://localhost:8092
|
||||||
|
OIDC_AUTHORITY=http://localhost:8092
|
||||||
# This defines the port moonlight should run on
|
OIDC_CLIENT_ID=client_id
|
||||||
MOONLIGHT_PORT=9069
|
OIDC_CLIENT_SECRET=client_secret
|
||||||
|
OIDC_REQUIRE_HTTPS_METADATA=false
|
||||||
# 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
|
|
||||||
96
Dockerfile
96
Dockerfile
@@ -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
|
# Install required packages
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-moonlight
|
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 BUILD_CONFIGURATION=Release
|
||||||
ARG MOONLIGHT_REPO=https://github.com/Moonlight-Panel/Moonlight
|
ARG GIT_REPOSITORY=https://git.battlestati.one/Moonlight-Panel/Moonlight
|
||||||
ARG MOONLIGHT_BRANCH=v2_ChangeArchitecture
|
ARG GIT_BRANCH=v2.1
|
||||||
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
|
|
||||||
|
|
||||||
# Setup nuget package source
|
# 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
|
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
|
# TODO: Implement plugin loading here
|
||||||
RUN git clone --branch $MOONLIGHT_BRANCH $MOONLIGHT_REPO /src/.
|
|
||||||
|
|
||||||
# Install npm packages
|
# Install npm packages
|
||||||
WORKDIR /src/Moonlight.Client.Runtime/Styles
|
WORKDIR /src/Hosts/Moonlight.Frontend.Host/Styles
|
||||||
RUN npm i
|
RUN npm install
|
||||||
|
|
||||||
|
# Install nuget packages
|
||||||
WORKDIR /src
|
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
|
# Build styles
|
||||||
COPY Plugins.ApiServer.props /src/Moonlight.ApiServer.Runtime/Plugins.props
|
# - We need to build the frontend before the tailwind build, so the class lists get generated
|
||||||
COPY Plugins.Frontend.props /src/Moonlight.Client.Runtime/Plugins.props
|
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
|
WORKDIR "/src/Hosts/Moonlight.Frontend.Host/Styles"
|
||||||
RUN dotnet build -c $BUILD_CONFIGURATION
|
RUN npm run build
|
||||||
|
|
||||||
# Build tailwind
|
# Build projects
|
||||||
WORKDIR /src/Moonlight.Client.Runtime/Styles
|
WORKDIR "/src/Hosts/Moonlight.Api.Host"
|
||||||
RUN npm run tailwind-build
|
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/Hosts/Moonlight.Frontend.Host"
|
||||||
WORKDIR "/src/Moonlight.ApiServer.Runtime"
|
RUN dotnet build --no-restore "./Moonlight.Frontend.Host.csproj" -c $BUILD_CONFIGURATION -o /output/build-frontend
|
||||||
RUN dotnet build "Moonlight.ApiServer.Runtime.csproj" -c $BUILD_CONFIGURATION -o /app/build/
|
|
||||||
|
|
||||||
# Publish application
|
# Publish projects
|
||||||
FROM build-moonlight AS publish
|
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
|
#
|
||||||
|
# Construct final docker image
|
||||||
# Create final minimal image
|
#
|
||||||
FROM base AS final
|
FROM cgr.dev/chainguard/aspnet-runtime:latest AS final
|
||||||
|
|
||||||
WORKDIR /app
|
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"]
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<Project>
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- Put your plugin references here -->
|
|
||||||
<!-- E.g. <PackageReference Include="MoonlightServers.ApiServer" Version="2.1.0" /> -->
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<Project>
|
|
||||||
<ItemGroup>
|
|
||||||
<!-- Put your plugin references here -->
|
|
||||||
<!-- E.g. <PackageReference Include="MoonlightServers.Frontend" Version="2.1.0" /> -->
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
|
||||||
99
compose.yml
99
compose.yml
@@ -1,49 +1,70 @@
|
|||||||
services:
|
services:
|
||||||
api-server:
|
app:
|
||||||
user: 0:0
|
# Meta
|
||||||
restart: always
|
image: moonlight-deploy
|
||||||
image: ${MOONLIGHT_IMAGE}
|
|
||||||
|
# Build
|
||||||
|
pull_policy: build
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./Dockerfile
|
dockerfile: Dockerfile
|
||||||
args:
|
args:
|
||||||
- MOONLIGHT_REPO=${MOONLIGHT_REPOSITORY}
|
HTTP_PROXY: ${HTTP_PROXY}
|
||||||
- MOONLIGHT_BRANCH=${MOONLIGHT_BRANCH}
|
HTTPS_PROXY: ${HTTPS_PROXY}
|
||||||
- MOONLIGHT_GITHUB_TOKEN=${MOONLIGHT_GITHUB_TOKEN}
|
|
||||||
- MOONLIGHT_NUGET_SOURCE=${MOONLIGHT_NUGET_SOURCE}
|
|
||||||
ports:
|
|
||||||
- "${MOONLIGHT_PORT}:8080"
|
|
||||||
depends_on:
|
|
||||||
db:
|
|
||||||
condition: service_healthy
|
|
||||||
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}
|
|
||||||
|
|
||||||
db:
|
# Requirements
|
||||||
image: postgres:latest
|
depends_on:
|
||||||
restart: always
|
database:
|
||||||
|
condition: service_healthy
|
||||||
|
|
||||||
|
# Networks
|
||||||
|
networks:
|
||||||
|
- moonlight
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
|
||||||
|
# Env Settings
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_USER=${MOONLIGHT_DATABASE_USER}
|
# Database settings
|
||||||
- POSTGRES_DB=${MOONLIGHT_DATABASE_NAME}
|
- "Moonlight__Database__Host=${DATABASE_HOST}"
|
||||||
- POSTGRES_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD}
|
- "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"
|
||||||
|
|
||||||
|
database:
|
||||||
|
image: postgres:18.1
|
||||||
|
|
||||||
|
networks:
|
||||||
|
- moonlight
|
||||||
|
|
||||||
|
environment:
|
||||||
|
- "POSTGRES_USER=${DATABASE_USERNAME}"
|
||||||
|
- "POSTGRES_PASSWORD=${DATABASE_PASSWORD}"
|
||||||
|
- "POSTGRES_DB=${DATABASE_DATABASE}"
|
||||||
|
- "PGDATA=/pgdata"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- ${MOONLIGHT_DATA}/database:/var/lib/postgresql/data
|
- ./data/database:/var/lib/postgresql/data
|
||||||
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready"]
|
test: [ "CMD", "pg_isready", "-q", "-d", $DATABASE_DATABASE, "-U", $DATABASE_USERNAME]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
||||||
|
networks:
|
||||||
|
moonlight:
|
||||||
7
nuget.config
Normal file
7
nuget.config
Normal 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>
|
||||||
48
update.sh
48
update.sh
@@ -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 :>"
|
|
||||||
Reference in New Issue
Block a user