From f1a7be15f204dc39deaf77258b54bb4c8e7d1001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C4=83ng=20Nguy=E1=BB=85n?= Date: Mon, 22 Dec 2025 18:38:35 +0700 Subject: [PATCH] update --- .dockerignore | 66 +++++++++++++++++++ Dockerfile | 60 +++++++++++++++++ RobotApp.Client/Pages/Dashboard.razor | 1 - RobotApp.Client/Pages/Logs.razor | 1 - RobotApp.Client/Pages/MapsManager.razor | 2 - RobotApp.Client/Pages/Order/OrderMess.razor | 1 - .../Pages/RobotConfigManager.razor | 1 - RobotApp.Client/Pages/RobotMonitor.razor | 3 +- RobotApp.Client/wwwroot/js/robotMonitor.js | 1 + RobotApp/Components/Pages/Home.razor | 2 - RobotApp/Controllers/FileController.cs | 3 +- RobotApp/Controllers/ImagesController.cs | 1 + RobotApp/Controllers/LogsManagerController.cs | 3 +- RobotApp/Controllers/OrderController.cs | 5 +- .../Controllers/RobotConfigsController.cs | 3 +- RobotApp/Data/ApplicationDbExtensions.cs | 2 +- RobotApp/Hubs/RobotMonitorHub.cs | 1 + RobotApp/Properties/launchSettings.json | 22 +++---- docker-compose.yaml | 35 ++++++++++ 19 files changed, 188 insertions(+), 25 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..24ffde6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,66 @@ +# Build artifacts +**/bin/ +**/obj/ +**/out/ + +# Visual Studio files +**/.vs/ +**/.vscode/ +**/*.user +**/*.suo +**/*.userosscache +**/*.sln.docstates + +# User-specific files +**/.user +**/.suo +**/.userosscache + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# NuGet packages +**/packages/ +**/*.nupkg +**/*.snupkg + +# Test results +**/[Tt]est[Rr]esult*/ +**/[Bb]uild[Ll]og.* + +# Docker files +Dockerfile* +docker-compose* +.dockerignore + +# Git +.git/ +.gitignore +.gitattributes + +# IDE +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db + +# Data and logs (will be mounted as volumes) +data/ +logs/ + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..129cedd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +# Stage 1: Build +# Note: Project files specify net10.0, but using .NET 9.0 based on package versions (9.0.9) +# Adjust version if needed: 8.0 (LTS), 9.0 (current), or future 10.0 +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +WORKDIR /src + +# Copy solution file +COPY RobotApp.sln . + +# Copy project files +COPY RobotApp/RobotApp.csproj RobotApp/ +COPY RobotApp.Client/RobotApp.Client.csproj RobotApp.Client/ +COPY RobotApp.Common.Shares/RobotApp.Common.Shares.csproj RobotApp.Common.Shares/ +COPY RobotApp.VDA5050/RobotApp.VDA5050.csproj RobotApp.VDA5050/ + +# Restore dependencies +RUN dotnet restore RobotApp.sln + +# Copy all source files +COPY RobotApp/ RobotApp/ +COPY RobotApp.Client/ RobotApp.Client/ +COPY RobotApp.Common.Shares/ RobotApp.Common.Shares/ +COPY RobotApp.VDA5050/ RobotApp.VDA5050/ + +RUN rm -rf ./RobotApp/RobotApp/bin +RUN rm -rf ./RobotApp/RobotApp/obj +RUN rm -rf ./RobotApp.Client/RobotApp.Client/bin +RUN rm -rf ./RobotApp.Client/RobotApp.Client/obj +RUN rm -rf ./RobotApp.Common.Shares/RobotApp.Common.Shares/bin +RUN rm -rf ./RobotApp.Common.Shares/RobotApp.Common.Shares/obj +RUN rm -rf ./RobotApp.VDA5050/RobotApp.VDA5050/bin +RUN rm -rf ./RobotApp.VDA5050/RobotApp.VDA5050/obj + +# Build the solution +WORKDIR /src/RobotApp +RUN dotnet build -c Release -o /app/build + +# Stage 2: Publish +FROM build AS publish +WORKDIR /src/RobotApp +RUN dotnet publish -c Release -o /app/publish /p:UseAppHost=false + +# Copy published files +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish ./ + +# Create directory for database +RUN mkdir -p /app/data + +# Set environment variables +#ENV ASPNETCORE_URLS=http://+:8080 +ENV ASPNETCORE_ENVIRONMENT=Production + +# Run the application +ENTRYPOINT ["dotnet", "RobotApp.dll"] + diff --git a/RobotApp.Client/Pages/Dashboard.razor b/RobotApp.Client/Pages/Dashboard.razor index f906ac5..937e889 100644 --- a/RobotApp.Client/Pages/Dashboard.razor +++ b/RobotApp.Client/Pages/Dashboard.razor @@ -5,7 +5,6 @@ @using MudBlazor @implements IDisposable -@attribute [Authorize] @inject RobotStateClient RobotStateClient @rendermode InteractiveWebAssemblyNoPrerender diff --git a/RobotApp.Client/Pages/Logs.razor b/RobotApp.Client/Pages/Logs.razor index 1e18167..b4c5bef 100644 --- a/RobotApp.Client/Pages/Logs.razor +++ b/RobotApp.Client/Pages/Logs.razor @@ -1,6 +1,5 @@ @page "/logs" @rendermode InteractiveWebAssemblyNoPrerender -@attribute [Authorize] @using Microsoft.AspNetCore.Components.WebAssembly.Authentication @using RobotApp.Client.Models diff --git a/RobotApp.Client/Pages/MapsManager.razor b/RobotApp.Client/Pages/MapsManager.razor index f41651d..8bff149 100644 --- a/RobotApp.Client/Pages/MapsManager.razor +++ b/RobotApp.Client/Pages/MapsManager.razor @@ -2,8 +2,6 @@ @rendermode InteractiveWebAssemblyNoPrerender -@attribute [Authorize] - Map Manager
diff --git a/RobotApp.Client/Pages/Order/OrderMess.razor b/RobotApp.Client/Pages/Order/OrderMess.razor index 84f5eb5..1e8bcb3 100644 --- a/RobotApp.Client/Pages/Order/OrderMess.razor +++ b/RobotApp.Client/Pages/Order/OrderMess.razor @@ -1,6 +1,5 @@ @page "/robot-order" -@attribute [Authorize] @rendermode InteractiveWebAssemblyNoPrerender @using System.Text.Json diff --git a/RobotApp.Client/Pages/RobotConfigManager.razor b/RobotApp.Client/Pages/RobotConfigManager.razor index ca8fc8f..c311e91 100644 --- a/RobotApp.Client/Pages/RobotConfigManager.razor +++ b/RobotApp.Client/Pages/RobotConfigManager.razor @@ -1,6 +1,5 @@ @page "/robot-config" @rendermode InteractiveWebAssemblyNoPrerender -@attribute [Authorize] @inject HttpClient Http @inject ISnackbar Snackbar diff --git a/RobotApp.Client/Pages/RobotMonitor.razor b/RobotApp.Client/Pages/RobotMonitor.razor index 8fb33e3..5d767ab 100644 --- a/RobotApp.Client/Pages/RobotMonitor.razor +++ b/RobotApp.Client/Pages/RobotMonitor.razor @@ -1,6 +1,5 @@ @page "/robot-monitor" @rendermode InteractiveWebAssemblyNoPrerender -@attribute [Authorize] @inject RobotApp.Client.Services.RobotMonitorService MonitorService @implements IAsyncDisposable @@ -40,3 +39,5 @@ } + + diff --git a/RobotApp.Client/wwwroot/js/robotMonitor.js b/RobotApp.Client/wwwroot/js/robotMonitor.js index 1eaa47a..192537f 100644 --- a/RobotApp.Client/wwwroot/js/robotMonitor.js +++ b/RobotApp.Client/wwwroot/js/robotMonitor.js @@ -59,3 +59,4 @@ window.robotMonitor = { }; + diff --git a/RobotApp/Components/Pages/Home.razor b/RobotApp/Components/Pages/Home.razor index 5c7d1e4..557f15e 100644 --- a/RobotApp/Components/Pages/Home.razor +++ b/RobotApp/Components/Pages/Home.razor @@ -3,8 +3,6 @@ @rendermode InteractiveServer -@attribute [Authorize] - @inject NavigationManager Nav @code diff --git a/RobotApp/Controllers/FileController.cs b/RobotApp/Controllers/FileController.cs index 97ac685..d0ad818 100644 --- a/RobotApp/Controllers/FileController.cs +++ b/RobotApp/Controllers/FileController.cs @@ -6,7 +6,8 @@ namespace RobotApp.Controllers; [Route("api/[controller]")] [ApiController] -[Authorize] +//[Authorize] +[AllowAnonymous] public class FileController(Services.Logger Logger) : ControllerBase { private readonly string certificatesPath = "MqttCertificates"; diff --git a/RobotApp/Controllers/ImagesController.cs b/RobotApp/Controllers/ImagesController.cs index a46ae4a..fdb4a42 100644 --- a/RobotApp/Controllers/ImagesController.cs +++ b/RobotApp/Controllers/ImagesController.cs @@ -5,6 +5,7 @@ namespace RobotApp.Controllers; [Route("api/[controller]")] [ApiController] +//[Authorize] [AllowAnonymous] public class ImagesController(Services.Logger Logger) : ControllerBase { diff --git a/RobotApp/Controllers/LogsManagerController.cs b/RobotApp/Controllers/LogsManagerController.cs index ca9741c..78c4403 100644 --- a/RobotApp/Controllers/LogsManagerController.cs +++ b/RobotApp/Controllers/LogsManagerController.cs @@ -5,7 +5,8 @@ namespace RobotApp.Controllers; [Route("api/[controller]")] [ApiController] -[Authorize] +//[Authorize] +[AllowAnonymous] public class LogsManagerController(Services.Logger Logger) : ControllerBase { private readonly string LoggerDirectory = "logs"; diff --git a/RobotApp/Controllers/OrderController.cs b/RobotApp/Controllers/OrderController.cs index 4115cb2..e2353a4 100644 --- a/RobotApp/Controllers/OrderController.cs +++ b/RobotApp/Controllers/OrderController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using RobotApp.Services.Robot; using RobotApp.VDA5050.Order; using System.Text.Json; @@ -7,6 +8,8 @@ namespace RobotApp.Controllers; [ApiController] [Route("api/order")] +//[Authorize] +[AllowAnonymous] public class OrderController : ControllerBase { private readonly RobotOrderController robotOrderController; diff --git a/RobotApp/Controllers/RobotConfigsController.cs b/RobotApp/Controllers/RobotConfigsController.cs index 5fa4199..b151623 100644 --- a/RobotApp/Controllers/RobotConfigsController.cs +++ b/RobotApp/Controllers/RobotConfigsController.cs @@ -10,7 +10,8 @@ namespace RobotApp.Controllers; [Route("api/[controller]")] [ApiController] -[Authorize] +//[Authorize] +[AllowAnonymous] public class RobotConfigsController(Services.Logger Logger, ApplicationDbContext AppDb, RobotConfiguration RobotConfiguration) : ControllerBase { [HttpGet] diff --git a/RobotApp/Data/ApplicationDbExtensions.cs b/RobotApp/Data/ApplicationDbExtensions.cs index a47ddb0..c25d3d5 100644 --- a/RobotApp/Data/ApplicationDbExtensions.cs +++ b/RobotApp/Data/ApplicationDbExtensions.cs @@ -155,7 +155,7 @@ public static class ApplicationDbExtensions VDA5050EnableTls = false, VDA5050UserName = "robotics", VDA5050Password = "robotics", - VDA5050TopicPrefix = "uagv/v2" + VDA5050TopicPrefix = "uagv/v2", IsActive = true, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, diff --git a/RobotApp/Hubs/RobotMonitorHub.cs b/RobotApp/Hubs/RobotMonitorHub.cs index 0e5b10e..fa1421f 100644 --- a/RobotApp/Hubs/RobotMonitorHub.cs +++ b/RobotApp/Hubs/RobotMonitorHub.cs @@ -11,3 +11,4 @@ public class RobotMonitorHub : Hub } + diff --git a/RobotApp/Properties/launchSettings.json b/RobotApp/Properties/launchSettings.json index 3f43f90..64a2d75 100644 --- a/RobotApp/Properties/launchSettings.json +++ b/RobotApp/Properties/launchSettings.json @@ -11,17 +11,17 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } - }, - "https": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "workingDirectory": "$(TargetDir)", - //"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", - "applicationUrl": "https://0.0.0.0:7150;http://localhost:5229", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } } + //"https": { + // "commandName": "Project", + // "dotnetRunMessages": true, + // "launchBrowser": true, + // "workingDirectory": "$(TargetDir)", + // //"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", + // "applicationUrl": "https://0.0.0.0:7150;http://localhost:5229", + // "environmentVariables": { + // "ASPNETCORE_ENVIRONMENT": "Development" + // } + //} } } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..4a76ef3 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + robotapp: + build: + context: . + dockerfile: Dockerfile + container_name: robotapp + restart: unless-stopped + ports: + - "8080:8080" + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://+:8080 + - ConnectionStrings__DefaultConnection=Data Source=/app/data/robot.db + volumes: + # Persist database + - ./data:/app/data + # Persist maps + - ./maps:/app/maps + # Persist logs (if needed) + - ./logs:/app/logs + networks: + - robotapp-network + healthcheck: + test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:8080 || exit 1"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s + +networks: + robotapp-network: + driver: bridge +