seguimos con los tests con jenkins

This commit is contained in:
Alejandro Sarmiento
2024-03-11 18:31:16 +01:00
parent 33d596bdbe
commit e290173fc3
7 changed files with 77 additions and 11 deletions

View File

@@ -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"] });
}
}
}

View File

@@ -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

View File

@@ -20,5 +20,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Environment": "Development"
}

View File

@@ -20,5 +20,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Environment": "Production"
}

View File

@@ -21,5 +21,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"Environment": "Development"
}

View File

@@ -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"]

View File

@@ -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} .'
}
}
}
}
}