-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
60 lines (60 loc) · 3.04 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
pipeline {
agent any
stages {
stage('Checkout Github Repo') {
steps {
git url: 'https://github.com/m3talliz3d/Sprints_Capstone-Final-Project.git', branch: 'main' , credentialsId: 'github_pipeline_id'
}
}
stage('Build and push Flask app') {
steps{
withCredentials([string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'), string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID')]) {
script {
sh '''
pwd
cd $PWD/docker/FlaskApp/
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 476713460067.dkr.ecr.us-east-1.amazonaws.com
docker build -t ecr_repo:flask .
docker tag ecr_repo:flask 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:flask
docker push 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:flask
echo "Docker Cleaning up 🗑️"
docker rmi 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:flask
'''
}
}
}
}
stage('Build and push MySQL app') {
steps{
withCredentials([string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'), string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID')]) {
script {
sh '''
pwd
cd $PWD/docker/db/
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 476713460067.dkr.ecr.us-east-1.amazonaws.com
docker build -t ecr_repo:sql .
docker tag ecr_repo:sql 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:sql
docker push 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:sql
echo "Docker Cleaning up 🗑️"
docker rmi 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:sql
'''
}
}
}
}
stage('K8s Deployment ') {
steps{
withCredentials([string(credentialsId: 'AWS_SECRET_ACCESS_KEY', variable: 'AWS_SECRET_ACCESS_KEY'), string(credentialsId: 'AWS_ACCESS_KEY_ID', variable: 'AWS_ACCESS_KEY_ID')]) {
script {
sh '''
sed -i \"s|image:.*|image: 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:flask |g\" `pwd`/kube/pod_dep_flask.yaml
sed -i \"s|image:.*|image: 476713460067.dkr.ecr.us-east-1.amazonaws.com/ecr_repo:sql |g\" `pwd`/kube/pod_stateful_db.yml
aws eks --region us-east-1 update-kubeconfig --name sprint_eks_cluster
kubectl apply -f $PWD/kube
'''
}
}
}
}
}
}