[연동 방법]
[Webhook]
[연동 방법]
Jenkins 서버에 aws-cli 설치 (는 꼭 안 해도 될듯)
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
$ aws --version # 설치 확인
$ aws configure
$ aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 337260748354.dkr.ecr.ap-northeast-1.amazonaws.com
Jenkinsfile
[참고] https://teichae.tistory.com/entry/Jenkins-Pipeline을-이용한-Docker-Image를-ECR로-Push
node {
stage('Clone repository') {
checkout scm
}
stage('Build spring image') {
spring = docker.build("{리포지토리 주소}/spring_prd:latest", "-f {spring Dockerfile 경로} .")
}
stage('Push spring image') {
sh 'rm ~/.dockercfg || true'
sh 'rm ~/.docker/config.json || true'
docker.withRegistry('https://{리포지토리 주소}', 'ecr:ap-northeast-1:aws') {
spring.push("latest")
}
}
stage('Build nginx image') {
nginx = docker.build("{리포지토리 주소}/nginx_prd:latest", "-f {nginx Dockerfile 경로} .")
}
stage('Push nginx image') {
docker.withRegistry('https://{리포지토리 주소}', 'ecr:ap-northeast-1:aws') {
nginx.push("latest")
}
stage('Deploy nginx') {
withAWS(region: 'ap-northeast-1', credentials: 'aws') {
sh 'aws ecs update-service --region ap-northeast-1 --cluster ecs-prd-nginx-01 --service ecs-service-prd-nginx-01 --force-new-deployment'
}
}
stage('Deploy spring') {
withAWS(region: 'ap-northeast-1', credentials: 'aws') {
sh 'aws ecs update-service --region ap-northeast-1 --cluster ecs-prd-spring-01 --service ecs-service-prd-spring-01 --force-new-deployment'
}
}
}
}
파이프라인 구성