-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
72 lines (56 loc) · 2.59 KB
/
Jenkinsfile
File metadata and controls
72 lines (56 loc) · 2.59 KB
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
pipeline {
agent any
environment {
def commitId = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
def gitCommitId = commitId.take(8)
}
stages {
stage('Git Pull Repo') {
steps {
withCredentials([gitUsernamePassword(credentialsId: 'gitaccess', gitToolName: 'git')]) {
sh ''' #!/bin/sh
ssh root@172.31.19.60 "cd /root/DevAssist && git pull origin main"
'''
}
}
}
stage('docker build image') {
steps {
sh ''' #!/bin/sh
## ssh root@172.31.19.60 "docker-compose -f /root/DevAssist-main/docker-compose.yml build"
## ssh root@172.31.19.60 "docker tag 316211033416.dkr.ecr.ap-south-1.amazonaws.com/streamlit:latest 316211033416.dkr.ecr.ap-south-1.amazonaws.com/streamlit:${gitCommitId}"
ssh root@172.31.19.60 "cd /root/DevAssist && docker build -t 316211033416.dkr.ecr.ap-south-1.amazonaws.com/streamlit:${gitCommitId} ." '''
}
}
stage('Push docker image') {
steps {
sh ''' #!/bin/sh
ssh root@172.31.19.60 "aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 316211033416.dkr.ecr.ap-south-1.amazonaws.com"
ssh root@172.31.19.60 "docker push 316211033416.dkr.ecr.ap-south-1.amazonaws.com/streamlit:${gitCommitId}"
'''
}
}
stage('New Task Revision') {
steps {
sh ''' #!/bin/sh
aws ecs register-task-definition \
--family fa-testdatasights2 \
--container-definitions '[{"name": "fa-testdatasights2", "image": "316211033416.dkr.ecr.ap-south-1.amazonaws.com/streamlit:'${gitCommitId}'",
"portMappings": [ {"containerPort": 8501, "hostPort": 8501, "protocol": "tcp"} ]}]' \
--requires-compatibilities FARGATE \
--network-mode awsvpc \
--cpu 1024 --memory 3072 \
--task-role-arn arn:aws:iam::316211033416:role/ecsTaskExecutionRole \
--execution-role-arn arn:aws:iam::316211033416:role/ecsTaskExecutionRole
'''
}
}
stage('Update Cluster Service') {
steps {
sh ''' #!/bin/sh
aws ecs update-service --cluster fa-testdatasights --service DatawebApp2 --region ap-south-1 --task-definition fa-testdatasights2 --desired-count 1 --force-new-deployment
'''
}
}
}
}