Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat : Jenkinsfile, 실제 cicd 는 파이프라인에서 할거라 주석처리함. #45

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 0 additions & 113 deletions .github/workflows/ai-cicd.yaml

This file was deleted.

133 changes: 133 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// pipeline {
// agent any
//
// environment {
// // 환경 변수 파일 경로 설정
// ENV_FILE = '/var/lib/jenkins/environments/.env.ai'
// // Docker 이미지 정보
// DOCKER_IMAGE = 'aida0/gitfolio_ai:test'
// // AWS 리전
// AWS_REGION = 'ap-northeast-2'
// }
//
// stages {
// stage('Load Environment Variables') {
// steps {
// script {
// // .env.ai 파일에서 환경 변수 로드
// def envContent = readFile(ENV_FILE).trim()
// envContent.split('\n').each { line ->
// def (key, value) = line.split('=', 2)
// env."${key}" = value
// }
// }
// }
// }
//
// // Git 저장소 체크아웃 단계
// stage('Checkout') {
// steps {
// // Git 저장소 URL을 직접 지정하여 체크아웃
// git branch: 'develop',
// url: 'https://github.com/KTB-Sixmen/gitfolio_AI.git'
// }
// }
//
// stage('Docker Build & Push') {
// steps {
// script {
// // Docker Hub 로그인
// withCredentials([usernamePassword(credentialsId: 'docker-credentials', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) {
// sh """
// docker login -u ${DOCKER_USER} -p ${DOCKER_PASS}
//
// # Docker 이미지 빌드
// docker build \
// --build-arg OPENAI_API_KEY=${env.OPENAI_API_KEY} \
// --build-arg GH_TOKEN=${env.GH_TOKEN} \
// --build-arg HOST=${env.HOST} \
// --build-arg PORT=${env.PORT} \
// -t ${DOCKER_IMAGE} .
//
// # Docker 이미지 푸시
// docker push ${DOCKER_IMAGE}
// """
// }
// }
// }
// }
//
// stage('Deploy to EC2') {
// steps {
// script {
// withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',
// credentialsId: 'aws-credentials',
// accessKeyVariable: 'AWS_ACCESS_KEY_ID',
// secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
//
// // EC2 인스턴스 ID 조회
// def instanceIds = sh(
// script: """
// aws ec2 describe-instances \
// --region ${AWS_REGION} \
// --filters 'Name=tag:Service,Values=ai' 'Name=instance-state-name,Values=running' \
// --query 'Reservations[].Instances[].InstanceId' \
// --output text
// """,
// returnStdout: true
// ).trim()
//
// if (instanceIds) {
// // docker-compose.yaml 파일 인코딩
// def dockerComposeContent = sh(
// script: "base64 docker-compose.yaml | tr -d '\n'",
// returnStdout: true
// ).trim()
//
// // SSM 명령 실행 - JSON 형식 수정
// def commandId = sh(
// script: """
// aws ssm send-command \
// --instance-ids "${instanceIds}" \
// --document-name "AWS-RunShellScript" \
// --comment "Deploying AI Server" \
// --parameters '{"commands":["cd /home/ec2-user","echo '\\''${dockerComposeContent}'\\'' | base64 -d > docker-compose.yaml","echo '\\''OPENAI_API_KEY=${env.OPENAI_API_KEY}'\\'' > .env","echo '\\''GH_TOKEN=${env.GH_TOKEN}'\\'' >> .env","echo '\\''HOST=${env.HOST}'\\'' >> .env","echo '\\''PORT=${env.PORT}'\\'' >> .env","chmod 600 .env","docker-compose down -v --rmi all","docker-compose pull","docker-compose up -d"]}' \
// --timeout-seconds 600 \
// --region ${AWS_REGION} \
// --output text \
// --query 'Command.CommandId'
// """,
// returnStdout: true
// ).trim()
//
// // 명령 실행 완료 대기
// sh """
// aws ssm wait command-executed \
// --command-id ${commandId} \
// --instance-id ${instanceIds} \
// --region ${AWS_REGION}
// """
//
// // 실행 결과 확인
// sh """
// aws ssm get-command-invocation \
// --command-id ${commandId} \
// --instance-id ${instanceIds} \
// --region ${AWS_REGION}
// """
// } else {
// error "No running EC2 instances found with the specified tags"
// }
// }
// }
// }
// }
// }
//
// post {
// always {
// // 작업 완료 후 정리
// cleanWs()
// }
// }
// }
Loading