From 6e02aa97f49643cdc1f8fe7b787fa084ec1e1f86 Mon Sep 17 00:00:00 2001 From: Lucas Depetris Date: Wed, 21 Feb 2024 15:54:40 -0300 Subject: [PATCH] Mejoro dockerfile --- .github/workflows/main.yml | 1 + src/WebAPI/Dockerfile => Dockerfile | 8 ++--- src/WebAPI/Program.cs | 51 ++++++++++------------------- src/WebAPI/WebAPI.csproj | 3 +- 4 files changed, 24 insertions(+), 39 deletions(-) rename src/WebAPI/Dockerfile => Dockerfile (83%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a49d0d0..d36d766 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,3 +16,4 @@ jobs: heroku_app_name: ${{secrets.HEROKU_APP_NAME}} heroku_email: ${{secrets.HEROKU_EMAIL}} usedocker: true + appdir: "." diff --git a/src/WebAPI/Dockerfile b/Dockerfile similarity index 83% rename from src/WebAPI/Dockerfile rename to Dockerfile index 154458b..be79cd9 100644 --- a/src/WebAPI/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ EXPOSE 8080 EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build -ARG BUILD_CONFIGURATION=Release +ARG BUILD_CONFIGURATION=Development WORKDIR /src COPY ["src/WebAPI/WebAPI.csproj", "src/WebAPI/"] COPY ["src/Application/Application.csproj", "src/Application/"] @@ -15,11 +15,11 @@ COPY ["src/Domain/Domain.csproj", "src/Domain/"] COPY ["src/Infraestructure/Infraestructure.csproj", "src/Infraestructure/"] RUN dotnet restore "./src/WebAPI/WebAPI.csproj" COPY . . -WORKDIR "/src/WebAPI" -RUN dotnet build "./WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/build +WORKDIR ./src/WebAPI +RUN dotnet build ./WebAPI.csproj -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish -ARG BUILD_CONFIGURATION=Release +ARG BUILD_CONFIGURATION=Development RUN dotnet publish "./WebAPI.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final diff --git a/src/WebAPI/Program.cs b/src/WebAPI/Program.cs index 355135f..c34dc7d 100644 --- a/src/WebAPI/Program.cs +++ b/src/WebAPI/Program.cs @@ -15,30 +15,6 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); -/*if (builder.Environment.EnvironmentName == "Production") -{ - var connectionUrl = Environment.GetEnvironmentVariable("DATABASE_URL"); - - connectionUrl = connectionUrl.Replace("mssqlserver://", string.Empty); - var userPassSide = connectionUrl.Split("@")[0]; - var hostSide = connectionUrl.Split("@")[1]; - - var user = userPassSide.Split(":")[0]; - var password = userPassSide.Split(":")[1]; - var host = hostSide.Split("/")[0]; - var database = hostSide.Split("/")[1].Split("?")[0]; - - string defaultConnectionString = $"Host={host};Database={database};Username={user};Password={password};SSL Mode=Require;Trust Server Certificate=true"; - - // Layers DI - builder.Services - .AddApplication() - .AddInfraestructure(defaultConnectionString); -} -else -{ -}*/ - // Layers DI builder.Services .AddApplication() @@ -49,17 +25,17 @@ // Configure the HTTP request pipeline. app.UseStaticFiles(); -if (app.Environment.IsDevelopment()) +//if (app.Environment.IsDevelopment()) +//{ +app.UseSwagger(); +//app.UseSwaggerThemes(Theme.OneDark); +app.UseSwaggerUI(options => { - app.UseSwagger(); - //app.UseSwaggerThemes(Theme.OneDark); - app.UseSwaggerUI(options => - { - options.DocExpansion(DocExpansion.None); - options.InjectStylesheet("/Swagger/SwaggerDark.css"); - options.EnableTryItOutByDefault(); - }); -} + options.DocExpansion(DocExpansion.None); + options.InjectStylesheet("/Swagger/SwaggerDark.css"); + options.EnableTryItOutByDefault(); +}); +//} app.UseHttpsRedirection(); @@ -67,4 +43,11 @@ app.MapControllers(); +if (app.Environment.IsProduction()) +{ + var port = Environment.GetEnvironmentVariable("PORT"); + app.Urls.Add($"http://*:{port}"); +} +/*var port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; +var host = Environment.GetEnvironmentVariable("applicationUrl") ?? "localhost";*/ app.Run(); diff --git a/src/WebAPI/WebAPI.csproj b/src/WebAPI/WebAPI.csproj index f8d8d90..7452678 100644 --- a/src/WebAPI/WebAPI.csproj +++ b/src/WebAPI/WebAPI.csproj @@ -6,7 +6,8 @@ enable 558b52cc-0347-4758-9da5-b8f4d979b767 Linux - ..\.. + ..\..\Dockerfile + ..\..