-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
71 lines (64 loc) · 2.43 KB
/
Jenkinsfile
File metadata and controls
71 lines (64 loc) · 2.43 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
pipeline {
agent any
stages {
stage('Git clone') {
steps {
git branch: 'develop', url: 'https://github.com/syncfit-msa/Config-Server';
}
}
stage('Project Build') {
steps {
sh '''
echo build start;
./gradlew clean build -Dspring.profiles.active=prod -x test
''';
}
}
stage ('AWS Credential') {
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'aws-access-key']]) {
sh 'aws ecr get-login-password --region ap-northeast-3 | docker login --username AWS --password-stdin 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com'
}
}
}
stage('Docker Image Build') {
steps {
sh '''
docker build --platform linux/amd64 -t mini2/config-server .
docker tag mini2/config-server:latest 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com/mini2/config-server:latest
'''
}
}
stage("Push to ECR") {
steps {
withCredentials([[
$class: 'AmazonWebServicesCredentialsBinding',
credentialsId: 'aws-access-key']]) {
sh 'docker push 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com/mini2/config-server:latest'
}
}
}
stage('Deploy to EC2') {
steps {
sshagent(['ec2-ssh-key']) {
sh '''
ssh [email protected] '
aws ecr get-login-password --region ap-northeast-3 | docker login --username AWS --password-stdin 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com
docker pull 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com/mini2/config-server:latest
docker-compose down
docker-compose up -d
'
'''
}
}
}
stage('Cleanup') {
steps {
sh 'docker rmi mini2/config-server:latest || true'
sh 'docker rmi 268104899906.dkr.ecr.ap-northeast-3.amazonaws.com/mini2/config-server:latest || true'
}
}
}
}