-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
37 lines (31 loc) · 1.42 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
node {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'docker-hub',
usernameVariable: 'DOCKER_USER_ID',
passwordVariable: 'DOCKER_USER_PASSWORD']])
{
stage('Pull') {
git branch: 'main', url: 'https://github.com/YeonjiKim0316/flask_0711_1/'
}
stage('Build') {
sh(script: 'sudo docker build -t flask_app2 .')
}
stage('Tag') {
sh(script: '''sudo docker tag flask_app2 ${DOCKER_USER_ID}/flask_app2:${BUILD_NUMBER}''')
}
stage('Push') {
sh(script: 'sudo docker login -u ${DOCKER_USER_ID} -p ${DOCKER_USER_PASSWORD}')
sh(script: 'sudo docker push ${DOCKER_USER_ID}/flask_app2:${BUILD_NUMBER}')
}
stage('Deploy') {
sshagent(credentials: ['yeonji-jenkins-ec2-key']) {
sh(script: 'ssh -o StrictHostKeyChecking=no [email protected]')
sh(script: 'if [ "$(sudo docker ps -q | wc -l)" -gt 1 ]; then "sudo docker rm -f \$(sudo docker ps -aq)"; fi')
sh(script: 'ssh [email protected] "sudo docker run --name docker_flask --env-file .env -e TZ=Asia/Seoul -p 80:80 -d -t \${DOCKER_USER_ID}/flask_app2:\${BUILD_NUMBER}"')
}
}
stage('Cleaning up') {
sh "sudo docker rmi ${DOCKER_USER_ID}/flask_app2:${BUILD_NUMBER}" // sudo docker image 제거
}
}
}