diff --git a/.github/workflows/development-build.yml b/.github/workflows/development-build.yml new file mode 100644 index 00000000..badedd9d --- /dev/null +++ b/.github/workflows/development-build.yml @@ -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" diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 00000000..bc57204f --- /dev/null +++ b/.github/workflows/release-build.yml @@ -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 }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1cd56bb8..a0eda3a6 100644 --- a/.gitignore +++ b/.gitignore @@ -399,6 +399,6 @@ FodyWeavers.xsd storage/ .idea/.idea.Moonlight/.idea/dataSources.xml -Moonlight/wwwroot/css/theme.css -Moonlight/wwwroot/css/theme.css.map +Moonlight/Assets/Core/css/theme.css +Moonlight/Assets/Core/css/theme.css.map .idea/.idea.Moonlight/.idea/discord.xml diff --git a/Moonlight/Core/CoreFeature.cs b/Moonlight/Core/CoreFeature.cs index 3a614ef6..2be4032a 100644 --- a/Moonlight/Core/CoreFeature.cs +++ b/Moonlight/Core/CoreFeature.cs @@ -27,6 +27,7 @@ using Moonlight.Core.Implementations.ApiDefinition; using Moonlight.Core.Implementations.UserDashboard; using Swashbuckle.AspNetCore.SwaggerGen; using AuthenticationStateProvider = Moonlight.Core.Helpers.AuthenticationStateProvider; +using Microsoft.AspNetCore.Http.Features; namespace Moonlight.Core; @@ -97,6 +98,12 @@ public class CoreFeature : MoonlightFeature options.Limits.MaxRequestBodySize = ByteSizeValue.FromMegaBytes(config.Http.UploadLimit).Bytes; }); + // Setup http upload limit in forms + context.Builder.Services.Configure(x => + { + x.MultipartBodyLengthLimit = ByteSizeValue.FromMegaBytes(config.Http.UploadLimit).Bytes; + }); + // Assets // - Javascript @@ -108,6 +115,7 @@ public class CoreFeature : MoonlightFeature context.AddAsset("Core", "js/alerter.js"); // - Css + context.AddAsset("Core", "css/theme.css"); context.AddAsset("Core", "css/blazor.css"); context.AddAsset("Core", "css/boxicons.css"); context.AddAsset("Core", "css/sweetalert2dark.css"); diff --git a/Moonlight/Core/Services/MoonlightService.cs b/Moonlight/Core/Services/MoonlightService.cs index 35238f32..6aae4a4a 100644 --- a/Moonlight/Core/Services/MoonlightService.cs +++ b/Moonlight/Core/Services/MoonlightService.cs @@ -7,6 +7,12 @@ namespace Moonlight.Core.Services; [Singleton] 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 private readonly DateTime StartTimestamp = DateTime.UtcNow; @@ -19,6 +25,37 @@ public class MoonlightService 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() { Logger.LogInformation("Restarting moonlight"); diff --git a/Moonlight/Core/UI/Views/Admin/Sys/Index.razor b/Moonlight/Core/UI/Views/Admin/Sys/Index.razor index c821ccdd..12ba8a75 100644 --- a/Moonlight/Core/UI/Views/Admin/Sys/Index.razor +++ b/Moonlight/Core/UI/Views/Admin/Sys/Index.razor @@ -30,9 +30,6 @@ -
- -
@{ var uptimeText = Formatter.FormatUptime(Uptime); @@ -41,7 +38,30 @@
- + @if (MoonlightService.IsDockerRun) + { + + } + else + { + + } +
+
+ @{ + var commitText = $"{MoonlightService.BuildCommitHash.Substring(0, 7)}"; // TODO: Add update check (possible during startup, with error handling etc) + } + + +
+
+ +
+
+ +
+
+
@@ -75,7 +95,9 @@ { await lazyLoader.SetText("Loading system statistics"); - OsName = await HostSystemHelper.GetOsName(); + if(!MoonlightService.IsDockerRun) + OsName = await HostSystemHelper.GetOsName(); + CpuUsage = await HostSystemHelper.GetCpuUsage(); MemoryUsage = await HostSystemHelper.GetMemoryUsage(); Uptime = await MoonlightService.GetUptime(); diff --git a/Moonlight/Dockerfile b/Moonlight/Dockerfile index b5f1c6b1..4d659464 100644 --- a/Moonlight/Dockerfile +++ b/Moonlight/Dockerfile @@ -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 EXPOSE 80 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 + WORKDIR /src COPY ["Moonlight/Moonlight.csproj", "Moonlight/"] 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 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 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 COPY --from=publish /app/publish . # Copy default 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"] diff --git a/Moonlight/Features/Servers/Helpers/ImageConversionHelper.cs b/Moonlight/Features/Servers/Helpers/ImageConversionHelper.cs index 2bfb0df2..840f5e1b 100644 --- a/Moonlight/Features/Servers/Helpers/ImageConversionHelper.cs +++ b/Moonlight/Features/Servers/Helpers/ImageConversionHelper.cs @@ -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 // 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 - result.OnlineDetection = Regex.Escape(startup["done"]?.Value() ?? "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() ?? "Online detection was missing"; + else + rawDone = val.Value() ?? "Online detection was missing"; + + result.OnlineDetection = Regex.Escape(rawDone); // Docker images diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index 42f27151..b3ecef82 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -5,78 +5,78 @@ enable enable Linux + linux-arm64;linux-x64;win-x64 - - .dockerignore - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - - - true - PreserveNewest - + + .dockerignore + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + + + true + PreserveNewest + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Moonlight/Pages/_Host.cshtml b/Moonlight/Pages/_Host.cshtml index 58bc63a0..183c616b 100644 --- a/Moonlight/Pages/_Host.cshtml +++ b/Moonlight/Pages/_Host.cshtml @@ -28,11 +28,6 @@ } } - - - - - diff --git a/Moonlight/Styles/build.bat b/Moonlight/Styles/build.bat index 19e34edd..a2e79953 100644 --- a/Moonlight/Styles/build.bat +++ b/Moonlight/Styles/build.bat @@ -1,2 +1,2 @@ @echo off -sass style.scss ../wwwroot/css/theme.css \ No newline at end of file +sass style.scss ../Assets/Core/css/theme.css \ No newline at end of file