7878 needs : [ buildImageAndPush ]
7979 env :
8080 OWNER : ${{ github.repository_owner }}
81+ EC2_INSTANCE_TAG_NAME : team5-ec2-1
82+
8183 steps :
84+ - uses : aws-actions/configure-aws-credentials@v4
85+ with :
86+ aws-region : ${{ secrets.AWS_REGION }}
87+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
88+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
89+
90+ - name : get instance id
91+ run : |
92+ INSTANCE_ID=$(aws ec2 describe-instances \
93+ --filters "Name=tag:Name, Values=${{ EC2_INSTANCE_TAG_NAME }}" "Name=instance-state-name, Values=running" \
94+ --query "Reservations[].Instances[].InstanceId" --output text)
95+ [[ -n "${INSTANCE_ID}" && "${INSTANCE_ID}" != "None" ]] || { echo "No running instance found"; exit 1; }
96+ echo "INSTANCE_ID=${INSTANCE_ID}" >> "${GITHUB_ENV}"
97+
8298 - name : set lower case owner name
8399 run : |
84100 echo "OWNER_LC=${OWNER,,}" >> ${GITHUB_ENV}
@@ -90,14 +106,17 @@ jobs:
90106 aws-region : ${{ secrets.AWS_REGION }}
91107 aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
92108 aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
93- instance-ids : " i-00e384163ab61f6cc "
109+ instance-ids : ${{ env.INSTANCE_ID }}
94110 working-directory : /
95111 comment : Deploy
96112 command : |
97- # 0 . env 변수 확인
113+ # 1 . env 변수 확인
98114 echo "OWNER_LC = ${{ env.OWNER_LC }}"
99115
100- # 1. 최신 이미지 pull
116+ # 2. EC2 인스턴스 아이디 확인
117+ echo "INSTANCE_ID=${INSTANCE_ID}"
118+
119+ # 3. 최신 이미지 pull
101120 docker pull ghcr.io/${{ env.OWNER_LC }}/catfe-backend:latest
102121
103122 # 2. 기존 컨테이너 종료 및 제거
0 commit comments