# 학습 목표
- 서버 배포 자동화 파이프라인 구축
# 해결 과제

repository 주소의 main 브랜치를 이용합니다.
- 위 링크로 접속하여 해당 리포지토리를 자신의 리포지토리로 fork 한 뒤, git clone 명령어를 사용하여 자신의 로컬 환경에 소스 코드를 저장합니다. (EC2 인스턴스에 소스 코드를 clone 하는 것이 아닙니다.)
- EC2 인스턴스를 생성합니다.
- AWS 개발자 도구 서비스를 이용해서 배포 자동화 파이프라인을 구축해야 합니다.
- 나중에 변경 사항을 GitHub 리포지토리에 반영했을 경우, 배포 과정이 자동으로 진행되어야 합니다.
- 배포 과정에서 오류가 생길 경우, log 파일을 참조하여 문제점을 확인할 수 있어야 합니다.
# 실습 자료
# 과제 항목별 진행 상황
EC2 인스턴스를 생성
ENI | Public, Private Dynamic IP |
IAM Role | AmazonS3FullAccess Permit AmazonSSMFullAccess Permit AWSCodeDeployRole Permit |
Security Group | Inbound : HTTP(80), HTTPS(443) Permit |
배포 자동화 파이프라인을 구축
(저장소 위치에서 조작)
- CodeDeploy-Agent 가 인식하고 자동으로 shell script가 동작설정
#root direcory 에 appspec.yml 파일로 위치
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/sprint-practice-deploy-for04
hooks:
ApplicationStop:
- location: scripts/stop.sh
runas: root
AfterInstall:
- location: scripts/initialize.sh
runas: root
ApplicationStart:
- location: scripts/start.sh
runas: root
#root directory/scripts 에 sh 파일 생성
# initialize.sh
cd /home/ubuntu/sprint-practice-deploy-for04/server
npm install
npm install pm2@latest -g
sudo apt-get update
sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chown ubuntu /etc/authbind/byport/80
sudo chmod 755 /etc/authbind/byport/80
# start.sh
cd /home/ubuntu/sprint-practice-deploy-for04/server
authbind --deep pm2 start app.js
# stop.sh
cd /home/ubuntu/sprint-practice-deploy-for04/server
pm2 stop app.js 2> /dev/null || true
pm2 delete app.js 2> /dev/null || true
- CodeDeploy 에서 애플리케이션 생성 컴퓨팅 플랫폼 : EC2/온프레미스

- CodeDeploy 에서 배포 그룹 생성 환경 구성 : Amazon EC2 인스턴스



- CodePipeline에서 파이프라인 생성


배포 결과 확인


# TROUBLE SHOOTING LOG
💡 appspec.yml 파일을 찾지 못하는 이슈 2023-04-24T07:13:45 INFO [codedeploy-agent(1718)]: [Aws::CodeDeployCommand::Client 200 0.017902 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":5,"script_name":"","message":"The CodeDeploy agent did not find an AppSpec file within the unpacked revision directory at revision-relative path \"appspec.yml\".
원인
- CodeDeploy agent 는 기본적으로 yml 확장자의 appspec 파일을 찾지만, 해당 파일의 확장자를 yaml (appspec.yaml) 로 생성하여 오류 발생
- appspec.yml 파일 version 을 기존 0.0 에서 임의로 변경하여 오류 발생
해결 방안
- 파일의 확장자를 yml 로 변경
- version 0.0 으로 원복