Merge branch 'dev'
This commit is contained in:
@@ -27,4 +27,4 @@ README.md
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
!.git/refs/heads/**
|
||||
|
||||
@@ -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"] });
|
||||
}
|
||||
}
|
||||
}
|
||||
33
CleanArchitecture/CleanArchitecture.API/Dockerfile
Normal file
33
CleanArchitecture/CleanArchitecture.API/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
||||
#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.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
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
|
||||
COPY ["CleanArchitecture.API/CleanArchitecture.API.csproj", "CleanArchitecture.API/"]
|
||||
COPY ["CleanArchitecture.Application/CleanArchitecture.Application.csproj", "CleanArchitecture.Application/"]
|
||||
COPY ["CleanArchitecture.Domain/CleanArchitecture.Domain.csproj", "CleanArchitecture.Domain/"]
|
||||
COPY ["CleanArchitecture.Data/CleanArchitecture.Infrastructure.csproj", "CleanArchitecture.Data/"]
|
||||
COPY ["CleanArchitecture.Identity/CleanArchitecture.Identity.csproj", "CleanArchitecture.Identity/"]
|
||||
RUN dotnet restore "./CleanArchitecture.API/CleanArchitecture.API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/CleanArchitecture.API"
|
||||
RUN dotnet build "./CleanArchitecture.API.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
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"]
|
||||
@@ -14,10 +14,12 @@ builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddApplicationServices();
|
||||
|
||||
//aniado nueva cosa
|
||||
|
||||
builder.Services.AddInfrastructureServices(builder.Configuration);
|
||||
|
||||
builder.Services.AddApplicationServices();
|
||||
builder.Services.ConfigureIdentityServices(builder.Configuration);
|
||||
|
||||
builder.Services.AddCors(o =>
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"Environment": "Development"
|
||||
}
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"Environment": "Production"
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"Environment": "Development"
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace CleanArchitecture.Application.UnitTests.Features.Video.Queries
|
||||
var result = await handler.Handle(request, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<List<VideosVm>>();
|
||||
result.Count.ShouldBe(1);
|
||||
result.Count.ShouldBe(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ namespace CleanArchitecture.Application.UnitTests.Mocks
|
||||
.With(tr => tr.CreatedBy, "Alex")
|
||||
.Create()
|
||||
);
|
||||
videos.Add(fixture.Build<Video>()
|
||||
.With(tr => tr.CreatedBy, "Alex")
|
||||
.Create()
|
||||
);
|
||||
videos.Add(fixture.Build<Video>()
|
||||
.With(tr => tr.Id, Guid.Parse("edfe00d5-7599-4788-b52a-acc2a683b188"))
|
||||
.Create()
|
||||
|
||||
@@ -25,7 +25,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.Applicati
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.Identity", "CleanArchitecture.Identity\CleanArchitecture.Identity.csproj", "{2D1CFE96-C41D-4EFC-9DBA-10249988D9FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanArchitecture.Application.UnitTests", "CleanArchitecture.Application.UnitTests\CleanArchitecture.Application.UnitTests.csproj", "{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanArchitecture.Application.UnitTests", "CleanArchitecture.Application.UnitTests\CleanArchitecture.Application.UnitTests.csproj", "{CF5179BD-2D75-4CEF-BE42-EFC20EEE6021}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "JenkinsFiles", "JenkinsFiles", "{75B368EE-F27E-476E-9406-C555CEA42B1C}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
kubernetes-deploy.yaml = kubernetes-deploy.yaml
|
||||
Pro.Jenkinsfile = Pro.Jenkinsfile
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
||||
@@ -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"]
|
||||
103
CleanArchitecture/Pro.Jenkinsfile
Normal file
103
CleanArchitecture/Pro.Jenkinsfile
Normal file
@@ -0,0 +1,103 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
ASP_ENVIRONMENT = 'Production'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage ('Unit Tests') {
|
||||
steps {
|
||||
script {
|
||||
withCredentials([string(credentialsId: 'unit-test-path', variable: 'UNIT_TEST_PATH')]){
|
||||
sh "dotnet test ${UNIT_TEST_PATH}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
stage ('Push to Docker Registry') {
|
||||
steps {
|
||||
script {
|
||||
|
||||
def version = "0.0.${env.BUILD_NUMBER}"
|
||||
def imageName = "clean-architecture-backend:${version}"
|
||||
|
||||
// Usando withCredentials para manejar el REGISTRY_URL
|
||||
withCredentials([string(credentialsId: 'docker-registry-url', variable: 'REGISTRY_URL')]) {
|
||||
|
||||
def fullImageName = "${REGISTRY_URL}/${imageName}"
|
||||
|
||||
sh "docker build --build-arg ENVIRONMENT=${env.ASP_ENVIRONMENT} -t ${imageName} ./CleanArchitecture/"
|
||||
|
||||
|
||||
docker.withRegistry(REGISTRY_URL, 'dockerregistryalexdev') {
|
||||
withCredentials([string(credentialsId: 'docker-registry-url-to-push', variable: 'REGISTRY_URL_PUSH')]) {
|
||||
|
||||
echo "Vamos a ejecutar el docker tag"
|
||||
sh "docker tag ${imageName} ${REGISTRY_URL_PUSH}/${imageName}"
|
||||
echo "Vamos a ejecutar el docker push"
|
||||
sh "docker push ${REGISTRY_URL_PUSH}/${imageName}"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Clean Local Docker Image') {
|
||||
steps {
|
||||
script {
|
||||
def version = "0.0.${env.BUILD_NUMBER}"
|
||||
// Eliminar la imagen del agente de Jenkins
|
||||
sh "docker rmi clean-architecture-backend:${version}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
stage ('Cleanup Old Docker Images') {
|
||||
steps {
|
||||
script {
|
||||
withCredentials([string(credentialsId: 'docker-registry-url-to-push', variable: 'REGISTRY_URL_PUSH')]) {
|
||||
def registry = "${REGISTRY_URL_PUSH}" // Ajusta esto a tu URL de Docker Registry
|
||||
def name = 'clean-architecture-backend' // Ajusta esto al nombre de tu imagen
|
||||
|
||||
def buildNumber = env.BUILD_NUMBER.toInteger()
|
||||
def startVersion = 1
|
||||
def endVersion = buildNumber - 3 // Para borrar hasta la versión "endVersion"
|
||||
|
||||
for (int i = startVersion; i <= endVersion; i++) {
|
||||
echo "Hola ${i}"
|
||||
def versionToDelete = "0.0.${i}"
|
||||
def fullImageNameToDelete = "${name}:${versionToDelete}"
|
||||
|
||||
echo "Borrando la imagen ${registry}/${fullImageNameToDelete}"
|
||||
|
||||
// Comando modificado para utilizar variables de Jenkins
|
||||
sh "curl -v -sSL -X DELETE \"http://${registry}/v2/${fullImageNameToDelete}/manifests/\$(curl -sSL -I -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' 'http://${registry}/v2/${fullImageNameToDelete}/manifests/\$(curl -sSL 'http://${registry}/v2/${fullImageNameToDelete}/tags/list' | jq -r '.tags[0]')' | awk '\$1 == \"Docker-Content-Digest:\" { print \$2 }' | tr -d \$'\\r')\""
|
||||
|
||||
}
|
||||
|
||||
// No olvides ejecutar la recolección de basura para liberar espacio realmente.
|
||||
//echo "Ejecutando garbage collect en el Docker Registry"
|
||||
//sh "docker exec -it docker-registry bin/registry garbage-collect /etc/docker/registry/config.yml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} //stages
|
||||
}
|
||||
37
CleanArchitecture/kubernetes-deploy.yaml
Normal file
37
CleanArchitecture/kubernetes-deploy.yaml
Normal file
@@ -0,0 +1,37 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: clean-architecture-deployment
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: clean-architecture-backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: clean-architecture-backend
|
||||
spec:
|
||||
containers:
|
||||
- name: clean-architecture-backend
|
||||
image: dockerregistry.alexdev.es/clean-architecture-backend:0.0.48
|
||||
ports:
|
||||
- containerPort: 80
|
||||
imagePullSecrets:
|
||||
- name: my-docker-registry-creds
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: clean-architecture-backend-service
|
||||
annotations:
|
||||
metallb.universe.tf/address-pool: first-pool
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
loadBalancerIP: 192.168.1.70
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: clean-architecture-backend
|
||||
Reference in New Issue
Block a user