Merge branch 'v2' into v2_UpgradeMoonCore

This commit is contained in:
Masu Baumgartner
2024-07-06 11:41:13 +02:00
committed by GitHub
11 changed files with 251 additions and 83 deletions

35
.github/workflows/development-build.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Development Build
on:
workflow_dispatch:
pull_request:
types:
- closed
branches: [ "v2" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login into docker hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PW }}
- name: Build and Push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./Moonlight/Dockerfile
push: true
tags: moonlightpanel/moonlight:dev
platforms: linux/amd64,linux/arm64
build-args: |
"BUILD_CHANNEL=${{ github.ref_name }}"
"BUILD_COMMIT_HASH=${{ github.sha }}"
"BUILD_NAME=devbuild ${{ steps.date.outputs.date }}"
"BUILD_VERSION=unknown"

35
.github/workflows/release-build.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Release Build
on:
workflow_dispatch:
inputs:
codeName:
description: 'Code Name'
required: true
versionName:
description: 'Version Name'
required: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login into docker hub
run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PW }}
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Moonlight/Dockerfile
push: true
tags: moonlightpanel/moonlight:latest
platforms: linux/amd64,linux/arm64
build-args: |
"BUILD_CHANNEL=${{ github.ref_name }}"
"BUILD_COMMIT_HASH=${{ github.sha }}"
"BUILD_NAME=${{ github.event.inputs.codeName }}"
"BUILD_VERSION=${{ github.event.inputs.versionName }}"

4
.gitignore vendored
View File

@@ -399,6 +399,6 @@ FodyWeavers.xsd
storage/ storage/
.idea/.idea.Moonlight/.idea/dataSources.xml .idea/.idea.Moonlight/.idea/dataSources.xml
Moonlight/wwwroot/css/theme.css Moonlight/Assets/Core/css/theme.css
Moonlight/wwwroot/css/theme.css.map Moonlight/Assets/Core/css/theme.css.map
.idea/.idea.Moonlight/.idea/discord.xml .idea/.idea.Moonlight/.idea/discord.xml

View File

@@ -27,6 +27,7 @@ using Moonlight.Core.Implementations.ApiDefinition;
using Moonlight.Core.Implementations.UserDashboard; using Moonlight.Core.Implementations.UserDashboard;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using AuthenticationStateProvider = Moonlight.Core.Helpers.AuthenticationStateProvider; using AuthenticationStateProvider = Moonlight.Core.Helpers.AuthenticationStateProvider;
using Microsoft.AspNetCore.Http.Features;
namespace Moonlight.Core; namespace Moonlight.Core;
@@ -97,6 +98,12 @@ public class CoreFeature : MoonlightFeature
options.Limits.MaxRequestBodySize = ByteSizeValue.FromMegaBytes(config.Http.UploadLimit).Bytes; options.Limits.MaxRequestBodySize = ByteSizeValue.FromMegaBytes(config.Http.UploadLimit).Bytes;
}); });
// Setup http upload limit in forms
context.Builder.Services.Configure<FormOptions>(x =>
{
x.MultipartBodyLengthLimit = ByteSizeValue.FromMegaBytes(config.Http.UploadLimit).Bytes;
});
// Assets // Assets
// - Javascript // - Javascript
@@ -108,6 +115,7 @@ public class CoreFeature : MoonlightFeature
context.AddAsset("Core", "js/alerter.js"); context.AddAsset("Core", "js/alerter.js");
// - Css // - Css
context.AddAsset("Core", "css/theme.css");
context.AddAsset("Core", "css/blazor.css"); context.AddAsset("Core", "css/blazor.css");
context.AddAsset("Core", "css/boxicons.css"); context.AddAsset("Core", "css/boxicons.css");
context.AddAsset("Core", "css/sweetalert2dark.css"); context.AddAsset("Core", "css/sweetalert2dark.css");

View File

@@ -7,6 +7,12 @@ namespace Moonlight.Core.Services;
[Singleton] [Singleton]
public class MoonlightService public class MoonlightService
{ {
public readonly string BuildChannel;
public readonly string BuildCommitHash;
public readonly string BuildName;
public readonly string BuildVersion;
public readonly bool IsDockerRun;
public WebApplication Application { get; set; } // Do NOT modify using a plugin public WebApplication Application { get; set; } // Do NOT modify using a plugin
private readonly DateTime StartTimestamp = DateTime.UtcNow; private readonly DateTime StartTimestamp = DateTime.UtcNow;
@@ -19,6 +25,37 @@ public class MoonlightService
Logger = logger; Logger = logger;
} }
public MoonlightService()
{
//TODO: Maybe extract to a method to make this a bit cleaner
if (File.Exists("version"))
{
var line = File.ReadAllText("version");
line = line.Trim();
var parts = line.Split(";");
if (parts.Length >= 5)
{
BuildChannel = parts[0];
BuildCommitHash = parts[1];
BuildName = parts[2];
BuildVersion = parts[3];
IsDockerRun = parts[4] == "docker";
return;
}
}
BuildChannel = "N/A";
BuildCommitHash = "N/A";
BuildName = "N/A";
BuildVersion = "N/A";
IsDockerRun = false;
//TODO: Add log call
}
public async Task Restart() public async Task Restart()
{ {
Logger.LogInformation("Restarting moonlight"); Logger.LogInformation("Restarting moonlight");

View File

@@ -30,9 +30,6 @@
<StatCard Value="@memoryUsageText" Description="Memory usage" Icon="bxs-microchip"/> <StatCard Value="@memoryUsageText" Description="Memory usage" Icon="bxs-microchip"/>
</div> </div>
<div class="col-md-3 col-12">
<StatCard Value="bf6641c (up-to-date)" Description="Version" Icon="bxs-purchase-tag"/>
</div>
<div class="col-md-3 col-12"> <div class="col-md-3 col-12">
@{ @{
var uptimeText = Formatter.FormatUptime(Uptime); var uptimeText = Formatter.FormatUptime(Uptime);
@@ -41,7 +38,30 @@
<StatCard Value="@uptimeText" Description="Uptime" Icon="bxs-time-five"/> <StatCard Value="@uptimeText" Description="Uptime" Icon="bxs-time-five"/>
</div> </div>
<div class="col-md-3 col-12"> <div class="col-md-3 col-12">
@if (MoonlightService.IsDockerRun)
{
<StatCard Value="Running in docker" Description="Operating system" Icon="bxl-docker"/>
}
else
{
<StatCard Value="@OsName" Description="Operating system" Icon="bx-fingerprint"/> <StatCard Value="@OsName" Description="Operating system" Icon="bx-fingerprint"/>
}
</div>
<div class="col-md-3 col-12">
@{
var commitText = $"{MoonlightService.BuildCommitHash.Substring(0, 7)}"; // TODO: Add update check (possible during startup, with error handling etc)
}
<StatCard Value="@commitText" Description="Commit" Icon="bxl-git"/>
</div>
<div class="col-md-3 col-12">
<StatCard Value="@MoonlightService.BuildChannel" Description="Channel" Icon="bx-git-branch"/>
</div>
<div class="col-md-3 col-12">
<StatCard Value="@MoonlightService.BuildName" Description="Name" Icon="bxs-bookmark"/>
</div>
<div class="col-md-3 col-12">
<StatCard Value="@MoonlightService.BuildVersion" Description="Version" Icon="bxs-purchase-tag"/>
</div> </div>
</LazyLoader> </LazyLoader>
</div> </div>
@@ -75,7 +95,9 @@
{ {
await lazyLoader.SetText("Loading system statistics"); await lazyLoader.SetText("Loading system statistics");
if(!MoonlightService.IsDockerRun)
OsName = await HostSystemHelper.GetOsName(); OsName = await HostSystemHelper.GetOsName();
CpuUsage = await HostSystemHelper.GetCpuUsage(); CpuUsage = await HostSystemHelper.GetCpuUsage();
MemoryUsage = await HostSystemHelper.GetMemoryUsage(); MemoryUsage = await HostSystemHelper.GetMemoryUsage();
Uptime = await MoonlightService.GetUptime(); Uptime = await MoonlightService.GetUptime();

View File

@@ -1,10 +1,12 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app WORKDIR /app
EXPOSE 80 EXPOSE 80
EXPOSE 443 EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
WORKDIR /src WORKDIR /src
COPY ["Moonlight/Moonlight.csproj", "Moonlight/"] COPY ["Moonlight/Moonlight.csproj", "Moonlight/"]
RUN dotnet restore "Moonlight/Moonlight.csproj" RUN dotnet restore "Moonlight/Moonlight.csproj"
@@ -14,14 +16,38 @@ RUN dotnet build "Moonlight.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish FROM build AS publish
ARG BUILD_CONFIGURATION=Release ARG BUILD_CONFIGURATION=Release
# Install sass and compile styles
RUN apt-get update
RUN apt-get install wget -y
RUN wget -O /tmp/sass.tar.gz https://github.com/sass/dart-sass/releases/download/1.77.5/dart-sass-1.77.5-linux-x64.tar.gz
RUN tar -xf /tmp/sass.tar.gz -C /tmp
RUN chmod +x /tmp/dart-sass/sass
RUN /tmp/dart-sass/sass /src/Moonlight/Styles/style.scss /app/publish/theme.css
RUN dotnet publish "Moonlight.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false RUN dotnet publish "Moonlight.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final FROM base AS final
# Define args
ARG BUILD_CHANNEL=unknown
ARG BUILD_COMMIT_HASH=unknown
ARG BUILD_NAME=unknown
ARG BUILD_VERSION=unknown
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
# Copy default assets # Copy default assets
RUN mkdir -p /app/Assets RUN mkdir -p /app/Assets
COPY ./Moonlight/Assets ./Assets COPY ./Moonlight/Assets /app/Assets
RUN mv /app/theme.css /app/Assets/Core/css/theme.css
# Ensure storage folder exists and is empty
RUN mkdir -p /app/storage
RUN rm -rf /app/storage/*
# Version the build
RUN echo "$BUILD_CHANNEL;$BUILD_COMMIT_HASH;$BUILD_NAME;$BUILD_VERSION;docker" > /app/version
ENTRYPOINT ["dotnet", "Moonlight.dll"] ENTRYPOINT ["dotnet", "Moonlight.dll"]

View File

@@ -274,7 +274,17 @@ public class ImageConversionHelper
// Node Regex: As the online detection uses regex, we want to escape any special chars from egg imports // Node Regex: As the online detection uses regex, we want to escape any special chars from egg imports
// as eggs dont use regex and as such may contain characters which regex uses as meta characters. // as eggs dont use regex and as such may contain characters which regex uses as meta characters.
// Without this escaping, many startup detection strings wont work // Without this escaping, many startup detection strings wont work
result.OnlineDetection = Regex.Escape(startup["done"]?.Value<string>() ?? "Online detection was missing");
// As pelican/pterodactyl changed their image format AGAIN, there needs to be the check below
var val = startup["done"]!;
string rawDone;
if (val is JArray array)
rawDone = array.First().Value<string>() ?? "Online detection was missing";
else
rawDone = val.Value<string>() ?? "Online detection was missing";
result.OnlineDetection = Regex.Escape(rawDone);
// Docker images // Docker images

View File

@@ -5,6 +5,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<RuntimeIdentifiers>linux-arm64;linux-x64;win-x64</RuntimeIdentifiers>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -50,33 +51,32 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Core\Database\Migrations\" /> <Folder Include="Core\Database\Migrations\"/>
<Folder Include="Core\Http\Requests\" /> <Folder Include="Core\Http\Requests\"/>
<Folder Include="Core\Http\Resources\" /> <Folder Include="Core\Http\Resources\"/>
<Folder Include="Core\UI\Components\Forms\" /> <Folder Include="Core\UI\Components\Forms\"/>
<Folder Include="Features\Dummy\Configuration\" /> <Folder Include="Features\Dummy\Configuration\"/>
<Folder Include="Features\Dummy\Entities\" /> <Folder Include="Features\Dummy\Entities\"/>
<Folder Include="Features\Dummy\Helpers\" /> <Folder Include="Features\Dummy\Helpers\"/>
<Folder Include="Features\Dummy\Http\Controllers\" /> <Folder Include="Features\Dummy\Http\Controllers\"/>
<Folder Include="Features\Dummy\Http\Middleware\" /> <Folder Include="Features\Dummy\Http\Middleware\"/>
<Folder Include="Features\Dummy\Http\Requests\" /> <Folder Include="Features\Dummy\Http\Requests\"/>
<Folder Include="Features\Dummy\Http\Resources\" /> <Folder Include="Features\Dummy\Http\Resources\"/>
<Folder Include="Features\Dummy\Models\Abstractions\" /> <Folder Include="Features\Dummy\Models\Abstractions\"/>
<Folder Include="Features\Dummy\Models\Enums\" /> <Folder Include="Features\Dummy\Models\Enums\"/>
<Folder Include="Features\Dummy\Models\Forms\" /> <Folder Include="Features\Dummy\Models\Forms\"/>
<Folder Include="Features\Dummy\Services\" /> <Folder Include="Features\Dummy\Services\"/>
<Folder Include="Features\Dummy\UI\Components\" /> <Folder Include="Features\Dummy\UI\Components\"/>
<Folder Include="Features\Dummy\UI\Layouts\" /> <Folder Include="Features\Dummy\UI\Layouts\"/>
<Folder Include="Features\Dummy\UI\Views\" /> <Folder Include="Features\Dummy\UI\Views\"/>
<Folder Include="Features\FileManager\Configuration\" /> <Folder Include="Features\FileManager\Configuration\"/>
<Folder Include="Features\FileManager\Entities\" /> <Folder Include="Features\FileManager\Entities\"/>
<Folder Include="Features\FileManager\Http\Middleware\" /> <Folder Include="Features\FileManager\Http\Middleware\"/>
<Folder Include="Features\FileManager\Http\Requests\" /> <Folder Include="Features\FileManager\Http\Requests\"/>
<Folder Include="Features\FileManager\Http\Resources\" /> <Folder Include="Features\FileManager\Http\Resources\"/>
<Folder Include="Features\Servers\Http\Resources\" /> <Folder Include="Features\Servers\Http\Resources\"/>
<Folder Include="storage\" /> <Folder Include="storage\"/>
<Folder Include="Styles\" /> <Folder Include="Styles\"/>
<Folder Include="wwwroot\css\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -28,11 +28,6 @@
} }
} }
<!-- Moonlight Themes -->
<!-- Moonlight Default Theme by MasuOwO -->
<link href="/css/theme.css" rel="stylesheet" type="text/css"/>
<!-- Google Fonts: Iter --> <!-- Google Fonts: Iter -->
<!-- TODO: Replace with local version --> <!-- TODO: Replace with local version -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inter:300,400,500,600,700">

View File

@@ -1,2 +1,2 @@
@echo off @echo off
sass style.scss ../wwwroot/css/theme.css sass style.scss ../Assets/Core/css/theme.css