-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
54 lines (51 loc) · 1.35 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
pipeline {
agent any
stages {
stage('Install Requirements') {
steps {
sh '''#!/bin/bash
python -m pip install -r python/requirements.txt --user'''
}
}
stage('Test') {
steps {
sh '''cd python
make test'''
}
}
stage('Build Docker') {
steps {
sh 'ansible-playbook ansible/build_docker.yml'
}
}
stage('Push Docker') {
steps {
sh 'ansible-playbook ansible/push_docker.yml -vvv'
}
}
stage('Deploy to EKS') {
steps {
sh '''kubectl apply -f ~/.kube/config_map_aws_auth.yml
if kubectl get deployment books; then
echo 'deployment exists, start rolling update'
while read line; do kubectl set image deployment/books tirganbooks=$line; done < /tmp/BOOKS_DOCKER_URI
else
echo 'creating deployment'
while read line; do kubectl create deployment books --image=$line; done < /tmp/BOOKS_DOCKER_URI
fi
if kubectl get service books; then
echo 'service already exists'
else
echo 'creating service'
kubectl expose deployment books --type=LoadBalancer --port 8080 --target-port 8080
fi
kubectl scale deployment/books --replicas=10'''
}
}
}
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins-aws-secret-key-id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-secret-access-key')
AWS_DEFAULT_REGION = 'us-west-2'
}
}