From b9683c6380019d3e630063fd7a92cb50b222cdb7 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 29 Sep 2024 19:39:28 +0300 Subject: [PATCH 01/60] add docker file --- Dockerfile | 23 +++++++++++++++++++++++ docker-compose.yml | 24 ++++++++++++++++++++++++ plan.md | 5 +++++ 3 files changed, 52 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 plan.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0d900bd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set environment variables +ENV PYTHONUNBUFFERED 1 + +# Set the working directory +WORKDIR /app + +# Copy the requirements file to the working directory +COPY requirements.txt . + +# Install dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code to the working directory +COPY . . + +# Expose the port the app runs on +EXPOSE ${PORT} + +# Command to run the application +CMD ["python", "hello.py"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4846b40 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: '3.8' + +services: + app: + build: + context: . + dockerfile: Dockerfile + environment: + - ENVIRONMENT=DEV + - HOST=0.0.0.0 + - PORT=8000 + - REDIS_HOST=redis + - REDIS_PORT=6379 + - REDIS_DB=0 + ports: + - "8000:8000" + depends_on: + - redis + command: python hello.py + + redis: + image: "redis:6.0-alpine" + ports: + - "6379:6379" diff --git a/plan.md b/plan.md new file mode 100644 index 0000000..e9c7fa1 --- /dev/null +++ b/plan.md @@ -0,0 +1,5 @@ +1. jenkins on an ec2 instance +2. configure docker & ansible agents in jenkins + 2.1. docker agent is used to build the image then run tests then push it to an image registry + 2.2. ansible agent is used to configure the ec2 ( install docker & pull the image ) +3. configure the notification channel in jenkins \ No newline at end of file From a5c75520ff59fb622b9af1cdebd1c9990e49d984 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 29 Sep 2024 19:44:23 +0300 Subject: [PATCH 02/60] Project Documentation --- Project DevOps DEPI.docx | Bin 0 -> 18067 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Project DevOps DEPI.docx diff --git a/Project DevOps DEPI.docx b/Project DevOps DEPI.docx new file mode 100644 index 0000000000000000000000000000000000000000..ae9301892194e8da82347b13d8a6c4cde7b9073f GIT binary patch literal 18067 zcmeIaWpo_LvM$<^EM{hAS!gkX#mo%0n3MHT?~Bme&%|AT9wE^gGcmmWdr{>Pi&bi*wXg zJsK~4OtS4b`VIbJ7H@N=wsuTO79e`!`repv1t^)c+%!K_)dxTXReYo}3C92?yntsY z=H;{Yg^$DqQd3;viXSXEoow(AvE`E#PgW8{n3~gOld@WIG68z^5J86y`(qjL4hag; z=Ckf*IA;;qFnr0P&x0V2E$}TVMX36Eh_kI#bNwnjR26NSs`6-s7I4;2B{N9s9%pDd ziQb}4mQvHoWmA@uUU9uNrzk{}bnr9kP6FRnFuF#OnL5^gMIk{}09DzY3#xYCT$`eF zj&br+jid(^`;6+dner-sVtJk z+%8}9x5uCqfh@bX>Id?EXx95X2tfAVnkQZ~R^!D7NBX1nL4Pz)9a{r)J389m^naV> z|KPUxw_7iZ>HcVzFnkw&uYS|*ax2{!xzcocQ>z%u;1C*OlE|w|ri*W{TuV#9T1VeS zMrUSYr(EsQgdMixv@Wp{lwd>JAr~ICdo`ZhoB{Da+VUBk7p!++QV;G7Uq^_=C`bH4 z)lfqwvB07qf|AC&koTzs@AeC!O^7Hb=k!Qwb2Ds|7Vnch8MBfZ<`+ywHQc~UxP>|b za9buYJ)sPFs}mV%q9S`XYP9+kk7Jv@gqu>{Qe&CZ(~+h{>y|-bUA9dhyXJNl_6Pr< zhRlWxrh9fb)I?H$`x$b8$;)yh#!^W zWM!*Qr*Ea_VDT}A{T{sbG*2v7+0foPyE^=~K+zNk!W}xD$#4&K9T+)VktI0}Cw-`= zS;%WBL>1*HD?NfddOTwGvuP8~*z!>uZC25O47A~f?ch4?2>0OI*q?r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fYQe|EZ%Vzu|~w}lafssyO*A=D~m|XI_kN*L7Pk3!*{H&+MP#^ zn$#X?qjkfDq2{M#u@O-K`o(GIOntS{YcIh-7v%a)zXfPk<>>!QP9y!5EoyUt9_SR4yXW-`)le!M%W%xSbArl2OoOx zm5CgeQ>p`uFrcEc()w*sc4HTPqVG=mN?)wSw@qP<%0;T3F3JzXm6U|$i|U_V^z_YrgyqB>V6|nNsNxv5ZN>gOln>C z2ItABgT5|m3&+DlXN)5!!3^AE2^%JgP_Ru$x|%LyP2vUG|L)_36w8DOA1uO`ICU9( zu=yW**YK1HVYd%eo%m2ygukomcWdk4ee3^f>PNMG9BJ~S(jVc@ZN$Ie<<94_Me zikG>)?KV;CBPl}~P}7X(4BH3Y-1HmV;tI%PKok7FTXHIY^)pOp`8(ZC*gyhVICQ({ zTtGr|!8B53+S;8la;nOF%(k0AsVwe8bQKQ9f_GgrzP2*7G(Y*LCCAe9dk%?;I908 zVTou8P0vCD>uKg<=Lbbiec*4i#C)_Y6pj3axRu^g8cp*o5`@l0q8bPm2pyp>Y|uEI zOQPScrGPGllY+WD0jjMV&=T(EWkDCrJdZ0{`_vuEo_@%wbQ})Yboyv^EWGJh8DZbP zQc&5_n_>VpWp^S;c6d8lgdRVSZSqH4x;SUNShJTNK98MZ6YuV}ZvPcz4FpW{F(>@b zZ{PT@$MYBc5AWiTmH2l7|Nee}zn}m>=0|t_x3>lS6Zp@K(|M(&se>`L}1|lOT^zJ_x=h0XSmE? z@HxVN!T&9I=AZa~F7^F|SEc;3`2Vx;_fPOYZH2$UitPUa|HE?lr-Xk_D*uvT!TB!< z|2D<^C;s0@_`lEq009pG@ZZM!f5QL0*Zn(ul<#lwfAzt#5}+UI1pvT&B%lusb^rSN G*Z&8>6z*XF literal 0 HcmV?d00001 From 7af7ab0f92fd35db97289126ab1016d22e1d784d Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 03:54:49 +0300 Subject: [PATCH 03/60] update docker-compose file --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 4846b40..d3ace5c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: depends_on: - redis command: python hello.py - + image: johnsami/dockerized-app-build-app:latest redis: image: "redis:6.0-alpine" ports: From 7b432bba29834beca903a4a741f9909b4525cd9d Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 04:02:21 +0300 Subject: [PATCH 04/60] update dockerfile --- Dockerfile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0d900bd..6c65a82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,15 @@ -# Use an official Python runtime as a parent image FROM python:3.9-slim -# Set environment variables ENV PYTHONUNBUFFERED 1 -# Set the working directory WORKDIR /app -# Copy the requirements file to the working directory COPY requirements.txt . -# Install dependencies RUN pip install --no-cache-dir -r requirements.txt -# Copy the rest of the application code to the working directory COPY . . -# Expose the port the app runs on EXPOSE ${PORT} -# Command to run the application CMD ["python", "hello.py"] From 8ee7237ebaa505ae0725d3af0b25201787f0c410 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 05:44:26 +0300 Subject: [PATCH 05/60] update docker-compose file --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d3ace5c..a20127e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: - REDIS_PORT=6379 - REDIS_DB=0 ports: - - "8000:8000" + - "8010:8000" depends_on: - redis command: python hello.py From d44074e933a136644283cd86935bc51f50c33187 Mon Sep 17 00:00:00 2001 From: Mostafa-Hesham <86481662+MainUseless@users.noreply.github.com> Date: Tue, 1 Oct 2024 20:47:08 +0300 Subject: [PATCH 06/60] Update plan.md --- plan.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plan.md b/plan.md index e9c7fa1..f1d4126 100644 --- a/plan.md +++ b/plan.md @@ -2,4 +2,5 @@ 2. configure docker & ansible agents in jenkins 2.1. docker agent is used to build the image then run tests then push it to an image registry 2.2. ansible agent is used to configure the ec2 ( install docker & pull the image ) -3. configure the notification channel in jenkins \ No newline at end of file +3. configure the notification channel in jenkins +4. testing jenkins auto build From dbc60cf02c79ce5553a0a6a9a4734e70108bee57 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:01:08 +0300 Subject: [PATCH 07/60] Add Jenkinsfile --- jenkinsfile | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 jenkinsfile diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..9ea7a2e --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,78 @@ +pipeline { + agent any + + // Options to configure the pipeline behavior + options { + // Delete the workspace before the build starts + skipDefaultCheckout true + } + + // Triggers to start the pipeline + triggers { + // Trigger the pipeline on GitHub push events + githubPush() + } + + // Environment variables and credentials + environment { + // Define Docker Hub credentials (replace with your actual credentials ID) + DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials-id') + } + + stages { + stage('Cleanup Workspace') { + steps { + // Delete the workspace to ensure a clean state + deleteDir() + } + } + + stage('Checkout Code') { + steps { + // Checkout the repository from GitHub + git( + branch: 'master', + url: 'https://github.com/johnsamey/DEPI-Project.git', + credentialsId: 'github-token-credentials-id' // Replace with your GitHub credentials ID + ) + } + } + + stage('Build Docker Image') { + steps { + // Use Docker Compose to build the Docker image + sh ''' + docker-compose build + docker tag depi-project-app:latest johnsami/depi-project-app:latest + ''' + } + } + + stage('Push Docker Image') { + steps { + // Log in to Docker Hub and push the Docker image + sh ''' + echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin + docker-compose push + ''' + } + } + } + + // Environment variables with credentials binding + environment { + // Bind Docker Hub username and password from the credentials + DOCKER_HUB_USERNAME = "${DOCKER_HUB_CREDENTIALS_USR}" + DOCKER_HUB_PASSWORD = "${DOCKER_HUB_CREDENTIALS_PSW}" + } + + // Post-build actions (optional) + post { + success { + echo 'Build and push completed successfully!' + } + failure { + echo 'Build or push failed.' + } + } +} From e02eaa5836e0d53b332644b0e3dd0eaa259968b8 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:18:08 +0300 Subject: [PATCH 08/60] Add Jenkinsfile --- jenkinsfile | 74 +++++++++++++++++++---------------------------------- 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 9ea7a2e..3e823e9 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,78 +1,56 @@ + pipeline { agent any - // Options to configure the pipeline behavior - options { - // Delete the workspace before the build starts - skipDefaultCheckout true - } - - // Triggers to start the pipeline - triggers { - // Trigger the pipeline on GitHub push events - githubPush() + environment { + DOCKER_HUB_USERNAME = credentials('docker-hub-username') + DOCKER_HUB_PASSWORD = credentials('docker-hub-password') } - // Environment variables and credentials - environment { - // Define Docker Hub credentials (replace with your actual credentials ID) - DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials-id') + options { + // Example to delete the workspace before the build starts, similar to the option in the freestyle job. + deleteDir() } stages { - stage('Cleanup Workspace') { + stage('Checkout') { steps { - // Delete the workspace to ensure a clean state - deleteDir() - } - } - - stage('Checkout Code') { - steps { - // Checkout the repository from GitHub - git( - branch: 'master', - url: 'https://github.com/johnsamey/DEPI-Project.git', - credentialsId: 'github-token-credentials-id' // Replace with your GitHub credentials ID - ) + git url: 'https://github.com/username/DEPiProject.git', branch: 'master', credentialsId: 'github-personal-access-token' } } stage('Build Docker Image') { steps { - // Use Docker Compose to build the Docker image - sh ''' + script { + sh ''' + cd $WORKSPACE docker-compose build - docker tag depi-project-app:latest johnsami/depi-project-app:latest - ''' + docker tag depi-project-app:latest joshman/depi-project-app:latest + ''' + } } } - stage('Push Docker Image') { + stage('Push to Docker Hub') { steps { - // Log in to Docker Hub and push the Docker image - sh ''' + script { + sh ''' + cd $WORKSPACE echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin docker-compose push - ''' + ''' + } } } } - // Environment variables with credentials binding - environment { - // Bind Docker Hub username and password from the credentials - DOCKER_HUB_USERNAME = "${DOCKER_HUB_CREDENTIALS_USR}" - DOCKER_HUB_PASSWORD = "${DOCKER_HUB_CREDENTIALS_PSW}" + triggers { + pollSCM('H/5 * * * *') // Poll SCM every 5 minutes (adjust as needed) } - // Post-build actions (optional) post { - success { - echo 'Build and push completed successfully!' - } - failure { - echo 'Build or push failed.' + always { + cleanWs() // Clean workspace after the build } } -} +} \ No newline at end of file From 1f250e0476a27c33b934919976be0fc6e1bba8e4 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:19:49 +0300 Subject: [PATCH 09/60] Add Jenkinsfile --- jenkinsfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 3e823e9..9759a76 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -7,10 +7,7 @@ pipeline { DOCKER_HUB_PASSWORD = credentials('docker-hub-password') } - options { - // Example to delete the workspace before the build starts, similar to the option in the freestyle job. - deleteDir() - } + stages { stage('Checkout') { From e133c2b37f192edb9feda104a09229641b4daf3f Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:27:54 +0300 Subject: [PATCH 10/60] Add Jenkinsfile --- jenkinsfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 9759a76..856426c 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -2,13 +2,11 @@ pipeline { agent any - environment { - DOCKER_HUB_USERNAME = credentials('docker-hub-username') - DOCKER_HUB_PASSWORD = credentials('docker-hub-password') + environment { + DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') } - stages { stage('Checkout') { steps { @@ -33,7 +31,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From 6acc2c7170808a211c98a0f4c0addbd4bbe716fc Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:29:13 +0300 Subject: [PATCH 11/60] Add Jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 856426c..2018c3b 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -3,7 +3,7 @@ pipeline { agent any environment { - DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') + DOCKER_HUB_CREDENTIALS = credentials('dockerHub-token') } From a96162d47d1c2d6633a4aaef453d9e70a2fe95b4 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:32:26 +0300 Subject: [PATCH 12/60] Add Jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 2018c3b..1c46e1d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -10,7 +10,7 @@ pipeline { stages { stage('Checkout') { steps { - git url: 'https://github.com/username/DEPiProject.git', branch: 'master', credentialsId: 'github-personal-access-token' + git url: 'https://github.com/username/DEPiProject.git', branch: 'master', credentialsId: 'github-token' } } From c9b4b84d03368ff1ceba7c03f367a816ba983f5a Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Tue, 1 Oct 2024 22:34:23 +0300 Subject: [PATCH 13/60] Add Jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 1c46e1d..aa5e76c 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -10,7 +10,7 @@ pipeline { stages { stage('Checkout') { steps { - git url: 'https://github.com/username/DEPiProject.git', branch: 'master', credentialsId: 'github-token' + git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github-token' } } From 4d975a41db6aa7dc9016dfe9bc9b4e2f579ef64e Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 22:48:36 +0300 Subject: [PATCH 14/60] update jenkinsfile --- jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index aa5e76c..52f3f58 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -3,14 +3,14 @@ pipeline { agent any environment { - DOCKER_HUB_CREDENTIALS = credentials('dockerHub-token') + DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') } stages { stage('Checkout') { steps { - git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github-token' + git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' } } From 7ebb7e6fc4622f8f71a8a623589f5595b67928dd Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 22:56:16 +0300 Subject: [PATCH 15/60] add email notification to the pipeline --- jenkinsfile | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/jenkinsfile b/jenkinsfile index 52f3f58..2f770a5 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -44,6 +44,40 @@ pipeline { } post { + failure { + emailext( + subject: 'Build failed: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''Build failed in Jenkins: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) + } + unstable { + emailext( + subject: 'Build unstable: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''The build is unstable: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) + } + success { + emailext( + subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''The build was successful: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) + } always { cleanWs() // Clean workspace after the build } From d939c1c73a321ace4da8ada9f6d6b7c4c2759f37 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 22:58:16 +0300 Subject: [PATCH 16/60] test failure jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 2f770a5..a98664f 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -31,7 +31,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From 26b3f8a92bd0089632d668ae45e22dbaf438b648 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 23:04:45 +0300 Subject: [PATCH 17/60] test failure jenkinsfile --- jenkinsfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index a98664f..9bc45f1 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,7 +1,9 @@ pipeline { agent any - + options { + deleteDir() + } environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') } @@ -78,8 +80,5 @@ pipeline { attachLog: true ) } - always { - cleanWs() // Clean workspace after the build - } } } \ No newline at end of file From f53c39d61842fb8e5a39968d9cf679f0559deb62 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 23:07:15 +0300 Subject: [PATCH 18/60] test failure jenkinsfile --- jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 9bc45f1..519310d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,15 +1,18 @@ pipeline { agent any - options { - deleteDir() - } + environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') } stages { + stage('Cleanup') { + steps { + deleteDir() + } + } stage('Checkout') { steps { git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' From 61e7f1f6c4dfdc6e8b41e3cb31c953f73f8a6bb7 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Tue, 1 Oct 2024 23:11:36 +0300 Subject: [PATCH 19/60] update --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 519310d..1be719b 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -36,7 +36,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From a5702065e9f1bf49f3b8f2dfc4285bccbc22c577 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 04:11:23 +0300 Subject: [PATCH 20/60] modify jenkinsfile --- jenkinsfile | 91 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 1be719b..adbe756 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -47,41 +47,66 @@ pipeline { triggers { pollSCM('H/5 * * * *') // Poll SCM every 5 minutes (adjust as needed) } - post { - failure { - emailext( - subject: 'Build failed: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''Build failed in Jenkins: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) - } - unstable { - emailext( - subject: 'Build unstable: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''The build is unstable: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) + always { + script { + emailext subject: "Jenkins Job: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${currentBuild.currentResult}", + body: """ + Job Name: ${env.JOB_NAME} + Build Number: ${env.BUILD_NUMBER} + Build Status: ${currentBuild.currentResult} + Build URL: ${env.BUILD_URL} + """, + recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], + to: 'johnhana567@gmail.com' + } } success { - emailext( - subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''The build was successful: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) + emailext subject: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}", + body: "Good news, the build was successful!", + to: 'johnhana567@gmail.com' + } + failure { + emailext subject: "FAILURE: ${env.JOB_NAME} #${env.BUILD_NUMBER}", + body: "Unfortunately, the build has failed.", + to: 'johnhana567@gmail.com' } } -} \ No newline at end of file +} + +// post { +// failure { +// emailext( +// subject: 'Build failed: ${JOB_NAME} [${BUILD_NUMBER}]', +// body: '''Build failed in Jenkins: +// - Job: ${JOB_NAME} +// - Build number: ${BUILD_NUMBER} +// - Check console output at: ${BUILD_URL}''', +// recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], +// to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', +// attachLog: true +// ) +// } +// unstable { +// emailext( +// subject: 'Build unstable: ${JOB_NAME} [${BUILD_NUMBER}]', +// body: '''The build is unstable: +// - Job: ${JOB_NAME} +// - Build number: ${BUILD_NUMBER} +// - Check console output at: ${BUILD_URL}''', +// to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', +// attachLog: true +// ) +// } +// success { +// emailext( +// subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', +// body: '''The build was successful: +// - Job: ${JOB_NAME} +// - Build number: ${BUILD_NUMBER} +// - Check console output at: ${BUILD_URL}''', +// to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', +// attachLog: true +// ) +// } +// } \ No newline at end of file From 553af293732a8e724f21a25d87d705ac2d16255f Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 04:39:08 +0300 Subject: [PATCH 21/60] modify jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index adbe756..a7a7c6e 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -25,7 +25,7 @@ pipeline { sh ''' cd $WORKSPACE docker-compose build - docker tag depi-project-app:latest joshman/depi-project-app:latest + docker tag depi-project-app:latest johnsami/dockerized-app-build-app:latest ''' } } From 6c9bf70e65be6f0676d52e6917ee162e837b2acd Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 04:41:44 +0300 Subject: [PATCH 22/60] modify jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index a7a7c6e..cbafa3d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -25,7 +25,7 @@ pipeline { sh ''' cd $WORKSPACE docker-compose build - docker tag depi-project-app:latest johnsami/dockerized-app-build-app:latest + docker tag dockerized-app-build-app johnsami/dockerized-app-build-app:latest ''' } } From 27e455bc2b8d8ca823ad04c1b2fb875280afa29b Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 04:44:40 +0300 Subject: [PATCH 23/60] modify jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index cbafa3d..3978e2b 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -31,7 +31,7 @@ pipeline { } } - stage('Push to Docker Hub') { + stage('Push to Docker-Hub') { steps { script { sh ''' From 4eff53c1353fb3cbf86afc144638cce3fcf6ad62 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 04:45:54 +0300 Subject: [PATCH 24/60] modify jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 3978e2b..71478d3 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -25,7 +25,7 @@ pipeline { sh ''' cd $WORKSPACE docker-compose build - docker tag dockerized-app-build-app johnsami/dockerized-app-build-app:latest + docker tag johnsami/dockerized-app-build-app johnsami/dockerized-app-build-app:latest ''' } } From 6b273458792221a6ef1c42037433e23c42f2c20f Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 18:30:08 +0300 Subject: [PATCH 25/60] update jenkinsfile --- jenkinsfile | 73 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 71478d3..8175147 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -36,7 +36,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } @@ -45,31 +45,28 @@ pipeline { } triggers { - pollSCM('H/5 * * * *') // Poll SCM every 5 minutes (adjust as needed) + pollSCM('H/5 * * * *') } post { - always { - script { - emailext subject: "Jenkins Job: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${currentBuild.currentResult}", - body: """ - Job Name: ${env.JOB_NAME} - Build Number: ${env.BUILD_NUMBER} - Build Status: ${currentBuild.currentResult} - Build URL: ${env.BUILD_URL} - """, - recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], - to: 'johnhana567@gmail.com' - } - } - success { - emailext subject: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}", - body: "Good news, the build was successful!", - to: 'johnhana567@gmail.com' - } failure { - emailext subject: "FAILURE: ${env.JOB_NAME} #${env.BUILD_NUMBER}", - body: "Unfortunately, the build has failed.", - to: 'johnhana567@gmail.com' + emailext( + to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', + subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build failed in Jenkins:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) + } + unstable { + emailext( + to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', + subject: 'Build is unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build is unstable:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) } } } @@ -109,4 +106,32 @@ pipeline { // attachLog: true // ) // } -// } \ No newline at end of file +// } + + + + // post { + // always { + // script { + // emailext subject: "Jenkins Job: ${env.JOB_NAME} #${env.BUILD_NUMBER} - ${currentBuild.currentResult}", + // body: """ + // Job Name: ${env.JOB_NAME} + // Build Number: ${env.BUILD_NUMBER} + // Build Status: ${currentBuild.currentResult} + // Build URL: ${env.BUILD_URL} + // """, + // recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']], + // to: 'johnhana567@gmail.com' + // } + // } + // success { + // emailext subject: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}", + // body: "Good news, the build was successful!", + // to: 'johnhana567@gmail.com' + // } + // failure { + // emailext subject: "FAILURE: ${env.JOB_NAME} #${env.BUILD_NUMBER}", + // body: "Unfortunately, the build has failed.", + // to: 'johnhana567@gmail.com' + // } + // } \ No newline at end of file From 11a58eabcbc5d9fbfabce9607690c70745b29206 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 18:33:11 +0300 Subject: [PATCH 26/60] update jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 8175147..dd1665c 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -36,7 +36,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From eefdddf073916d326f80d0cf2ee0fec0a60a8bbe Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 19:14:18 +0300 Subject: [PATCH 27/60] update jenkinsfile --- jenkinsfile | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index dd1665c..b504d6d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,31 +1,52 @@ - pipeline { agent any - environment { + environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') + DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' + DOCKER_IMAGE_TAG = 'latest' } - stages { stage('Cleanup') { steps { deleteDir() } } + stage('Checkout') { steps { git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' } } + stage('Prepare Docker Image') { + steps { + script { + sh ''' + cd $WORKSPACE + + # Check if the Docker image exists + IMAGE_EXISTS=$(docker images -q $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG) + + if [ -n "$IMAGE_EXISTS" ]; then + echo "Docker image exists. Deleting existing image..." + docker rmi $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG + else + echo "Docker image does not exist. Proceeding to build a new image..." + fi + ''' + } + } + } + stage('Build Docker Image') { steps { script { sh ''' cd $WORKSPACE docker-compose build - docker tag johnsami/dockerized-app-build-app johnsami/dockerized-app-build-app:latest + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG ''' } } @@ -45,8 +66,9 @@ pipeline { } triggers { - pollSCM('H/5 * * * *') + pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes } + post { failure { emailext( @@ -71,6 +93,7 @@ pipeline { } } + // post { // failure { // emailext( From 2c36fc6dc259b669418dfbde953aadcb8cca6c13 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 19:17:48 +0300 Subject: [PATCH 28/60] update jenkinsfile --- jenkinsfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jenkinsfile b/jenkinsfile index b504d6d..fbca3ac 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -90,6 +90,17 @@ pipeline { attachLog: true ) } + success { + emailext( + subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''The build was successful: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) + } } } From b3f5378ed2d201766024b72a8b137140e7c11be0 Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:34:20 +0300 Subject: [PATCH 29/60] add always test email --- jenkinsfile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index fbca3ac..3bb6115 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -70,9 +70,18 @@ pipeline { } post { + always { + emailext( + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + subject: 'Test Email from Jenkins', + body: 'This is a test email to verify Jenkins email notifications.', + attachLog: false + ) + } + failure { emailext( - to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', body: """

Build failed in Jenkins:

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

@@ -82,8 +91,7 @@ pipeline { } unstable { emailext( - to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', - subject: 'Build is unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', body: """

Build is unstable:

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

Check console output at ${BUILD_URL}

""", @@ -102,6 +110,9 @@ pipeline { ) } } + + + } From e47cda87d81d3d5e3b1b00c13989e7b2c65ef606 Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:36:22 +0300 Subject: [PATCH 30/60] add subject for email --- jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/jenkinsfile b/jenkinsfile index 3bb6115..dbd4fbc 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -92,6 +92,7 @@ pipeline { unstable { emailext( to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', body: """

Build is unstable:

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

Check console output at ${BUILD_URL}

""", From 95f2a735d8f803c50c94a1a251fc29970a418668 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 19:39:02 +0300 Subject: [PATCH 31/60] Updated Jenkinsfile for testing --- jenkinsfile | 212 +++++++++++++++++++++++++++------------------------- 1 file changed, 112 insertions(+), 100 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index dbd4fbc..1445b5c 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,119 +1,131 @@ pipeline { - agent any - - environment { - DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') - DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' - DOCKER_IMAGE_TAG = 'latest' + agent any + + environment { + DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') + DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' + DOCKER_IMAGE_TAG = 'latest' + } + + stages { + stage('Cleanup') { + steps { + deleteDir() + } } - stages { - stage('Cleanup') { - steps { - deleteDir() - } - } - - stage('Checkout') { - steps { - git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' - } - } + stage('Checkout') { + steps { + git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' + } + } - stage('Prepare Docker Image') { - steps { - script { - sh ''' - cd $WORKSPACE - - # Check if the Docker image exists - IMAGE_EXISTS=$(docker images -q $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG) - - if [ -n "$IMAGE_EXISTS" ]; then - echo "Docker image exists. Deleting existing image..." - docker rmi $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG - else - echo "Docker image does not exist. Proceeding to build a new image..." - fi - ''' - } - } + // Optional Stage for Dependency Installation + stage('Install Dependencies (Optional)') { + when { + expression { // Add a condition to run this stage if needed (e.g., when you have external libraries) + return projectHasDependencies() // Replace with your logic to check for dependencies } + } + steps { + sh 'pip install -r requirements.txt' // Example for installing dependencies from a requirements file + } + } - stage('Build Docker Image') { - steps { - script { - sh ''' - cd $WORKSPACE - docker-compose build - docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG - ''' - } - } + stage('Prepare Docker Image (Optional)') { + steps { + script { + """ + cd $WORKSPACE + + # Check if the Docker image exists (Optional) + IMAGE_EXISTS=$(docker images -q $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG) + if [ -n "$IMAGE_EXISTS" ]; then + echo "Docker image exists. Skipping build..." + else + echo "Docker image does not exist. Proceeding to build..." + fi + """ } + } + } - stage('Push to Docker-Hub') { - steps { - script { - sh ''' - cd $WORKSPACE - echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin - docker-compose push - ''' - } - } + stage('Build Docker Image') { + steps { + script { + """ + cd $WORKSPACE + docker-compose build + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG + """ } + } } - triggers { - pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes + stage('Run Unit Tests') { + steps { + // Assuming your tests are in DEPI-Project/tests + sh 'pytest DEPI-Project/tests --junitxml=junit-test-results.xml' // Generate JUnit XML report + } } - post { - always { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Test Email from Jenkins', - body: 'This is a test email to verify Jenkins email notifications.', - attachLog: false - ) - } + stage('Publish Test Results') { + steps { + // Assuming you have the JUnit Plugin installed + junit testResults: 'junit-test-results.xml' + } + } - failure { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build failed in Jenkins:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) - } - unstable { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build is unstable:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) - } - success { - emailext( - subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''The build was successful: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) + stage('Push to Docker-Hub') { + steps { + script { + """ + cd $WORKSPACE + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + docker-compose push + """ } + } } - - - + } + + triggers { + pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes + } + + post { + failure { + emailext( + to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', + subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build failed in Jenkins:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) + } + unstable { + emailext( + to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', + subject: 'Build is unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build is unstable:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) + } + success { + emailext( + subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''The build was successful: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + to: 'mostafa777444333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) + } + } } From d5a1d4cb42db98ceeacf613b5f454a84034d1249 Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:42:17 +0300 Subject: [PATCH 32/60] return to the LTS --- jenkinsfile | 212 +++++++++++++++++++++++++--------------------------- 1 file changed, 100 insertions(+), 112 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 1445b5c..dbd4fbc 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,131 +1,119 @@ pipeline { - agent any - - environment { - DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') - DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' - DOCKER_IMAGE_TAG = 'latest' - } - - stages { - stage('Cleanup') { - steps { - deleteDir() - } - } + agent any - stage('Checkout') { - steps { - git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' - } + environment { + DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') + DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' + DOCKER_IMAGE_TAG = 'latest' } - // Optional Stage for Dependency Installation - stage('Install Dependencies (Optional)') { - when { - expression { // Add a condition to run this stage if needed (e.g., when you have external libraries) - return projectHasDependencies() // Replace with your logic to check for dependencies + stages { + stage('Cleanup') { + steps { + deleteDir() + } } - } - steps { - sh 'pip install -r requirements.txt' // Example for installing dependencies from a requirements file - } - } - stage('Prepare Docker Image (Optional)') { - steps { - script { - """ - cd $WORKSPACE - - # Check if the Docker image exists (Optional) - IMAGE_EXISTS=$(docker images -q $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG) - if [ -n "$IMAGE_EXISTS" ]; then - echo "Docker image exists. Skipping build..." - else - echo "Docker image does not exist. Proceeding to build..." - fi - """ + stage('Checkout') { + steps { + git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' + } } - } - } - stage('Build Docker Image') { - steps { - script { - """ - cd $WORKSPACE - docker-compose build - docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG - """ + stage('Prepare Docker Image') { + steps { + script { + sh ''' + cd $WORKSPACE + + # Check if the Docker image exists + IMAGE_EXISTS=$(docker images -q $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG) + + if [ -n "$IMAGE_EXISTS" ]; then + echo "Docker image exists. Deleting existing image..." + docker rmi $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG + else + echo "Docker image does not exist. Proceeding to build a new image..." + fi + ''' + } + } } - } - } - stage('Run Unit Tests') { - steps { - // Assuming your tests are in DEPI-Project/tests - sh 'pytest DEPI-Project/tests --junitxml=junit-test-results.xml' // Generate JUnit XML report - } + stage('Build Docker Image') { + steps { + script { + sh ''' + cd $WORKSPACE + docker-compose build + docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG + ''' + } + } + } + + stage('Push to Docker-Hub') { + steps { + script { + sh ''' + cd $WORKSPACE + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + docker-compose push + ''' + } + } + } } - stage('Publish Test Results') { - steps { - // Assuming you have the JUnit Plugin installed - junit testResults: 'junit-test-results.xml' - } + triggers { + pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes } - stage('Push to Docker-Hub') { - steps { - script { - """ - cd $WORKSPACE - echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin - docker-compose push - """ + post { + always { + emailext( + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + subject: 'Test Email from Jenkins', + body: 'This is a test email to verify Jenkins email notifications.', + attachLog: false + ) + } + + failure { + emailext( + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build failed in Jenkins:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) + } + unstable { + emailext( + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + body: """

Build is unstable:

+

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+

Check console output at ${BUILD_URL}

""", + attachLog: true + ) + } + success { + emailext( + subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', + body: '''The build was successful: + - Job: ${JOB_NAME} + - Build number: ${BUILD_NUMBER} + - Check console output at: ${BUILD_URL}''', + to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + attachLog: true + ) } - } - } - } - - triggers { - pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes - } - - post { - failure { - emailext( - to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', - subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build failed in Jenkins:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) - } - unstable { - emailext( - to: 'mostafa777444333@gmail.com, johnhnana567@gmail.com, khalid.salman1996@gmail.com', - subject: 'Build is unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build is unstable:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) - } - success { - emailext( - subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''The build was successful: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - to: 'mostafa777444333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) } - } + + + } From 4d4c2b1a086983be694bd02941e62bfa81dcfc0a Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:42:57 +0300 Subject: [PATCH 33/60] return to the LTS --- jenkinsfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jenkinsfile b/jenkinsfile index dbd4fbc..02fa83e 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -78,6 +78,12 @@ pipeline { attachLog: false ) } + + always { + mail to: 'mostafa777444333@gmail.com', + subject: 'Test Email from Jenkins', + body: 'This is a test email to verify Jenkins email notifications.' + } failure { emailext( From 31f7762bd645bb50082fc85ae4cd3217e0f2970d Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:45:38 +0300 Subject: [PATCH 34/60] remove second always --- jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 02fa83e..6000df0 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -77,9 +77,7 @@ pipeline { body: 'This is a test email to verify Jenkins email notifications.', attachLog: false ) - } - - always { + mail to: 'mostafa777444333@gmail.com', subject: 'Test Email from Jenkins', body: 'This is a test email to verify Jenkins email notifications.' From 8fb93470c64f5248f208d3106a8fe36954e836dd Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 19:49:52 +0300 Subject: [PATCH 35/60] add rest of email to mail --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 6000df0..069b05d 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -78,7 +78,7 @@ pipeline { attachLog: false ) - mail to: 'mostafa777444333@gmail.com', + mail to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', subject: 'Test Email from Jenkins', body: 'This is a test email to verify Jenkins email notifications.' } From dbb5d62435049036dd52890205d2e534dd97302c Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:02:52 +0300 Subject: [PATCH 36/60] use mail instead of emailext --- jenkinsfile | 112 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 38 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 069b05d..4d31685 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -5,6 +5,7 @@ pipeline { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' DOCKER_IMAGE_TAG = 'latest' + EMAIL_RECIPIENTS = 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com' } stages { @@ -69,50 +70,85 @@ pipeline { pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes } + // post { + // always { + // emailext( + // to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + // subject: 'Test Email from Jenkins', + // body: 'This is a test email to verify Jenkins email notifications.', + // attachLog: false + // ) + + // mail to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + // subject: 'Test Email from Jenkins', + // body: 'This is a test email to verify Jenkins email notifications.' + // } + + // failure { + // emailext( + // to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + // subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + // body: """

Build failed in Jenkins:

+ //

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+ //

Check console output at ${BUILD_URL}

""", + // attachLog: true + // ) + // } + // unstable { + // emailext( + // to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + // subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', + // body: """

Build is unstable:

+ //

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

+ //

Check console output at ${BUILD_URL}

""", + // attachLog: true + // ) + // } + // success { + // emailext( + // subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', + // body: '''The build was successful: + // - Job: ${JOB_NAME} + // - Build number: ${BUILD_NUMBER} + // - Check console output at: ${BUILD_URL}''', + // to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', + // attachLog: true + // ) + // } + // } + post { - always { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Test Email from Jenkins', - body: 'This is a test email to verify Jenkins email notifications.', - attachLog: false - ) - - mail to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Test Email from Jenkins', - body: 'This is a test email to verify Jenkins email notifications.' + success { + mail to: "${EMAIL_RECIPIENTS}", + subject: "✅ Build Successful: ${JOB_NAME} - Build #${BUILD_NUMBER}", + body: """

Good news! The build was successful.

+

Job: ${JOB_NAME}

+

Build Number: ${BUILD_NUMBER}

+

Check the details at ${BUILD_URL}

""", + mimeType: 'text/html', + attachLog: true } failure { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build failed in Jenkins:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) + mail to: "${EMAIL_RECIPIENTS}", + subject: "❌ Build Failed: ${JOB_NAME} - Build #${BUILD_NUMBER}", + body: """

Oops! The build has failed.

+

Job: ${JOB_NAME}

+

Build Number: ${BUILD_NUMBER}

+

Check the console output at ${BUILD_URL}

""", + mimeType: 'text/html', + attachLog: true } + unstable { - emailext( - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}', - body: """

Build is unstable:

-

Job: ${JOB_NAME} - Build #${BUILD_NUMBER}

-

Check console output at ${BUILD_URL}

""", - attachLog: true - ) - } - success { - emailext( - subject: 'Build successful: ${JOB_NAME} [${BUILD_NUMBER}]', - body: '''The build was successful: - - Job: ${JOB_NAME} - - Build number: ${BUILD_NUMBER} - - Check console output at: ${BUILD_URL}''', - to: 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com', - attachLog: true - ) + mail to: "${EMAIL_RECIPIENTS}", + subject: "⚠️ Build Unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}", + body: """

The build is unstable.

+

Job: ${JOB_NAME}

+

Build Number: ${BUILD_NUMBER}

+

Check the console output at ${BUILD_URL}

""", + mimeType: 'text/html', + attachLog: true } } From 2bb40852b4d7cb21260fd6d513daea0a8c186328 Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:03:44 +0300 Subject: [PATCH 37/60] remove attachLog --- jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 4d31685..0bc41ec 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -126,7 +126,7 @@ pipeline {

Build Number: ${BUILD_NUMBER}

Check the details at ${BUILD_URL}

""", mimeType: 'text/html', - attachLog: true + // attachLog: true } failure { @@ -137,7 +137,7 @@ pipeline {

Build Number: ${BUILD_NUMBER}

Check the console output at ${BUILD_URL}

""", mimeType: 'text/html', - attachLog: true + // attachLog: true } unstable { @@ -148,7 +148,7 @@ pipeline {

Build Number: ${BUILD_NUMBER}

Check the console output at ${BUILD_URL}

""", mimeType: 'text/html', - attachLog: true + // attachLog: true } } From 23d2915509e14773e75d43411a8f5679c1d261ff Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:04:23 +0300 Subject: [PATCH 38/60] tst --- jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 0bc41ec..892c6d8 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -125,7 +125,7 @@ pipeline {

Job: ${JOB_NAME}

Build Number: ${BUILD_NUMBER}

Check the details at ${BUILD_URL}

""", - mimeType: 'text/html', + mimeType: 'text/html' // attachLog: true } @@ -136,7 +136,7 @@ pipeline {

Job: ${JOB_NAME}

Build Number: ${BUILD_NUMBER}

Check the console output at ${BUILD_URL}

""", - mimeType: 'text/html', + mimeType: 'text/html' // attachLog: true } @@ -147,7 +147,7 @@ pipeline {

Job: ${JOB_NAME}

Build Number: ${BUILD_NUMBER}

Check the console output at ${BUILD_URL}

""", - mimeType: 'text/html', + mimeType: 'text/html' // attachLog: true } } From 854d924e90fa1824393f7a0127f5ba039bf0c88d Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:07:35 +0300 Subject: [PATCH 39/60] remove mostafa's email --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 892c6d8..d4c5d73 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -5,7 +5,7 @@ pipeline { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app' DOCKER_IMAGE_TAG = 'latest' - EMAIL_RECIPIENTS = 'mostafa77744333@gmail.com, johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com' + EMAIL_RECIPIENTS = 'johnhana567@gmail.com, khalid.salman1996@gmail.com, andrewadel3322@gmail.com' } stages { From c8e6a29f50054d228d852770616812cfa12ea75c Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:09:11 +0300 Subject: [PATCH 40/60] test_failure --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index d4c5d73..3f55e50 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -58,7 +58,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From d1e6e5433464843b7b87b6918e80ee7bb3d56b70 Mon Sep 17 00:00:00 2001 From: Andrew Adel Date: Wed, 2 Oct 2024 20:12:09 +0300 Subject: [PATCH 41/60] return_the_correct_credential --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 3f55e50..d4c5d73 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -58,7 +58,7 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "$DOCKER_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin + echo "$DOCKER_HUB_CREDENTIALS_PSW" | docker login -u "$DOCKER_HUB_CREDENTIALS_USR" --password-stdin docker-compose push ''' } From cc7ede9824575d4d5d97bd3134c3840ea0b60ac4 Mon Sep 17 00:00:00 2001 From: khalid-salman <71970537+khalid-salman@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:26:04 +0300 Subject: [PATCH 42/60] Update jenkinsfile for testing --- jenkinsfile | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index d4c5d73..01bc688 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -53,6 +53,25 @@ pipeline { } } + stage('Run Tests') { + steps { + script { + sh ''' + cd $WORKSPACE + echo "Installing pytest..." + pip install pytest + + echo "Running tests..." + if [ -f tests/test.py ]; then + pytest tests/test.py --maxfail=1 --disable-warnings + else + echo "No tests found. Skipping." + fi + ''' + } + } + } + stage('Push to Docker-Hub') { steps { script { @@ -220,4 +239,4 @@ pipeline { // body: "Unfortunately, the build has failed.", // to: 'johnhana567@gmail.com' // } - // } \ No newline at end of file + // } From ba9272b5a329054c9610b2619a709940fe78e158 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 20:35:15 +0300 Subject: [PATCH 43/60] updating for testing --- jenkinsfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 01bc688..9136f63 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,5 +1,11 @@ pipeline { - agent any + agent { + docker { + image 'python:3.9-slim' // Use a Python Docker image + args '-u root' // Run as root to allow installations + } +} + environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') From 59d481f01f79847be75254c2522ffd2e81d3a862 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 20:36:37 +0300 Subject: [PATCH 44/60] updating for testing --- jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 9136f63..b44b9b9 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -4,8 +4,7 @@ pipeline { image 'python:3.9-slim' // Use a Python Docker image args '-u root' // Run as root to allow installations } -} - + } environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') From 0457f189dbf08704ddde1fbe847bd203f17111b8 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 20:40:18 +0300 Subject: [PATCH 45/60] updating for testing --- jenkinsfile | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index b44b9b9..5be799f 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -1,10 +1,5 @@ pipeline { - agent { - docker { - image 'python:3.9-slim' // Use a Python Docker image - args '-u root' // Run as root to allow installations - } - } + agent any environment { DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials') @@ -63,20 +58,21 @@ pipeline { script { sh ''' cd $WORKSPACE - echo "Installing pytest..." - pip install pytest - - echo "Running tests..." - if [ -f tests/test.py ]; then - pytest tests/test.py --maxfail=1 --disable-warnings - else - echo "No tests found. Skipping." - fi + echo "Running tests in Docker container..." + + # Run tests in a Python Docker container + docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " + pip install pytest && + if [ -f tests/test.py ]; then + pytest tests/test.py --maxfail=1 --disable-warnings; + else + echo 'No tests found. Skipping.'; + fi + " ''' } } } - stage('Push to Docker-Hub') { steps { script { From dd846dbcaa8cb646d9bfaba6f45ceee00fc01935 Mon Sep 17 00:00:00 2001 From: khalid-salman <71970537+khalid-salman@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:46:14 +0300 Subject: [PATCH 46/60] Update test.py for fail testing --- tests/test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.py b/tests/test.py index 3419901..84fd438 100644 --- a/tests/test.py +++ b/tests/test.py @@ -11,7 +11,7 @@ def test_isupper(self): self.assertFalse('Foo'.isupper()) def test_split(self): - s = 'hello world' + s = 'helloO0 world' self.assertEqual(s.split(), ['hello', 'world']) # check that s.split fails when the separator is not a string with self.assertRaises(TypeError): @@ -19,4 +19,4 @@ def test_split(self): if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() From 75b66e8146c61b0fe5a8a813bfa424e6b2686bcb Mon Sep 17 00:00:00 2001 From: khalid-salman <71970537+khalid-salman@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:55:21 +0300 Subject: [PATCH 47/60] Update jenkinsfile for run test stage --- jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 5be799f..cbe708f 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -63,8 +63,8 @@ pipeline { # Run tests in a Python Docker container docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " pip install pytest && - if [ -f tests/test.py ]; then - pytest tests/test.py --maxfail=1 --disable-warnings; + if [ -f ./tests/test.py ]; then + pytest ./tests/test.py --maxfail=1 --disable-warnings; else echo 'No tests found. Skipping.'; fi From 80c2c77aeb51bce18689964d68f40522ead601bf Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 20:59:57 +0300 Subject: [PATCH 48/60] update run test stage --- jenkinsfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index cbe708f..0a505cc 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -58,13 +58,16 @@ pipeline { script { sh ''' cd $WORKSPACE + echo "Current directory: $(pwd)" + echo "Listing files in the tests directory:" + ls -la tests/ echo "Running tests in Docker container..." # Run tests in a Python Docker container docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " pip install pytest && - if [ -f ./tests/test.py ]; then - pytest ./tests/test.py --maxfail=1 --disable-warnings; + if ls tests/test_*.py; then + pytest tests/test_*.py --maxfail=1 --disable-warnings; else echo 'No tests found. Skipping.'; fi @@ -73,6 +76,8 @@ pipeline { } } } + + stage('Push to Docker-Hub') { steps { script { From 31dc58cc11f2f0f015ad59ad6a07571a02737de2 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 21:10:20 +0300 Subject: [PATCH 49/60] update for testing --- jenkinsfile | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 0a505cc..3c9bcab 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -20,7 +20,30 @@ pipeline { git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' } } + stage('Run Tests') { + steps { + script { + sh ''' + cd $WORKSPACE + echo "Current directory: $(pwd)" + echo "Listing files in the tests directory:" + ls -la tests/ + echo "Running tests in Docker container..." + # Run tests in a Python Docker container + docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " + pip install pytest && + if ls tests/test_*.py; then + pytest tests/test_*.py --maxfail=1 --disable-warnings; + else + echo 'No tests found. Skipping.'; + fi + " + ''' + } + } + } + stage('Prepare Docker Image') { steps { script { @@ -53,31 +76,7 @@ pipeline { } } - stage('Run Tests') { - steps { - script { - sh ''' - cd $WORKSPACE - echo "Current directory: $(pwd)" - echo "Listing files in the tests directory:" - ls -la tests/ - echo "Running tests in Docker container..." - - # Run tests in a Python Docker container - docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " - pip install pytest && - if ls tests/test_*.py; then - pytest tests/test_*.py --maxfail=1 --disable-warnings; - else - echo 'No tests found. Skipping.'; - fi - " - ''' - } - } - } - - + stage('Push to Docker-Hub') { steps { script { From 63498dc33a83d5646558c19fa3ec03298d5d6ea4 Mon Sep 17 00:00:00 2001 From: Khalid Salman Date: Wed, 2 Oct 2024 21:12:18 +0300 Subject: [PATCH 50/60] update for testing task --- jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 3c9bcab..70c6836 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -20,6 +20,7 @@ pipeline { git url: 'https://github.com/johnsamey/DEPI-Project.git', branch: 'master', credentialsId: 'github' } } + stage('Run Tests') { steps { script { @@ -33,8 +34,8 @@ pipeline { # Run tests in a Python Docker container docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " pip install pytest && - if ls tests/test_*.py; then - pytest tests/test_*.py --maxfail=1 --disable-warnings; + if ls tests/test.py; then + pytest tests/test.py --maxfail=1 --disable-warnings; else echo 'No tests found. Skipping.'; fi @@ -43,7 +44,7 @@ pipeline { } } } - + stage('Prepare Docker Image') { steps { script { From cd8b79b4c57e8ef1a84dcf0e5828f818ad0b0b36 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 21:22:03 +0300 Subject: [PATCH 51/60] update jenkinsfile --- jenkinsfile | 73 +++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 70c6836..6b5d6c3 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -94,7 +94,41 @@ pipeline { triggers { pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes } + post { + // success { + // mail to: "${EMAIL_RECIPIENTS}", + // subject: "✅ Build Successful: ${JOB_NAME} - Build #${BUILD_NUMBER}", + // body: """

Good news! The build was successful.

+ //

Job: ${JOB_NAME}

+ //

Build Number: ${BUILD_NUMBER}

+ //

Check the details at ${BUILD_URL}

""", + // mimeType: 'text/html' + // // attachLog: true + // } + failure { + mail to: "${EMAIL_RECIPIENTS}", + subject: "❌ Build Failed: ${JOB_NAME} - Build #${BUILD_NUMBER}", + body: """

Oops! The build has failed.

+

Job: ${JOB_NAME}

+

Build Number: ${BUILD_NUMBER}

+

Check the console output at ${BUILD_URL}

""", + mimeType: 'text/html' + // attachLog: true + } + + unstable { + mail to: "${EMAIL_RECIPIENTS}", + subject: "⚠️ Build Unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}", + body: """

The build is unstable.

+

Job: ${JOB_NAME}

+

Build Number: ${BUILD_NUMBER}

+

Check the console output at ${BUILD_URL}

""", + mimeType: 'text/html' + // attachLog: true + } + } +} // post { // always { // emailext( @@ -142,45 +176,6 @@ pipeline { // } // } - post { - success { - mail to: "${EMAIL_RECIPIENTS}", - subject: "✅ Build Successful: ${JOB_NAME} - Build #${BUILD_NUMBER}", - body: """

Good news! The build was successful.

-

Job: ${JOB_NAME}

-

Build Number: ${BUILD_NUMBER}

-

Check the details at ${BUILD_URL}

""", - mimeType: 'text/html' - // attachLog: true - } - - failure { - mail to: "${EMAIL_RECIPIENTS}", - subject: "❌ Build Failed: ${JOB_NAME} - Build #${BUILD_NUMBER}", - body: """

Oops! The build has failed.

-

Job: ${JOB_NAME}

-

Build Number: ${BUILD_NUMBER}

-

Check the console output at ${BUILD_URL}

""", - mimeType: 'text/html' - // attachLog: true - } - - unstable { - mail to: "${EMAIL_RECIPIENTS}", - subject: "⚠️ Build Unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}", - body: """

The build is unstable.

-

Job: ${JOB_NAME}

-

Build Number: ${BUILD_NUMBER}

-

Check the console output at ${BUILD_URL}

""", - mimeType: 'text/html' - // attachLog: true - } - } - - - -} - // post { // failure { From 0bf66a4238e032a49b4a35bc1958a2918ab3d7b8 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Wed, 2 Oct 2024 21:28:54 +0300 Subject: [PATCH 52/60] update jenkinsfile --- jenkinsfile | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 6b5d6c3..b5e5828 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -21,30 +21,39 @@ pipeline { } } + // stage('Run Tests') { + // steps { + // script { + // sh ''' + // cd $WORKSPACE + // echo "Current directory: $(pwd)" + // echo "Listing files in the tests directory:" + // ls -la tests/ + // echo "Running tests in Docker container..." + + // # Run tests in a Python Docker container + // docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " + // pip install pytest && + // if ls tests/test.py; then + // pytest tests/test.py --maxfail=1 --disable-warnings; + // else + // echo 'No tests found. Skipping.'; + // fi + // " + // ''' + // } + // } + // } stage('Run Tests') { steps { script { sh ''' cd $WORKSPACE - echo "Current directory: $(pwd)" - echo "Listing files in the tests directory:" - ls -la tests/ - echo "Running tests in Docker container..." - - # Run tests in a Python Docker container - docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " - pip install pytest && - if ls tests/test.py; then - pytest tests/test.py --maxfail=1 --disable-warnings; - else - echo 'No tests found. Skipping.'; - fi - " + docker-compose run --rm app python -m unittest discover ''' } } } - stage('Prepare Docker Image') { steps { script { From 650083d91ff5d284289c2e1beb8db05984f0a002 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Thu, 3 Oct 2024 05:26:57 +0300 Subject: [PATCH 53/60] update .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 75ec3f0..54f6b99 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.vscode/* \ No newline at end of file +.vscode/* +terraform/ \ No newline at end of file From 07d78de8579d1248a2a033cd8833bc0370b69a73 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Thu, 3 Oct 2024 05:47:31 +0300 Subject: [PATCH 54/60] update jenkinsfile --- jenkinsfile | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index b5e5828..d23c766 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -44,16 +44,6 @@ pipeline { // } // } // } - stage('Run Tests') { - steps { - script { - sh ''' - cd $WORKSPACE - docker-compose run --rm app python -m unittest discover - ''' - } - } - } stage('Prepare Docker Image') { steps { script { From db067775b82309269b1877a277babeb7f536c2cd Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 03:07:05 +0300 Subject: [PATCH 55/60] Add testing stage --- jenkinsfile | 33 +++++++++------------------------ 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index d23c766..5a204ec 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -21,29 +21,6 @@ pipeline { } } - // stage('Run Tests') { - // steps { - // script { - // sh ''' - // cd $WORKSPACE - // echo "Current directory: $(pwd)" - // echo "Listing files in the tests directory:" - // ls -la tests/ - // echo "Running tests in Docker container..." - - // # Run tests in a Python Docker container - // docker run --rm -v $WORKSPACE:/app -w /app python:3.9-slim bash -c " - // pip install pytest && - // if ls tests/test.py; then - // pytest tests/test.py --maxfail=1 --disable-warnings; - // else - // echo 'No tests found. Skipping.'; - // fi - // " - // ''' - // } - // } - // } stage('Prepare Docker Image') { steps { script { @@ -76,7 +53,15 @@ pipeline { } } - + stage('Run Tests') { + steps { + sh 'echo "Running tests..."' + sh 'cd counting_App && docker-compose up -d --build my_app ' + sh 'cd counting_App && docker exec my_app_container python -m unittest test_hello.py' + sh 'cd counting_App && docker-compose down' + } + } + stage('Push to Docker-Hub') { steps { script { From e404f5b071c41181eb43b2a1e7d771dd18891f46 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 03:10:51 +0300 Subject: [PATCH 56/60] Updated docker-compose.yml to match master --- docker-compose.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index a20127e..6ddd81b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,12 +13,14 @@ services: - REDIS_PORT=6379 - REDIS_DB=0 ports: - - "8010:8000" + - "8000:8000" depends_on: - redis command: python hello.py + container_name: app-container image: johnsami/dockerized-app-build-app:latest redis: image: "redis:6.0-alpine" ports: - "6379:6379" + container_name: redis-container \ No newline at end of file From c7e24fe24df7274f029b140b2bf8bb9a35170a03 Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 04:17:25 +0300 Subject: [PATCH 57/60] Add testing stage --- jenkinsfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 5a204ec..0d731b9 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -56,9 +56,6 @@ pipeline { stage('Run Tests') { steps { sh 'echo "Running tests..."' - sh 'cd counting_App && docker-compose up -d --build my_app ' - sh 'cd counting_App && docker exec my_app_container python -m unittest test_hello.py' - sh 'cd counting_App && docker-compose down' } } From 23feaec42bf288a8f58bb1e2e257a8471fd12c9b Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 04:18:02 +0300 Subject: [PATCH 58/60] Add testing stage --- jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jenkinsfile b/jenkinsfile index 0d731b9..bdc10ca 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -72,9 +72,9 @@ pipeline { } } - triggers { - pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes - } + // triggers { + // pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes + // } post { // success { // mail to: "${EMAIL_RECIPIENTS}", From 7270aaaeb3223fa7669fd60bf6e7dd6f6a48813e Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 14:57:51 +0300 Subject: [PATCH 59/60] add terraform --- terraform/auto_var.auto.tfvars | 10 +++ terraform/main.tf | 16 ++++ terraform/modules/ec2/main.tf | 96 +++++++++++++++++++++++ terraform/modules/ec2/outputs.tf | 13 +++ terraform/modules/ec2/public_user_data.sh | 15 ++++ terraform/modules/ec2/variables.tf | 48 ++++++++++++ terraform/modules/vpc/main.tf | 60 ++++++++++++++ terraform/modules/vpc/outputs.tf | 8 ++ terraform/modules/vpc/variables.tf | 23 ++++++ terraform/outputs.tf | 0 terraform/providers.tf | 18 +++++ terraform/variables.tf | 40 ++++++++++ 12 files changed, 347 insertions(+) create mode 100644 terraform/auto_var.auto.tfvars create mode 100644 terraform/main.tf create mode 100644 terraform/modules/ec2/main.tf create mode 100644 terraform/modules/ec2/outputs.tf create mode 100644 terraform/modules/ec2/public_user_data.sh create mode 100644 terraform/modules/ec2/variables.tf create mode 100644 terraform/modules/vpc/main.tf create mode 100644 terraform/modules/vpc/outputs.tf create mode 100644 terraform/modules/vpc/variables.tf create mode 100644 terraform/outputs.tf create mode 100644 terraform/providers.tf create mode 100644 terraform/variables.tf diff --git a/terraform/auto_var.auto.tfvars b/terraform/auto_var.auto.tfvars new file mode 100644 index 0000000..e3ffdf6 --- /dev/null +++ b/terraform/auto_var.auto.tfvars @@ -0,0 +1,10 @@ + # vpc + vpc_Name = "test-vpc" + vpc_cidr_block = "10.0.0.0/16" + public_subnets_cidr = ["10.0.1.0/24","10.0.2.0/24"] + availability_Zones_subnet = ["us-east-1a","us-east-1b"] # us-east-1a +#ec2 + ec2_Name = ["Docker","Jenkins"] + ami_id = "ami-0e86e20dae9224db8" # ami-0e86e20dae9224db8 + key_Name = "private_key" + instance_type = "t2.micro" # t2.micro \ No newline at end of file diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..79067d0 --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,16 @@ +module "vpc" { + source = "./modules/vpc" + vpc_Name = var.vpc_Name + vpc_cidr_block = var.vpc_cidr_block + public_subnets_cidr = var.public_subnets_cidr + availability_Zones_subnet = var.availability_Zones_subnet +} +module "ec2" { + source = "./modules/ec2" + ec2_Name = var.ec2_Name + vpc_id = module.vpc.vpc_id + public_subnet_ids = module.vpc.public_subnet_ids + ami_id = var.ami_id + key_Name = var.key_Name + instance_type = var.instance_type +} \ No newline at end of file diff --git a/terraform/modules/ec2/main.tf b/terraform/modules/ec2/main.tf new file mode 100644 index 0000000..5a7d47c --- /dev/null +++ b/terraform/modules/ec2/main.tf @@ -0,0 +1,96 @@ + + +resource "aws_instance" "public_ec2"{ + count =length(var.public_subnet_ids) + ami = var.ami_id + instance_type = var.instance_type + subnet_id = var.public_subnet_ids[count.index] + vpc_security_group_ids = [aws_security_group.public_security-group.id] + key_name = aws_key_pair.kp.key_name #key pair attach + associate_public_ip_address = "true" + user_data =file("./modules/ec2/public_user_data.sh") + tags = { + Name = "${var.ec2_Name[count.index]}", + created-by="john" + } + provisioner "local-exec" { + command = <> inventory.ini + elif [ "$instance_name" = "Jenkins" ]; then + echo "[Jenkins]\n$instance_ip" >> inventory.ini + fi + EOT + } +} + + + + +resource "aws_security_group" "public_security-group" { + name = "public-security-group" + vpc_id = var.vpc_id + + ingress { + from_port = var.ssh_port + to_port = var.ssh_port + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + + ingress { + from_port = var.HTTP_port + to_port = var.HTTP_port + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + from_port = var.jenkins_port + to_port = var.jenkins_port + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + + +# Generate a new RSA private key with a key size of 4096 bits +resource "tls_private_key" "pk" { + algorithm = "RSA" + rsa_bits = 4096 +} +# Create an AWS key pair using the generated public key +resource "aws_key_pair" "kp" { + key_name = var.key_Name # Create "myKey" to AWS!! + public_key = tls_private_key.pk.public_key_openssh + + # Use a local-exec provisioner to save the private key to a file on the local machine +# provisioner "local-exec" { +# command = < ./${var.key_Name}.pem +# chmod 400 ./${var.key_Name}.pem +# EOT +# } + +} + +# Save the private key to a file locally (will be destroyed with the key_pair resource) +resource "local_file" "private_key" { + content = tls_private_key.pk.private_key_pem + filename = "${path.cwd}/${var.key_Name}.pem" + provisioner "local-exec" { + command = < 0 ? 1 : 0 + vpc_id = aws_vpc.aws_vpc.id + + tags = { + Name = "igw-${var.vpc_Name}" + created-by="john" + } + +} + +# Create a route table for public subnets +resource "aws_route_table" "public_route_table" { + count = length(var.public_subnets_cidr) > 0 ? 1 : 0 #use to prevent creation of rw if not public subnet entered + vpc_id = aws_vpc.aws_vpc.id + + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.internet_gateway[0].id + } + + tags = { + Name = "route_table_${var.vpc_Name}" + created-by="john" + } +} + + + +# Associate public subnets with the public route table +resource "aws_route_table_association" "public_association" { + count = length(var.public_subnets_cidr) + subnet_id = aws_subnet.public_subnet[count.index].id + route_table_id = aws_route_table.public_route_table[0].id + +} diff --git a/terraform/modules/vpc/outputs.tf b/terraform/modules/vpc/outputs.tf new file mode 100644 index 0000000..815e887 --- /dev/null +++ b/terraform/modules/vpc/outputs.tf @@ -0,0 +1,8 @@ + +output "vpc_id" { + value = aws_vpc.aws_vpc.id +} +output "public_subnet_ids" { + description = "List with IDs of the public subnets" + value = aws_subnet.public_subnet.*.id +} diff --git a/terraform/modules/vpc/variables.tf b/terraform/modules/vpc/variables.tf new file mode 100644 index 0000000..3b06add --- /dev/null +++ b/terraform/modules/vpc/variables.tf @@ -0,0 +1,23 @@ +variable "vpc_cidr_block" { + description = "this is cidr block of created vpc " + type = string + +} + +variable "public_subnets_cidr" { + description = "cider blocks for public subnets" + type = list(string) +} + +variable "vpc_Name" { + description = "this name vpc " + type = string +} + + +variable "availability_Zones_subnet" { + description = "Availability Zones subnet for each subnet" + type = list(string) +} + + diff --git a/terraform/outputs.tf b/terraform/outputs.tf new file mode 100644 index 0000000..e69de29 diff --git a/terraform/providers.tf b/terraform/providers.tf new file mode 100644 index 0000000..44cc68e --- /dev/null +++ b/terraform/providers.tf @@ -0,0 +1,18 @@ +terraform { + + required_providers { + aws = { + + source = "hashicorp/aws" + version = "~> 5.0.0" + } + } + +} + +provider "aws" { + shared_config_files = [ "~/.aws/config" ] + shared_credentials_files = [ "~/.aws/credentials" ] + profile = "default" + region = "us-east-1" +} diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..7fbce37 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,40 @@ +variable "vpc_Name" { + description = "Name of the VPC." + type = string +} + +variable "vpc_cidr_block" { + description = "CIDR block for the VPC." + type = string +} + +variable "public_subnets_cidr" { + description = "List of CIDR blocks for public subnets." + type = list(string) +} + +variable "availability_Zones_subnet" { + description = "List of Availability Zones for subnets." + type = list(string) +} + +variable "ec2_Name" { + description = "Name of the EC2 instance." + type = list(string) +} + +variable "ami_id" { + description = "AMI ID for the EC2 instance." + type = string +} + +variable "instance_type" { + description = "Type of EC2 instance." + type = string +} + +variable "key_Name" { + description = "SSH key pair name for instance access." + type = string +} + From b38b6a148d576ebfff2325d8312ecba0d969824f Mon Sep 17 00:00:00 2001 From: johnsamey Date: Sun, 6 Oct 2024 15:02:39 +0300 Subject: [PATCH 60/60] Update --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 54f6b99..c8618e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ .vscode/* -terraform/ \ No newline at end of file +# terraform/ +terraform/.terraform +terraform/.terraform.lock.hcl +terraform/terraform.tfstate +terraform/terraform.tfstate.backup