diff --git a/.jenkinsfile.swp b/.jenkinsfile.swp new file mode 100644 index 0000000..bc07790 Binary files /dev/null and b/.jenkinsfile.swp differ diff --git a/DSL/nodejsDSL.groovy b/DSL/nodejsDSL.groovy deleted file mode 100644 index 740ee73..0000000 --- a/DSL/nodejsDSL.groovy +++ /dev/null @@ -1,37 +0,0 @@ -job('Aplicacion Node.js DSL') { - description('Aplicación Node JS DSL para el curso de Jenkins') - scm { - git('https://github.com/macloujulian/nodejsapp.git', 'master') { node -> - node / gitConfigName('macloujulian') - node / gitConfigEmail('macloujulian@gmail.com') - } - } - triggers { - scm('H/7 * * * *') - } - wrappers { - nodejs('nodejs') - } - steps { - shell("npm install") - } - publishers { - slackNotifier { - notifyAborted(true) - notifyEveryFailure(true) - notifyNotBuilt(false) - notifyUnstable(false) - notifyBackToNormal(true) - notifySuccess(true) - notifyRepeatedFailure(false) - startNotification(false) - includeTestSummary(false) - includeCustomMessage(false) - customMessage(null) - sendAs(null) - commitInfoChoice('NONE') - teamDomain(null) - authToken(null) - } - } -} diff --git a/DSL/nodejsDockerDSL.groovy b/DSL/nodejsDockerDSL.groovy deleted file mode 100644 index 35d22f5..0000000 --- a/DSL/nodejsDockerDSL.groovy +++ /dev/null @@ -1,44 +0,0 @@ -job('Aplicacion Node.js Docker DSL') { - description('Aplicación Node JS Docker DSL para el curso de Jenkins') - scm { - git('https://github.com/macloujulian/nodejsapp.git', 'master') { node -> - node / gitConfigName('macloujulian') - node / gitConfigEmail('macloujulian@gmail.com') - } - } - triggers { - scm('H/7 * * * *') - } - wrappers { - nodejs('nodejs') - } - steps { - dockerBuildAndPublish { - repositoryName('macloujulian/nodejsapp') - tag('${GIT_REVISION,length=7}') - registryCredentials('docker-hub') - forcePull(false) - createFingerprints(false) - skipDecorate() - } - } - publishers { - slackNotifier { - notifyAborted(true) - notifyEveryFailure(true) - notifyNotBuilt(false) - notifyUnstable(false) - notifyBackToNormal(true) - notifySuccess(true) - notifyRepeatedFailure(false) - startNotification(false) - includeTestSummary(false) - includeCustomMessage(false) - customMessage(null) - sendAs(null) - commitInfoChoice('NONE') - teamDomain(null) - authToken(null) - } - } -} diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0cc7217 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,92 @@ +pipeline { + agent any + + stages { + stage('Instalar dependencias') { + steps { + script { + // Ejecuta npm install dentro del contenedor mynode + // sh "docker exec mynode npm install --prefix $WORKDIR" + // lo que haga en el volumen se hace en el host se refleja sh "npm install --prefix $WORKDIR" + //creo un contenedor temporal para instalar las dependencias + // sh "docker run --rm -v $WORKDIR:/app -w /app node:18 npm install" + + sh ''' + docker run --rm \ + -v /home/ec2-user/devops/backend/nodejsapp:/app \ + -w /app \ + node:18 npm install +''' + + } + } + } + stage('Build Docker') { + steps { + script { + // Construye la imagen Docker en mynode + // sh "docker exec -T mynode docker build -t $APP_NAME $WORKDIR" + sh "docker build -t $APP_NAME $WORKDIR" + } + } + } + + stage('Reiniciar contenedor') { + steps { + script { + // Detener, eliminar y reiniciar el contenedor mynode + // sh "docker exec -T mynode docker stop $CONTAINER_NAME || true" + // sh "docker exec -T mynode docker rm $CONTAINER_NAME || true" + // sh "docker exec -T mynode docker run -d --name $CONTAINER_NAME -p $PORT:3000 $APP_NAME" + sh ''' + docker stop $CONTAINER_NAME || true + docker rm $CONTAINER_NAME || true + docker run -d --name $CONTAINER_NAME -p $PORT:3000 $APP_NAME + ''' + } + } + } + } + + post { + success { + mail to: 'salvador.moskeda@gmail.com', + subject: "Pipeline Success: ${currentBuild.fullDisplayName}", + body: "El pipeline ha terminado con éxito. El build fue exitoso eres un crack." + } + + } + + + + + // stages { // Agregar la apertura de 'stages' + + // stage('Instalar dependencias') { + // steps { + // dir("$WORKDIR") { + // sh 'npm install' + // } + // } + // } + + // stage('Build Docker') { + // steps { + // dir("$WORKDIR") { + // sh "docker build -t $APP_NAME ." + // } + // } + // } + + // stage('Reiniciar contenedor') { + // steps { + // sh ''' + // docker stop $CONTAINER_NAME || true + // docker rm $CONTAINER_NAME || true + // docker run -d --name $CONTAINER_NAME -p $PORT:3000 $APP_NAME + // ''' + // } + // } + + // } // Cierre de 'stages' +} // Cierre de 'pipeline' diff --git a/app.js b/app.js index 4b67bbe..5e47a2c 100644 --- a/app.js +++ b/app.js @@ -2,12 +2,12 @@ var express = require('express'); var app = express(); app.get('/', function (req, res) { - res.send('Hello World! Hola Mundo!'); + res.send('esto se acual!! 50'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; - console.log('App escuchando a http://%s:%s', host, port); + console.log('App escdo a http://%s:%s', host, port); });