Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b9683c6
add docker file
johnsamey Sep 29, 2024
a5c7552
Project Documentation
johnsamey Sep 29, 2024
7af7ab0
update docker-compose file
johnsamey Oct 1, 2024
7b432bb
update dockerfile
johnsamey Oct 1, 2024
8ee7237
update docker-compose file
johnsamey Oct 1, 2024
d44074e
Update plan.md
MainUseless Oct 1, 2024
dbc60cf
Add Jenkinsfile
khalid-salman Oct 1, 2024
e02eaa5
Add Jenkinsfile
khalid-salman Oct 1, 2024
1f250e0
Add Jenkinsfile
khalid-salman Oct 1, 2024
e133c2b
Add Jenkinsfile
khalid-salman Oct 1, 2024
6acc2c7
Add Jenkinsfile
khalid-salman Oct 1, 2024
a96162d
Add Jenkinsfile
khalid-salman Oct 1, 2024
c9b4b84
Add Jenkinsfile
khalid-salman Oct 1, 2024
4d975a4
update jenkinsfile
johnsamey Oct 1, 2024
7ebb7e6
add email notification to the pipeline
johnsamey Oct 1, 2024
d939c1c
test failure jenkinsfile
johnsamey Oct 1, 2024
26b3f8a
test failure jenkinsfile
johnsamey Oct 1, 2024
f53c39d
test failure jenkinsfile
johnsamey Oct 1, 2024
61e7f1f
update
johnsamey Oct 1, 2024
a570206
modify jenkinsfile
johnsamey Oct 2, 2024
553af29
modify jenkinsfile
johnsamey Oct 2, 2024
6c9bf70
modify jenkinsfile
johnsamey Oct 2, 2024
27e455b
modify jenkinsfile
johnsamey Oct 2, 2024
4eff53c
modify jenkinsfile
johnsamey Oct 2, 2024
6b27345
update jenkinsfile
johnsamey Oct 2, 2024
11a58ea
update jenkinsfile
johnsamey Oct 2, 2024
eefdddf
update jenkinsfile
johnsamey Oct 2, 2024
2c36fc6
update jenkinsfile
johnsamey Oct 2, 2024
b3f5378
add always test email
Andrew-Adel Oct 2, 2024
e47cda8
add subject for email
Andrew-Adel Oct 2, 2024
95f2a73
Updated Jenkinsfile for testing
khalid-salman Oct 2, 2024
d5a1d4c
return to the LTS
Andrew-Adel Oct 2, 2024
4d4c2b1
return to the LTS
Andrew-Adel Oct 2, 2024
31f7762
remove second always
Andrew-Adel Oct 2, 2024
8fb9347
add rest of email to mail
Andrew-Adel Oct 2, 2024
dbb5d62
use mail instead of emailext
Andrew-Adel Oct 2, 2024
2bb4085
remove attachLog
Andrew-Adel Oct 2, 2024
23d2915
tst
Andrew-Adel Oct 2, 2024
854d924
remove mostafa's email
Andrew-Adel Oct 2, 2024
c8e6a29
test_failure
Andrew-Adel Oct 2, 2024
d1e6e54
return_the_correct_credential
Andrew-Adel Oct 2, 2024
cc7ede9
Update jenkinsfile for testing
khalid-salman Oct 2, 2024
ba9272b
updating for testing
khalid-salman Oct 2, 2024
59d481f
updating for testing
khalid-salman Oct 2, 2024
0457f18
updating for testing
khalid-salman Oct 2, 2024
dd846db
Update test.py for fail testing
khalid-salman Oct 2, 2024
75b66e8
Update jenkinsfile for run test stage
khalid-salman Oct 2, 2024
80c2c77
update run test stage
khalid-salman Oct 2, 2024
31dc58c
update for testing
khalid-salman Oct 2, 2024
63498dc
update for testing task
khalid-salman Oct 2, 2024
cd8b79b
update jenkinsfile
johnsamey Oct 2, 2024
0bf66a4
update jenkinsfile
johnsamey Oct 2, 2024
650083d
update .gitignore
johnsamey Oct 3, 2024
07d78de
update jenkinsfile
johnsamey Oct 3, 2024
db06777
Add testing stage
johnsamey Oct 6, 2024
e404f5b
Updated docker-compose.yml to match master
johnsamey Oct 6, 2024
c7e24fe
Add testing stage
johnsamey Oct 6, 2024
23feaec
Add testing stage
johnsamey Oct 6, 2024
7270aaa
add terraform
johnsamey Oct 6, 2024
b38b6a1
Update
johnsamey Oct 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.vscode/*
.vscode/*
# terraform/
terraform/.terraform
terraform/.terraform.lock.hcl
terraform/terraform.tfstate
terraform/terraform.tfstate.backup
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.9-slim

ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE ${PORT}

CMD ["python", "hello.py"]
Binary file added Project DevOps DEPI.docx
Binary file not shown.
26 changes: 26 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
container_name: app-container
image: johnsami/dockerized-app-build-app:latest
redis:
image: "redis:6.0-alpine"
ports:
- "6379:6379"
container_name: redis-container
224 changes: 224 additions & 0 deletions jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
pipeline {
agent any

environment {
DOCKER_HUB_CREDENTIALS = credentials('docker-Hub-credentials')
DOCKER_IMAGE_NAME = 'johnsami/dockerized-app-build-app'
DOCKER_IMAGE_TAG = 'latest'
EMAIL_RECIPIENTS = '[email protected], [email protected], [email protected]'
}

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 $DOCKER_IMAGE_NAME $DOCKER_IMAGE_NAME:$DOCKER_IMAGE_TAG
'''
}
}
}

stage('Run Tests') {
steps {
sh 'echo "Running tests..."'
}
}

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
'''
}
}
}
}

// triggers {
// pollSCM('H/5 * * * *') // Poll GitHub every 5 minutes
// }
post {
// success {
// mail to: "${EMAIL_RECIPIENTS}",
// subject: "✅ Build Successful: ${JOB_NAME} - Build #${BUILD_NUMBER}",
// body: """<p>Good news! The build was successful.</p>
// <p><strong>Job:</strong> ${JOB_NAME}</p>
// <p><strong>Build Number:</strong> ${BUILD_NUMBER}</p>
// <p>Check the details at <a href="${BUILD_URL}">${BUILD_URL}</a></p>""",
// mimeType: 'text/html'
// // attachLog: true
// }

failure {
mail to: "${EMAIL_RECIPIENTS}",
subject: "❌ Build Failed: ${JOB_NAME} - Build #${BUILD_NUMBER}",
body: """<p>Oops! The build has failed.</p>
<p><strong>Job:</strong> ${JOB_NAME}</p>
<p><strong>Build Number:</strong> ${BUILD_NUMBER}</p>
<p>Check the console output at <a href="${BUILD_URL}">${BUILD_URL}</a></p>""",
mimeType: 'text/html'
// attachLog: true
}

unstable {
mail to: "${EMAIL_RECIPIENTS}",
subject: "⚠️ Build Unstable: ${JOB_NAME} - Build #${BUILD_NUMBER}",
body: """<p>The build is unstable.</p>
<p><strong>Job:</strong> ${JOB_NAME}</p>
<p><strong>Build Number:</strong> ${BUILD_NUMBER}</p>
<p>Check the console output at <a href="${BUILD_URL}">${BUILD_URL}</a></p>""",
mimeType: 'text/html'
// attachLog: true
}
}
}
// post {
// always {
// emailext(
// to: '[email protected], [email protected], [email protected], [email protected]',
// subject: 'Test Email from Jenkins',
// body: 'This is a test email to verify Jenkins email notifications.',
// attachLog: false
// )

// mail to: '[email protected], [email protected], [email protected], [email protected]',
// subject: 'Test Email from Jenkins',
// body: 'This is a test email to verify Jenkins email notifications.'
// }

// failure {
// emailext(
// to: '[email protected], [email protected], [email protected], [email protected]',
// subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}',
// body: """<p>Build failed in Jenkins:</p>
// <p>Job: ${JOB_NAME} - Build #${BUILD_NUMBER}</p>
// <p>Check console output at <a href="${BUILD_URL}">${BUILD_URL}</a></p>""",
// attachLog: true
// )
// }
// unstable {
// emailext(
// to: '[email protected], [email protected], [email protected], [email protected]',
// subject: 'Build failed in Jenkins: ${JOB_NAME} - Build #${BUILD_NUMBER}',
// body: """<p>Build is unstable:</p>
// <p>Job: ${JOB_NAME} - Build #${BUILD_NUMBER}</p>
// <p>Check console output at <a href="${BUILD_URL}">${BUILD_URL}</a></p>""",
// 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: '[email protected], [email protected], [email protected], [email protected]',
// attachLog: true
// )
// }
// }


// 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: '[email protected], [email protected], [email protected], [email protected]',
// 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: '[email protected], [email protected], [email protected], [email protected]',
// 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: '[email protected], [email protected], [email protected], [email protected]',
// attachLog: true
// )
// }
// }



// 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: '[email protected]'
// }
// }
// success {
// emailext subject: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
// body: "Good news, the build was successful!",
// to: '[email protected]'
// }
// failure {
// emailext subject: "FAILURE: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
// body: "Unfortunately, the build has failed.",
// to: '[email protected]'
// }
// }
6 changes: 6 additions & 0 deletions plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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
4. testing jenkins auto build
10 changes: 10 additions & 0 deletions terraform/auto_var.auto.tfvars
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
Loading