-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
80 lines (79 loc) · 3.33 KB
/
Jenkinsfile
File metadata and controls
80 lines (79 loc) · 3.33 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
73
74
75
76
77
78
79
80
pipeline {
agent any
environment {
DOCKER_CREDENTIAL_ID = 'docker_credentials'
DOCKER_HUB_USERNAME = 'kovengers'
IMAGE_NAME = 'frontend'
VERSION = "${env.BUILD_NUMBER}" // Jenkins 빌드 번호를 버전으로 사용합니다.
}
stages {
stage('Pull Git Submodules') {
steps {
sh 'git submodule update --init --recursive'
}
}
stage('Copy YAML File') {
steps {
script{
sh('sudo cp ' + WORKSPACE+'/config/frontend-api-key/.env' + ' ' + WORKSPACE)
}
}
}
stage('Build Docker images') {
steps {
script {
docker.build("${DOCKER_HUB_USERNAME}/${IMAGE_NAME}", "-t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest -t ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${VERSION} .")
}
}
}
stage('Push Docker images') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', "${DOCKER_CREDENTIAL_ID}") {
// 'latest' 태그 푸시
docker.image("${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest").push()
// 버전 태그 푸시
docker.image("${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${VERSION}").push()
}
}
}
}
stage('Docker image cleanup') {
steps {
script {
sh 'docker rmi ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest'
sh 'docker rmi ${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${VERSION}'
sh 'docker rmi registry.hub.docker.com/${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:latest'
sh 'docker rmi registry.hub.docker.com/${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${VERSION}'
}
}
}
stage('Update Kubernetes YAML') {
steps {
script {
dir('config'){
sshagent(['k8s_git']) {
sh 'mkdir -p ~/.ssh'
sh 'if [ ! -f ~/.ssh/known_hosts ]; then ssh-keyscan github.com >> ~/.ssh/known_hosts; fi'
sh 'rm -rf kubernetes-yaml' // Add this line
sh 'git clone git@github.com:KEA-Kovengers/kubernetes-yaml.git'
}
dir('kubernetes-yaml') {
dir('frontend'){
sh "sed -i 's|${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:.*|${DOCKER_HUB_USERNAME}/${IMAGE_NAME}:${VERSION}|' frontend.yaml"
}
sh 'git config user.email "keakovengers@gmail.com"'
sh 'git config user.name "kovengers"'
sh 'git add -A'
sh 'git status'
sh 'git diff --cached --exit-code || git commit -m "Update frontend service image tag"'
sshagent(['k8s_git']) {
sh 'git push origin kakao-cloud'
}
}
}
}
}
}
}
}