-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
61 lines (54 loc) · 2.47 KB
/
Jenkinsfile
File metadata and controls
61 lines (54 loc) · 2.47 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
pipeline {
agent any
environment {
REPO = 'KTB-LuckyVicky/todayfin-fe'
ECR_REPO = '905418374604.dkr.ecr.ap-northeast-2.amazonaws.com/todayfin-fe'
ECR_CREDENTIALS_ID = 'ecr:ap-northeast-2:ecr_credentials_id'
ALPHA_VANTAGE_API_KEY = credentials('alpha_vantage_api_key')
HUGGINGFACE_API_KEY = credentials('huggingface_api_key')
ALPHA_VANTAGE_BACKEND_URL = credentials('alpha_vantage_backend_url')
NEXT_PUBLIC_BACKEND_URL = credentials('NEXT_PUBLIC_BACKEND_URL')
RECOMMEND_AI_URL = credentials('RECOMMEND_AI_URL')
}
stages {
stage('Checkout') {
steps {
git branch: 'dev', url: "https://github.com/${REPO}.git"
}
}
stage('Build Docker Image') {
steps {
script {
dockerImage = docker.build("${ECR_REPO}:latest")
}
}
}
stage('Push to ECR') {
steps {
script {
docker.withRegistry("https://${ECR_REPO}", "${ECR_CREDENTIALS_ID}") {
dockerImage.push('latest')
}
}
}
}
stage('Deploy on Local Server') {
steps {
script {
// Jenkins 자격증명을 사용하여 Docker 로그인
docker.withRegistry("https://${ECR_REPO}", "${ECR_CREDENTIALS_ID}") {
//기존에 도커 컨테이너 삭제
sh "docker rm -f todayfin-fe"
// ECR에서 이미지 pull
sh "docker pull ${ECR_REPO}:latest"
// 도커 컨테이너 실행
sh "docker run -d -e NEXT_PUBLIC_BACKEND_URL=${NEXT_PUBLIC_BACKEND_URL} -e RECOMMEND_AI_URL=${RECOMMEND_AI_URL} -e ALPHA_VANTAGE_API_KEY=${ALPHA_VANTAGE_API_KEY} -e HUGGINGFACE_API_KEY=${HUGGINGFACE_API_KEY} -e ALPHA_VANTAGE_BACKEND_URL=${ALPHA_VANTAGE_BACKEND_URL} --name todayfin-fe -p 3000:3000 ${ECR_REPO}:latest"
// Docker 이미지 리스트를 가져오고, <none> 태그 이미지 정렬 및 필터링
// 최신 5개를 제외한 이미지 ID 추출
sh "docker images --format '{{.ID}} {{.CreatedAt}}' | grep '<none>' | sort -r -k 2 | tail -n +6 | awk '{print \$1}' | xargs -r docker rmi"
}
}
}
}
}
}