-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.groovy
More file actions
27 lines (24 loc) · 959 Bytes
/
script.groovy
File metadata and controls
27 lines (24 loc) · 959 Bytes
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
def testApp() {
echo 'testing the application...'
sh 'mvn test'
}
def deployApp(Map dockerImage, String ipAddress) {
echo 'deploying the application...'
def dockerComposeCmd = "IMAGE=${dockerImage.image}:${dockerImage.tag} docker-compose -f docker-compose.yaml up --detach"
def ec2Instance = "ec2-user@${ipAddress}"
sshagent(['aws-ec2']) {
sh "scp docker-compose.yaml ${ec2Instance}:/home/ec2-user"
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${dockerComposeCmd}"
}
}
def deployScript(Map dockerImage, String ipAddress) {
echo 'deploying the application using shell script...'
def shellCmd = "bash ./deploy.sh ${dockerImage.image}:${dockerImage.tag}"
def ec2Instance = "ec2-user@${ipAddress}"
sshagent(['aws-ec2']) {
sh "scp deploy.sh ${ec2Instance}:/home/ec2-user"
sh "scp docker-compose.yaml ${ec2Instance}:/home/ec2-user"
sh "ssh -o StrictHostKeyChecking=no ${ec2Instance} ${shellCmd}"
}
}
return this