-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
89 lines (80 loc) · 2.25 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
pipeline {
agent any
stages {
stage('Lint HTML') {
steps {
sh 'tidy -q -e *.html'
}
}
stage('Build Docker Image') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]){
sh '''
docker build -t $DOCKER_USERNAME/capstone .
'''
}
}
}
stage('Push Image To Dockerhub') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]){
sh '''
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push $DOCKER_USERNAME/capstone
'''
}
}
}
stage('Create cluster') {
steps {
withAWS(credentials: 'aws-static', region: 'us-west-2') {
sh "eksctl create cluster --name capstonecluster --version 1.16 --region us-west-2 --without-nodegroup"
}
}
}
stage('Create node group') {
steps {
withAWS(credentials: 'aws-static', region: 'us-west-2') {
sh "eksctl create nodegroup --cluster capstonecluster --version auto --name standard-workers --node-type t3.micro --node-ami auto --nodes 3 --nodes-min 1 --nodes-max 4 --region us-west-2 --ssh-public-key udacity-oregon-course"
}
}
}
stage('Configuring') {
steps {
withAWS(credentials: 'aws-static', region: 'us-west-2') {
sh '''
aws eks --region us-west-2 update-kubeconfig --name capstonecluster
chmod +x aws/replaceARNrole.sh
./aws/replaceARNrole.sh
cat aws/aws-auth-cm.yaml
'''
}
}
}
stage('Deploying') {
steps {
withAWS(credentials: 'aws-static', region: 'us-west-2') {
sh '''
kubectl get nodes
kubectl apply -f aws/aws-auth-cm.yaml
kubectl apply -f aws/capstone-app-deployment.yml
kubectl apply -f aws/load-balancer.yml
kubectl get pods
kubectl get svc
'''
}
}
}
stage('Getting nodes,pods,services') {
steps {
withAWS(credentials: 'aws-static', region: 'us-west-2') {
sh '''
kubectl get nodes
kubectl get pods
kubectl get svc
'''
}
}
}
}
}