From e290173fc3a09b17171b2114d1bc855ae9dffdba Mon Sep 17 00:00:00 2001 From: Alejandro Sarmiento Date: Mon, 11 Mar 2024 18:31:16 +0100 Subject: [PATCH] seguimos con los tests con jenkins --- .../Controllers/TestController.cs | 25 +++++++++++++++ .../CleanArchitecture.API/Dockerfile | 5 +++ .../appsettings.Development.json | 3 +- .../appsettings.Production.json | 3 +- .../CleanArchitecture.API/appsettings.json | 3 +- CleanArchitecture/Dockerfile | 17 +++++----- .../Jenkinsfiles/Pro.Jenkinsfile | 32 +++++++++++++++++++ 7 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 CleanArchitecture/CleanArchitecture.API/Controllers/TestController.cs create mode 100644 CleanArchitecture/Jenkinsfiles/Pro.Jenkinsfile diff --git a/CleanArchitecture/CleanArchitecture.API/Controllers/TestController.cs b/CleanArchitecture/CleanArchitecture.API/Controllers/TestController.cs new file mode 100644 index 0000000..6b1ff2e --- /dev/null +++ b/CleanArchitecture/CleanArchitecture.API/Controllers/TestController.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace CleanArchitecture.API.Controllers +{ + [Route("api/v1/[controller]")] + [ApiController] + public class TestController : ControllerBase + { + private readonly IConfiguration _configuration; + public TestController(IConfiguration configuration) + { + + _configuration = configuration; + + } + + + [HttpGet] + public IActionResult Get() + { + return Ok(new { configuration = _configuration["Environment"] }); + } + } +} diff --git a/CleanArchitecture/CleanArchitecture.API/Dockerfile b/CleanArchitecture/CleanArchitecture.API/Dockerfile index 9c69599..6395483 100644 --- a/CleanArchitecture/CleanArchitecture.API/Dockerfile +++ b/CleanArchitecture/CleanArchitecture.API/Dockerfile @@ -5,6 +5,11 @@ USER app WORKDIR /app EXPOSE 80 +#seteo de variables de entorno +ARG ENVIRONMENT=dev +ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT} +ENV ASPNETCORE_URLS=http://+:80 + FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src diff --git a/CleanArchitecture/CleanArchitecture.API/appsettings.Development.json b/CleanArchitecture/CleanArchitecture.API/appsettings.Development.json index 950bd10..bd1c22f 100644 --- a/CleanArchitecture/CleanArchitecture.API/appsettings.Development.json +++ b/CleanArchitecture/CleanArchitecture.API/appsettings.Development.json @@ -20,5 +20,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Environment": "Development" } diff --git a/CleanArchitecture/CleanArchitecture.API/appsettings.Production.json b/CleanArchitecture/CleanArchitecture.API/appsettings.Production.json index 5d068b6..395c09d 100644 --- a/CleanArchitecture/CleanArchitecture.API/appsettings.Production.json +++ b/CleanArchitecture/CleanArchitecture.API/appsettings.Production.json @@ -20,5 +20,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Environment": "Production" } diff --git a/CleanArchitecture/CleanArchitecture.API/appsettings.json b/CleanArchitecture/CleanArchitecture.API/appsettings.json index 6e29d67..f682b5f 100644 --- a/CleanArchitecture/CleanArchitecture.API/appsettings.json +++ b/CleanArchitecture/CleanArchitecture.API/appsettings.json @@ -21,5 +21,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Environment": "Development" } diff --git a/CleanArchitecture/Dockerfile b/CleanArchitecture/Dockerfile index 2aff743..9f70daa 100644 --- a/CleanArchitecture/Dockerfile +++ b/CleanArchitecture/Dockerfile @@ -5,14 +5,14 @@ USER app WORKDIR /app EXPOSE 80 -ARG ENVIRONMENT Production -ENV ASPNETCORE_ENVIRONMENT Production -ENV ASPNETCORE_HTTP_PORTS 80 - +ARG ENVIRONMENT=dev +ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT} +ENV ASPNETCORE_URLS=http://+:80 FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build - ARG BUILD_CONFIGURATION=Release + + WORKDIR /src COPY ["CleanArchitecture.API/CleanArchitecture.API.csproj", "CleanArchitecture.API/"] COPY ["CleanArchitecture.Application/CleanArchitecture.Application.csproj", "CleanArchitecture.Application/"] @@ -22,12 +22,13 @@ COPY ["CleanArchitecture.Identity/CleanArchitecture.Identity.csproj", "CleanArch RUN dotnet restore "./CleanArchitecture.API/CleanArchitecture.API.csproj" COPY . . WORKDIR "/src/CleanArchitecture.API" -RUN dotnet build "./CleanArchitecture.API.csproj" -c Release -o /app/build +RUN dotnet build "./CleanArchitecture.API.csproj" -c $BUILD_CONFIGURATION -o /app/build FROM build AS publish -RUN dotnet publish "./CleanArchitecture.API.csproj" -c Release -o /app/publish /p:UseAppHost=false +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./CleanArchitecture.API.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "CleanArchitecture.API.dll"] +ENTRYPOINT ["dotnet", "CleanArchitecture.API.dll"] \ No newline at end of file diff --git a/CleanArchitecture/Jenkinsfiles/Pro.Jenkinsfile b/CleanArchitecture/Jenkinsfiles/Pro.Jenkinsfile new file mode 100644 index 0000000..4d146b1 --- /dev/null +++ b/CleanArchitecture/Jenkinsfiles/Pro.Jenkinsfile @@ -0,0 +1,32 @@ +pipeline { + + agent any + + envirnment { + DOCKER_REGISTRY_URL = credentials('docker-registry-url') + DOCKER_REGISTRY_USER = credentials('docker-registry-user') + DOCKER_REGISTRY_PASSWORD = credentials('docker-registry-password') + ASP_ENVIRONMENT = 'Production' + } + + stages { + + stage ('Checkout') { + steps { + checkout scm + } + } + + stage ('Build') { + steps { + script { + def version = "0.0.${env.BUILD_NUMBER}" + + echo 'docker build -t $DOCKER_REGISTRY_URL/$clean-architecture-backend:${version} .' + } + } + } + + } + +} \ No newline at end of file