File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,23 +70,23 @@ jobs:
7070 host : ${{ secrets.EC2_HOST }}
7171 username : ${{ secrets.EC2_USER }}
7272 key : ${{ secrets.EC2_SSH_KEY }}
73+ envs : ECR_REGISTRY,ECR_REPOSITORY,AWS_REGION
74+ env :
75+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
76+ ECR_REPOSITORY : cp_main_be
77+ AWS_REGION : ${{ secrets.AWS_REGION }}
7378 script : |
74- # 하드코딩된 값으로 테스트
75- ECR_REGISTRY="${{ steps.login-ecr.outputs.registry }}"
76- ECR_REPOSITORY="cp_main_be"
77- AWS_REGION="${{ secrets.AWS_REGION }}"
78-
79+ # 환경변수 확인
7980 echo "ECR_REGISTRY: $ECR_REGISTRY"
8081 echo "ECR_REPOSITORY: $ECR_REPOSITORY"
81- echo "AWS_REGION: $AWS_REGION"
8282
83- # AWS CLI 설정
83+ # AWS CLI 설정 (EC2에서 ECR에 접근하기 위해)
8484 aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $ECR_REGISTRY
8585
86- # 1. 이미지 pull
86+ # 1. 배포 서버에서 최신 버전의 'latest' 태그 이미지를 pull
8787 docker pull $ECR_REGISTRY/$ECR_REPOSITORY:latest
8888
89- # 2. 기존 컨테이너 정리
89+ # 2. 기존에 실행 중인 컨테이너가 있다면 중지하고 삭제
9090 if [ $(docker ps -a -q -f name=spring-app-container) ]; then
9191 docker stop spring-app-container
9292 docker rm spring-app-container
9595 # 환경변수 로드
9696 source /etc/environment
9797
98- # 3. 새 컨테이너 실행
98+ # 3. 새 컨테이너를 실행
9999 docker run -d --name spring-app-container -p 80:8080 \
100100 -e DB_URL="$DB_URL" \
101101 -e DB_USERNAME="$DB_USERNAME" \
You can’t perform that action at this time.
0 commit comments