From e24143aed600fd5fd20877ced5ff9ccc85a9d413 Mon Sep 17 00:00:00 2001 From: Ricardo Carneiro <71648276+ricarneiro@users.noreply.github.com> Date: Tue, 3 Jun 2025 20:48:13 -0300 Subject: [PATCH] fix: ajustes de versionamento --- .gitea/workflows/deploy.yml | 35 +++++++++--- Dockerfile | 29 +++++++--- OnlyOneAccessTemplate/Program.cs | 57 ++++++++++++++++++- .../appsettings.Production.json | 2 +- OnlyOneAccessTemplate/appsettings.json | 2 +- 5 files changed, 106 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 7075907..2c1fd50 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -89,15 +89,34 @@ jobs: docker pull registry.redecarneir.us/onlyoneaccesstemplate:latest # Executa o novo container na porta 80 + # docker run -d \ + # --name onlyoneaccesstemplate \ + # --restart unless-stopped \ + # -p 80:8080 \ + # -p 443:8081 \ + # -e ASPNETCORE_ENVIRONMENT=Production \ + # -e ASPNETCORE_URLS="http://+:8080;https://+:8081" \ + # registry.redecarneir.us/onlyoneaccesstemplate:latest docker run -d \ - --name onlyoneaccesstemplate \ - --restart unless-stopped \ - -p 80:8080 \ - -p 443:8081 \ - -e ASPNETCORE_ENVIRONMENT=Production \ - -e ASPNETCORE_URLS="http://+:8080;https://+:8081" \ - registry.redecarneir.us/onlyoneaccesstemplate:latest - + --name onlyoneaccesstemplate \ + --restart unless-stopped \ + -p 80:8080 \ + -p 443:8081 \ + --memory=2g \ + --cpus=1.5 \ + --health-cmd="curl -f http://localhost:8080/health || exit 1" \ + --health-interval=30s \ + --health-timeout=10s \ + --health-retries=3 \ + --health-start-period=60s \ + -e ASPNETCORE_ENVIRONMENT=Production \ + -e ASPNETCORE_URLS="http://+:8080;https://+:8081" \ + -e DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true \ + -e DOTNET_USE_POLLING_FILE_WATCHER=true \ + -e DOTNET_EnableDiagnostics=0 \ + -e DOTNET_RUNNING_IN_CONTAINER=true \ + registry.redecarneir.us/onlyoneaccesstemplate:latest + # Limpa imagens não utilizadas docker image prune -f diff --git a/Dockerfile b/Dockerfile index 2a9a76e..a04140a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. - +# Dockerfile otimizado para ARM64 FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS base USER app WORKDIR /app @@ -12,13 +11,17 @@ WORKDIR /src # Copiar apenas arquivos de projeto primeiro (melhor cache) COPY ["OnlyOneAccessTemplate/OnlyOneAccessTemplate.csproj", "OnlyOneAccessTemplate/"] + +# Restore com configurações otimizadas para ARM64 RUN dotnet restore "./OnlyOneAccessTemplate/OnlyOneAccessTemplate.csproj" \ --runtime linux-arm64 \ --no-cache -# Copiar código fonte depois do restore +# Copiar código fonte COPY . . WORKDIR "/src/OnlyOneAccessTemplate" + +# Build otimizado RUN dotnet build "./OnlyOneAccessTemplate.csproj" \ -c $BUILD_CONFIGURATION \ -o /app/build \ @@ -27,20 +30,30 @@ RUN dotnet build "./OnlyOneAccessTemplate.csproj" \ FROM build AS publish ARG BUILD_CONFIGURATION=Release + +# Publish com AOT ReadyToRun para melhor performance RUN dotnet publish "./OnlyOneAccessTemplate.csproj" \ -c $BUILD_CONFIGURATION \ -o /app/publish \ --runtime linux-arm64 \ --no-restore \ --self-contained false \ - /p:UseAppHost=false + /p:UseAppHost=false \ + /p:PublishReadyToRun=true \ + /p:PublishSingleFile=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -# Healthcheck (adicional - opcional mas recomendado) -HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ - CMD curl -f http://localhost:8080/health || exit 1 +# Variáveis de ambiente otimizadas para produção +ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true +ENV DOTNET_USE_POLLING_FILE_WATCHER=true +ENV ASPNETCORE_ENVIRONMENT=Production +ENV DOTNET_EnableDiagnostics=0 -ENTRYPOINT ["dotnet", "OnlyOneAccessTemplate.dll"] \ No newline at end of file +# Healthcheck simples (removendo rota específica) +HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ + CMD curl -f http://localhost:8080/ || exit 1 + +ENTRYPOINT ["dotnet", "OnlyOneAccessTemplate.dll"] diff --git a/OnlyOneAccessTemplate/Program.cs b/OnlyOneAccessTemplate/Program.cs index cdf7a04..5c7234f 100644 --- a/OnlyOneAccessTemplate/Program.cs +++ b/OnlyOneAccessTemplate/Program.cs @@ -1,8 +1,56 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Server.Kestrel.Core; using MongoDB.Driver; using OnlyOneAccessTemplate.Services; var builder = WebApplication.CreateBuilder(args); +// Configurações otimizadas para produção ARM64 +if (builder.Environment.IsProduction()) +{ + // Configurar Kestrel para melhor performance + builder.WebHost.ConfigureKestrel(options => + { + options.Limits.MaxConcurrentConnections = 100; + options.Limits.MaxConcurrentUpgradedConnections = 100; + options.Limits.MaxRequestBodySize = 10 * 1024 * 1024; // 10MB + options.Limits.MinRequestBodyDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)); + options.Limits.MinResponseDataRate = new MinDataRate(bytesPerSecond: 100, gracePeriod: TimeSpan.FromSeconds(10)); + options.AddServerHeader = false; + }); + + // Configurações de logging otimizadas + builder.Logging.ClearProviders(); + builder.Logging.AddConsole(); + builder.Logging.SetMinimumLevel(LogLevel.Warning); +} + +// Add services to the container. +builder.Services.AddControllersWithViews(options => +{ + if (builder.Environment.IsProduction()) + { + // Configurações de cache para produção + options.CacheProfiles.Add("Default", new CacheProfile() + { + Duration = 300 // 5 minutos + }); + } +}); + +// Configurar Response Caching +builder.Services.AddResponseCaching(options => +{ + options.MaximumBodySize = 1024 * 1024; // 1MB + options.UseCaseSensitivePaths = false; +}); + +// Configurar Response Compression +builder.Services.AddResponseCompression(options => +{ + options.EnableForHttps = true; +}); + // Add services to the container builder.Services.AddControllersWithViews(); @@ -74,7 +122,14 @@ if (!app.Environment.IsDevelopment()) } app.UseHttpsRedirection(); -app.UseStaticFiles(); +app.UseStaticFiles(new StaticFileOptions +{ + OnPrepareResponse = ctx => + { + // Cache estático por 1 hora + ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=3600"); + } +}); // Session app.UseSession(); diff --git a/OnlyOneAccessTemplate/appsettings.Production.json b/OnlyOneAccessTemplate/appsettings.Production.json index 0771632..782be88 100644 --- a/OnlyOneAccessTemplate/appsettings.Production.json +++ b/OnlyOneAccessTemplate/appsettings.Production.json @@ -26,7 +26,7 @@ }, "TextConversionApi": { - "BaseUrl": "https://localhost:7071" + "BaseUrl": "http://convert-it.online" }, "SEO": { diff --git a/OnlyOneAccessTemplate/appsettings.json b/OnlyOneAccessTemplate/appsettings.json index 0771632..b7f9f3b 100644 --- a/OnlyOneAccessTemplate/appsettings.json +++ b/OnlyOneAccessTemplate/appsettings.json @@ -26,7 +26,7 @@ }, "TextConversionApi": { - "BaseUrl": "https://localhost:7071" + "BaseUrl": "https://localhost:7299" }, "SEO": {