forked from mudathirlawal/cicd-with-jenkins-docker-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
55 lines (54 loc) · 2.39 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
pipeline {
agent any
stages {
stage('Clone git repo') {
steps {
sh 'echo "STAGE 0: Cloning app code from SCM ..."'
git 'https://github.com/mudathirlawal/cicd-with-jenkins-docker-and-aws-eks.git'
}
}
stage('Lint all app code') {
steps {
sh 'echo "STAGE 1: Checking app code for syntax error ..."'
sh 'tidy -q -e *.html'
}
}
stage( 'Build docker image for app' ) {
steps {
sh 'echo "STAGE 2: Building and tagging docker image ..."'
sh 'docker build -t web-app:v1.0 .'
sh 'docker image ls'
}
}
stage( 'Push image to dockerhub repo' ) {
steps {
withDockerRegistry([url: "", credentialsId: "dockerhub"]) {
sh 'echo "STAGE 3: Uploading image to dockerhub repository ..."'
sh 'docker login'
sh 'docker tag web-app:v1.0 nigercode/web-app:v1.0'
sh 'docker push nigercode/web-app:v1.0'
}
}
}
stage( 'Deploy image to AWS EKS' ) {
steps {
withAWS( region:'us-west-2', credentials:'capstone' ) {
sh 'echo "STAGE 4: Deploying image to AWS EKS cluster ..."'
sh 'aws eks --region us-west-2 update-kubeconfig --name capstone'
sh 'kubectl config use-context arn:aws:eks:us-west-2:428819381342:cluster/capstone'
sh 'kubectl set image deployment web-app web-app=nigercode/web-app:v1.0'
sh 'kubectl rollout status deployment web-app'
sh 'kubectl apply -f templates/deployment.yml'
sh 'kubectl apply -f templates/loadbalancer.yml'
sh 'kubectl apply -f templates/aws-auth-cm.yml'
sh 'kubectl get nodes --all-namespaces'
sh 'kubectl get deployment'
sh 'kubectl get pod -o wide'
sh 'kubectl get service/web-app'
sh 'echo "Congratulations! Deployment successful."'
sh 'kubectl describe deployment/web-app'
}
}
}
}
}