From de7e7d244bda23d4b9fbdc8c6df4835d0aee3e87 Mon Sep 17 00:00:00 2001 From: Flaminel Date: Wed, 18 Jun 2025 23:22:13 +0300 Subject: [PATCH] fixed initial docker build --- code/Dockerfile | 25 +++++++++++++++---- .../Controllers/ApiDocumentationController.cs | 4 +-- code/backend/Cleanuparr.Api/Program.cs | 14 +++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/code/Dockerfile b/code/Dockerfile index db820f9c..9beb6392 100644 --- a/code/Dockerfile +++ b/code/Dockerfile @@ -1,11 +1,16 @@ # Build Angular frontend FROM --platform=$BUILDPLATFORM node:18-alpine AS frontend-build -ARG BASE_PATH="" WORKDIR /app + +# Copy package files first for better layer caching COPY frontend/package*.json ./ -RUN npm ci --only=production +RUN npm ci && npm install -g @angular/cli + +# Copy source code COPY frontend/ . -RUN npm run build -- --base-href="${BASE_PATH}/" --deploy-url="${BASE_PATH}/" + +# Build with appropriate base-href and deploy-url +RUN npm run build # Build .NET backend FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim AS build @@ -15,8 +20,18 @@ ARG PACKAGES_USERNAME ARG PACKAGES_PAT WORKDIR /app EXPOSE 11011 -COPY . ./ + +# Copy solution and project files first for better layer caching +# COPY backend/*.sln ./backend/ +# COPY backend/*/*.csproj ./backend/*/ + +# Copy source code +COPY backend/ ./backend/ + +# Restore dependencies RUN dotnet nuget add source --username ${PACKAGES_USERNAME} --password ${PACKAGES_PAT} --store-password-in-clear-text --name Cleanuparr https://nuget.pkg.github.com/flmorg/index.json + +# Build and publish RUN dotnet publish ./backend/Cleanuparr.Api/Cleanuparr.Api.csproj \ -a $TARGETARCH \ -c Release \ @@ -36,6 +51,6 @@ WORKDIR /app COPY --from=build /app/publish . # Copy frontend to wwwroot -COPY --from=frontend-build /app/dist ./wwwroot +COPY --from=frontend-build /app/dist/ui/browser ./wwwroot ENTRYPOINT ["./cleanuparr"] \ No newline at end of file diff --git a/code/backend/Cleanuparr.Api/Controllers/ApiDocumentationController.cs b/code/backend/Cleanuparr.Api/Controllers/ApiDocumentationController.cs index 65d5f64c..2ddfea3f 100644 --- a/code/backend/Cleanuparr.Api/Controllers/ApiDocumentationController.cs +++ b/code/backend/Cleanuparr.Api/Controllers/ApiDocumentationController.cs @@ -3,12 +3,12 @@ using Microsoft.AspNetCore.Mvc; namespace Cleanuparr.Api.Controllers; [ApiController] -[Route("")] +[Route("api")] public class ApiDocumentationController : ControllerBase { [HttpGet] public IActionResult RedirectToSwagger() { - return Redirect("/swagger"); + return Redirect("/api/swagger"); } } diff --git a/code/backend/Cleanuparr.Api/Program.cs b/code/backend/Cleanuparr.Api/Program.cs index e98c2162..27d9bf67 100644 --- a/code/backend/Cleanuparr.Api/Program.cs +++ b/code/backend/Cleanuparr.Api/Program.cs @@ -7,9 +7,23 @@ using Serilog; var builder = WebApplication.CreateBuilder(args); +int? port = builder.Configuration.GetValue("PORT"); + +if (port is null or 0) +{ + port = 11011; +} + +builder.WebHost.UseUrls($"http://*:{port}"); + builder.Configuration .AddJsonFile(Path.Combine(ConfigurationPathProvider.GetConfigPath(), "cleanuparr.json"), optional: true, reloadOnChange: true); +builder.Services.AddResponseCompression(options => +{ + options.EnableForHttps = true; +}); + // Configure JSON options to serialize enums as strings builder.Services.ConfigureHttpJsonOptions(options => {