-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
79 lines (70 loc) · 2.26 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
pipeline {
agent any
environment {
AWS_ECR_URI = "642881291524.dkr.ecr.us-east-1.amazonaws.com/capstone"
CAPSTONE_ML_APP = "capstone-ml-app"
VERSION = "${env.BRANCH_NAME}.${BUILD_NUMBER}"
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Install Dependencies') {
steps {
echo 'Installing application dependencies'
withPythonEnv('python3') {
sh 'pip3 install -r ./app/requirements.txt'
}
}
}
stage('Linitng') {
steps {
echo 'Performing liniting checks.'
withPythonEnv('python3') {
sh 'pylint ./app/app.py'
}
sh 'hadolint Dockerfile'
}
}
stage('Image Build') {
steps {
echo 'Image Build'
sh "docker build --tag ${CAPSTONE_ML_APP}:${VERSION} ."
sh 'docker images'
}
}
stage('Deploy to ECR') {
when {
anyOf { branch 'master'; branch 'develop' }
}
steps {
echo 'Deploying application image to AWS ECR.'
sh '$(aws ecr get-login --region us-east-1 --no-include-email)'
sh "docker tag ${CAPSTONE_ML_APP} ${AWS_ECR_URI}:${VERSION}"
sh "docker push ${AWS_ECR_URI}"
}
}
stage('Deploy ECR Image to AWS EKS Cluster') {
when {
anyOf { branch 'master'; branch 'develop' }
}
steps {
echo 'Deploying application to AWS EKS Cluster'
sh "kubectl set image deployment/ml-app ml-app=${AWS_ECR_URI}:${VERSION}"
sh 'kubectl get pods'
}
}
}
post {
success {
echo 'Build successful. Cleaning workspace and docker images'
sh "docker image rm ${AWS_ECR_URI}:${VERSION}"
}
failure {
echo 'Pipeline failed. Cleaning workspace and docker images'
sh "docker image rm ${AWS_ECR_URI}:${VERSION}"
}
}
}