-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
107 lines (95 loc) · 2.74 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
pipeline {
environment{
registryCredential = 'docker-hub'
greenDockerImage = ''
blueDockerImage = ''
}
agent any
stages {
stage('Install Requirements'){
steps{
sh "pip3 install -r requirements.txt"
}
}
stage('Lint Code'){
steps {us-east-2
sh "bash ./run_pylint.sh"
}
}
stage('Set K8S Context'){
steps {
withAWS(credentials:'aws-credentials'){
sh "kubectl config set-context arn:aws:eks:us-east-2:526037358249:cluster/production"
}
}
}
stage('Build Green Docker Image') {
steps {
script{
greenDockerImage = docker.build "desjenkins/pre-production-flask-app"
}
}
}
stage('Upload Green Image to Docker-Hub'){
steps{
script{
docker.withRegistry('', registryCredential){
greenDockerImage.push()
}
}
}
}
stage('Clean Up Green Image'){
steps {
sh "docker rmi desjenkins/pre-production-flask-app:latest"
}
}
stage('Green Deployment'){
steps {
withAWS(credentials:'aws-credentials'){
sh "kubectl apply -f k8s/Green/green-deployment.yaml && kubectl apply -f k8s/Green/test-service.yaml"
}
}
}
stage('Test Green Deployment'){
steps{
input "Deploy to production?"
}
}
stage('Switch Traffic To Green Deployment'){
steps{
withAWS(credentials:'aws-credentials'){
sh "kubectl apply -f k8s/Green/green-service.yaml"
}
}
}
stage('Build Blue Docker Image') {
steps {
script{
blueDockerImage = docker.build "desjenkins/flask-app"
}
}
}
stage('Upload Blue Image to Docker-Hub'){
steps{
script{
docker.withRegistry('', registryCredential){
blueDockerImage.push()
}
}
}
}
stage('Clean Up Blue Image'){
steps {
sh "docker rmi desjenkins/flask-app:latest"
}
}
stage('Blue Deployment'){
steps {
withAWS(credentials:'aws-credentials'){
sh "kubectl apply -f k8s/Blue"
}
}
}
}
}