-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
96 lines (81 loc) · 3.11 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
pipeline {
agent any
tools {nodejs "Node_version"}
environment {
DOCKER_COMPOSE_VERSION = '1.29.2'
AWS_PUBLIC_URL = "43.203.237.252"
DOCKERHUB_CREDENTIALS = credentials('dockerhub_token')
DOCKER_IMAGE = "falconlee236/puangfilm-web"
CONTAINER_NAME = "puangfilm-web"
DOCKERHUB_CREDENTIALS_PSW = credentials('DOCKERHUB_pwd')
DOCKERHUB_CREDENTIALS_USR = credentials('DOCKERHUB_id')
}
stages {
stage('github_clone') {
steps {
git branch: 'main', credentialsId: 'github_token', url: 'https://github.com/GDSC-CAU/PuangFilm-FE'
}
}
stage('env file copy') {
steps {
script {
sh "cp /var/jenkins_home/env/.env.local ."
}
}
}
stage('docker-build'){
steps {
script {
echo 'Build Docker'
sh 'docker build -t ${DOCKER_IMAGE} .'
}
}
}
stage('dockerhub-login') {
steps {
script {
sh 'echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin'
}
}
}
stage('Deploy image') {
steps {
script {
// 태그를 달아서 한 레포에 2개 이상 이미지를 배포할 수 있음
// sh 'docker image tag $DOCKER_REPO $DOCKER_REPO:$BUILD_NUMBER'
sh 'docker push $DOCKER_IMAGE'
}
}
}
stage('docker-image-pull') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker pull ${DOCKER_IMAGE}"'
}
}
}
}
stage('docker-clean-up') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker stop $CONTAINER_NAME"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker rm -f $CONTAINER_NAME"'
}
}
}
}
stage('docker-start') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker run -p 3030:3030 --name $CONTAINER_NAME -d ${DOCKER_IMAGE}"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker system prune --force --all --volumes"'
}
}
}
}
}
}