From dc7b496e971b4e890b979e749087249aaf720c3d Mon Sep 17 00:00:00 2001 From: Dom1046 Date: Thu, 26 Dec 2024 16:11:53 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20main=20branch=20CI/CD=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CICD.yml | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml index 2232e29e..0d86d231 100644 --- a/.github/workflows/CICD.yml +++ b/.github/workflows/CICD.yml @@ -26,7 +26,7 @@ jobs: # 생성된 파일들을 아티팩트로 업로드 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: application.properties path: ./src/main/resources/application.properties @@ -50,6 +50,39 @@ jobs: artifact=$(ls ./build/libs/*.jar | head -n 1) echo "artifact=$artifact" >> $GITHUB_ENV + # 9. SSH 키 설정 + - name: Set up SSH + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.EC2_SSH_KEY }} + # GitHub Secrets에 저장된 EC2 SSH 개인 키를 SSH 에이전트에 로드 + + # 10. GCP Credentials 디코딩 및 EC2로 전송 + - name: Decode GCP Credentials + run: echo "${{ secrets.GCP_CREDENTIALS }}" | base64 --decode > gcp-key.json + # GitHub Secrets에 저장된 Base64 인코딩된 GCP JSON Key를 디코딩하여 로컬에 저장 + + - name: Copy GCP Credentials to EC2 + run: scp -o StrictHostKeyChecking=no gcp-key.json ${{ secrets.EC2_USER }}@${{ secrets.EC2_IP }}:/home/${{ secrets.EC2_USER }}/gcp-key.json + # 디코딩된 GCP JSON Key 파일을 EC2 서버로 전송 + # YOUR_EC2_IP -> GitHub Secrets에 저장된 EC2 IP 주소 (${ secrets.EC2_IP }) + # ec2-user -> GitHub Secrets에 저장된 EC2 SSH 사용자 이름 (${ secrets.EC2_USER }) + + # 11. EC2에서 GCP Credentials 설정 + - name: Set up GCP Credentials on EC2 + run: | + ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_IP }} << 'EOF' + mkdir -p ~/.gcp + mv /home/${{ secrets.EC2_USER }}/gcp-key.json ~/.gcp/key.json + chmod 600 ~/.gcp/key.json + export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/key.json + # 환경 변수 설정을 영구적으로 추가 + echo 'export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/key.json' >> ~/.bash_profile + EOF + # EC2 서버에서 GCP Credentials 설정 + # YOUR_EC2_IP -> GitHub Secrets에 저장된 EC2 IP 주소 (${ secrets.EC2_IP }) + # ec2-user -> GitHub Secrets에 저장된 EC2 SSH 사용자 이름 (${ secrets.EC2_USER }) + # 빈스토크 배포 - name: Deploy to Elastic Beanstalk uses: einaregilsson/beanstalk-deploy@v20