From da5ac5c80b469fc286427c591cbbd49ed475e6e7 Mon Sep 17 00:00:00 2001 From: kamatador9 Date: Fri, 18 Aug 2023 17:15:01 +0100 Subject: [PATCH 01/15] jenkinsfile add --- Jenkinsfile.groovy | 126 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 Jenkinsfile.groovy diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy new file mode 100644 index 00000000..dfb339fb --- /dev/null +++ b/Jenkinsfile.groovy @@ -0,0 +1,126 @@ +pipeline { + environment { + ID_DOCKER = "${ID_DOCKER_PARAMS}" + IMAGE_NAME = "alpinehelloworld" + IMAGE_TAG = "latest" + // PORT_EXPOSED = "80" à paraméter dans le job obligatoirement + APP_NAME = "kamsu" + STG_API_ENDPOINT = "http://ip10-0-1-3-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" + STG_APP_ENDPOINT = "http://ip10-0-1-3-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" + PROD_API_ENDPOINT = "http://ip10-0-1-4-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" + PROD_APP_ENDPOINT = "http://ip10-0-1-4-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" + INTERNAL_PORT = "5000" + EXTERNAL_PORT = "${PORT_EXPOSED}" + CONTAINER_IMAGE = "${ID_DOCKER}/${IMAGE_NAME}:${IMAGE_TAG}" + + } + agent none + stages { + stage('Build image') { + agent any + steps { + script { + sh 'docker build -t ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG .' + } + } + } + stage('Run container based on builded image') { + agent any + steps { + script { + sh ''' + echo "Clean Environment" + docker rm -f $IMAGE_NAME || echo "container does not exist" + docker run --name $IMAGE_NAME -d -p ${PORT_EXPOSED}:${INTERNAL_PORT} -e PORT=${INTERNAL_PORT} ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG + sleep 5 + ''' + } + } + } + stage('Test image') { + agent any + steps { + script { + sh ''' + curl http://172.17.0.1:${PORT_EXPOSED} | grep -q "Hello world!" + ''' + } + } + } + stage('Clean Container') { + agent any + steps { + script { + sh ''' + docker stop $IMAGE_NAME + docker rm $IMAGE_NAME + ''' + } + } + } + + stage('Save Artefact') { + agent any + steps { + script { + sh ''' + docker save ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG > /tmp/alpinehelloworld.tar + ''' + } + } + } + + stage ('Login and Push Image on docker hub') { + agent any + environment { + DOCKERHUB_PASSWORD = credentials('dockerhub-credentials') + } + steps { + script { + sh ''' + echo $DOCKERHUB_PASSWORD_PSW | docker login -u $ID_DOCKER --password-stdin + docker push ${ID_DOCKER}/$IMAGE_NAME:$IMAGE_TAG + ''' + } + } + } + + stage('STAGING - Deploy app') { + agent any + steps { + script { + sh """ + echo {\\"your_name\\":\\"${APP_NAME}\\",\\"container_image\\":\\"${CONTAINER_IMAGE}\\", \\"external_port\\":\\"${EXTERNAL_PORT}\\", \\"internal_port\\":\\"${INTERNAL_PORT}\\"} > data.json + curl -X POST http://${STG_API_ENDPOINT}/staging -H 'Content-Type: application/json' --data-binary @data.json + """ + } + } + } + + + + stage('PRODUCTION - Deploy app') { + when { + expression { GIT_BRANCH == 'origin/master' } + } + agent any + + steps { + script { + sh """ + curl -X POST http://${PROD_API_ENDPOINT}/prod -H 'Content-Type: application/json' -d '{"your_name":"${APP_NAME}","container_image":"${CONTAINER_IMAGE}", "external_port":"${EXTERNAL_PORT}", "internal_port":"${INTERNAL_PORT}"}' + """ + } + } + } + } + + post { + success { + slackSend (color: '#00FF00', message: "ULRICH - SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) - PROD URL => http://${PROD_APP_ENDPOINT} , STAGING URL => http://${STG_APP_ENDPOINT}") + } + failure { + slackSend (color: '#FF0000', message: "ULRICH - FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + } +} From da13606b57e1c05027c17c3371fe64684284c42a Mon Sep 17 00:00:00 2001 From: kamatador9 Date: Fri, 18 Aug 2023 17:23:39 +0100 Subject: [PATCH 02/15] fix name jenkinsfile --- Jenkinsfile.groovy => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Jenkinsfile.groovy => Jenkinsfile (100%) diff --git a/Jenkinsfile.groovy b/Jenkinsfile similarity index 100% rename from Jenkinsfile.groovy rename to Jenkinsfile From 6f8dead87cf2d1f0bf3c0ad1c40bcc44e6681098 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:29:09 +0100 Subject: [PATCH 03/15] Update Jenkinsfile --- Jenkinsfile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dfb339fb..f814ab0b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -115,12 +115,4 @@ pipeline { } } - post { - success { - slackSend (color: '#00FF00', message: "ULRICH - SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) - PROD URL => http://${PROD_APP_ENDPOINT} , STAGING URL => http://${STG_APP_ENDPOINT}") - } - failure { - slackSend (color: '#FF0000', message: "ULRICH - FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") - } - } } From 95e9e7d144fb33fbe668f6efe17fd2b8356b64a7 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 18 Aug 2023 17:32:25 +0100 Subject: [PATCH 04/15] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f814ab0b..f324f141 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -113,6 +113,6 @@ pipeline { } } } - } + } } From 6e9b767b5285c4c29f7803b885f5c90968ec4e69 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 18 Aug 2023 19:03:19 +0100 Subject: [PATCH 05/15] Update Jenkinsfile --- Jenkinsfile | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f324f141..c33fdd7b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,17 +5,17 @@ pipeline { IMAGE_TAG = "latest" // PORT_EXPOSED = "80" à paraméter dans le job obligatoirement APP_NAME = "kamsu" - STG_API_ENDPOINT = "http://ip10-0-1-3-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" - STG_APP_ENDPOINT = "http://ip10-0-1-3-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" - PROD_API_ENDPOINT = "http://ip10-0-1-4-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" - PROD_APP_ENDPOINT = "http://ip10-0-1-4-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" + STG_API_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" + STG_APP_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" + PROD_API_ENDPOINT = "ip10-0-1-5-cjfq00979sugqdpn0vlg-1993.direct.docker.labs.eazytraining.fr" + PROD_APP_ENDPOINT = "ip10-0-1-5-cjfq00979sugqdpn0vlg-80.direct.docker.labs.eazytraining.fr" INTERNAL_PORT = "5000" EXTERNAL_PORT = "${PORT_EXPOSED}" CONTAINER_IMAGE = "${ID_DOCKER}/${IMAGE_NAME}:${IMAGE_TAG}" } agent none - stages { + stages { stage('Build image') { agent any steps { @@ -68,8 +68,7 @@ pipeline { ''' } } - } - + } stage ('Login and Push Image on docker hub') { agent any environment { @@ -83,9 +82,12 @@ pipeline { ''' } } - } - - stage('STAGING - Deploy app') { + } + + stage('STAGING - Deploy app') { + when { + expression { GIT_BRANCH == 'origin/eazylabs' } + } agent any steps { script { @@ -97,7 +99,7 @@ pipeline { } } - + stage('PRODUCTION - Deploy app') { when { @@ -115,4 +117,5 @@ pipeline { } } + } From c8c8164f2072252413978381f889f3a4a176aa6b Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 18 Aug 2023 20:11:29 +0100 Subject: [PATCH 06/15] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c33fdd7b..e3fb067f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,8 +7,8 @@ pipeline { APP_NAME = "kamsu" STG_API_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" STG_APP_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" - PROD_API_ENDPOINT = "ip10-0-1-5-cjfq00979sugqdpn0vlg-1993.direct.docker.labs.eazytraining.fr" - PROD_APP_ENDPOINT = "ip10-0-1-5-cjfq00979sugqdpn0vlg-80.direct.docker.labs.eazytraining.fr" + PROD_API_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-1993.direct.docker.labs.eazytraining.fr" + PROD_APP_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-80.direct.docker.labs.eazytraining.fr" INTERNAL_PORT = "5000" EXTERNAL_PORT = "${PORT_EXPOSED}" CONTAINER_IMAGE = "${ID_DOCKER}/${IMAGE_NAME}:${IMAGE_TAG}" From 3f25a60b3ccb33fb2f4b56ada751b3a281533353 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:13:54 +0100 Subject: [PATCH 07/15] Update Jenkinsfile --- Jenkinsfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e3fb067f..b374bf23 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,8 +5,8 @@ pipeline { IMAGE_TAG = "latest" // PORT_EXPOSED = "80" à paraméter dans le job obligatoirement APP_NAME = "kamsu" - STG_API_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-1993.direct.docker.labs.eazytraining.fr" - STG_APP_ENDPOINT = "ip10-0-1-3-cjfolbh79sugqdpn0vi0-80.direct.docker.labs.eazytraining.fr" + STG_API_ENDPOINT = "dev.q-bb.ca:1993" + STG_APP_ENDPOINT = "dev.q-bb.ca:80" PROD_API_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-1993.direct.docker.labs.eazytraining.fr" PROD_APP_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-80.direct.docker.labs.eazytraining.fr" INTERNAL_PORT = "5000" @@ -116,6 +116,14 @@ pipeline { } } } + post { + success { + slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) - PROD URL => http://${PROD_APP_ENDPOINT} , STAGING URL => http://${STG_APP_ENDPOINT}") + } + failure { + slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") + } + } } From ba0d55dc85794d63a64dbafbbab7fdd05c3c69d7 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:38:31 +0100 Subject: [PATCH 08/15] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..639f026f --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# alpinehelloworld +An Alpine-based Docker example From cc4d946b8882b4a407a7606409b394109a262e39 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:43:53 +0100 Subject: [PATCH 09/15] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 639f026f..16662dc8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # alpinehelloworld An Alpine-based Docker example + +[![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/badge/icon)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/) From f6aa4800140736905a59c84178c1d69af066e7bc Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:46:57 +0100 Subject: [PATCH 10/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 16662dc8..d8691fd7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # alpinehelloworld An Alpine-based Docker example -[![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/badge/icon)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/) +[![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/) From d93cd490d60b44b5fb227cf524d17c8f8320ffef Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:50:27 +0100 Subject: [PATCH 11/15] Update README.md From 2d3e53f9437e811fb775dd9d3665b23523dcd0b2 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:54:56 +0100 Subject: [PATCH 12/15] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index d8691fd7..ea2eafa8 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,7 @@ An Alpine-based Docker example [![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/) + +http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement + + From d7f584e8ba44efbd8611f677c02e487fb84bed68 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Wed, 23 Aug 2023 04:55:50 +0100 Subject: [PATCH 13/15] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ea2eafa8..360653d7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ An Alpine-based Docker example [![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/) -http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement - + + From 5cc47e04a5d77e5596b54fb5c56f460f3c015454 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 27 Oct 2023 20:50:26 +0200 Subject: [PATCH 14/15] Update Jenkinsfile --- Jenkinsfile | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b374bf23..b662b5ad 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,10 +5,10 @@ pipeline { IMAGE_TAG = "latest" // PORT_EXPOSED = "80" à paraméter dans le job obligatoirement APP_NAME = "kamsu" - STG_API_ENDPOINT = "dev.q-bb.ca:1993" - STG_APP_ENDPOINT = "dev.q-bb.ca:80" - PROD_API_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-1993.direct.docker.labs.eazytraining.fr" - PROD_APP_ENDPOINT = "ip10-0-2-3-cjfs1j979sugqdpn0vt0-80.direct.docker.labs.eazytraining.fr" + STG_API_ENDPOINT = "ip10-0-3-3-cku0bn8db1j0qechj98g-1993.direct.docker.labs.eazytraining.fr" + STG_APP_ENDPOINT = "ip10-0-3-3-cku0bn8db1j0qechj98g-80.direct.docker.labs.eazytraining.fr" + PROD_API_ENDPOINT = "ip10-0-1-3-cktdtr0db1j0qechj730-1993.direct.docker.labs.eazytraining.fr" + PROD_APP_ENDPOINT = "ip10-0-1-3-cktdtr0db1j0qechj730-80.direct.docker.labs.eazytraining.fr" INTERNAL_PORT = "5000" EXTERNAL_PORT = "${PORT_EXPOSED}" CONTAINER_IMAGE = "${ID_DOCKER}/${IMAGE_NAME}:${IMAGE_TAG}" @@ -115,15 +115,8 @@ pipeline { } } } - } - post { - success { - slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL}) - PROD URL => http://${PROD_APP_ENDPOINT} , STAGING URL => http://${STG_APP_ENDPOINT}") - } - failure { - slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})") - } - } + + } +} -} From 3ba84f37f418fc4d4d5fb8df61b25ac0ea7dff45 Mon Sep 17 00:00:00 2001 From: kamatador9 <36776224+kamatador9@users.noreply.github.com> Date: Fri, 27 Oct 2023 20:51:55 +0200 Subject: [PATCH 15/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 360653d7..35198880 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# alpinehelloworld +# alpinehelloworld 1 An Alpine-based Docker example [![Build Status](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/buildStatus/icon?job=deploiement)](http://ip10-0-0-3-cjimkfh79sugqdpn13cg-8080.direct.docker.labs.eazytraining.fr/job/deploiement/)