From a436332b7abe77ae1635e9f87d4ed13166e7ff00 Mon Sep 17 00:00:00 2001 From: kdkdhoho Date: Tue, 28 May 2024 19:26:08 +0900 Subject: [PATCH] prod: test22 (#prod) --- .github/workflows/prod-cd.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/prod-cd.yml b/.github/workflows/prod-cd.yml index bf3f1435..de4924b2 100644 --- a/.github/workflows/prod-cd.yml +++ b/.github/workflows/prod-cd.yml @@ -32,11 +32,32 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + + - name: IP를 파일로 저장 + run: echo "${{ steps.ip.outputs.ipv4 }}" > ip)address.txt + + - name: IP 주소를 아티팩트로 업로드 + uses: actions/upload-artifact@v3 + with: + name: ip-address + path: ip_address.txt deploy: needs: [ ip-setup ] runs-on: ubuntu-latest steps: + - name: 아티팩트에서 IP 주소 다운로드 + uses: actions/download-artifact@v3 + with: + name: ip-address + path: . + + - name: IP 주소 읽기 + id: ip + run: | + IP_ADDRESS=$(cat ip_address.txt) + echo "IP_ADDRESS=${IP_ADDRESS}" >> $GITHUB_ENV + - name: 저장소 Checkout uses: actions/checkout@v4 @@ -96,16 +117,22 @@ jobs: password: ${{ secrets.PROD_EC2_PASSWORD }} port: ${{ secrets.PROD_EC2_PORT }} script: | + ls docker stop "${{ secrets.PROD_CONTAINER_NAME }}" + echo "1" docker rm -f "${{ secrets.PROD_CONTAINER_NAME }}" + echo "2" docker rmi "${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.IMAGE_NAME }}:${{ secrets.PROD_TAG }}" + echo "3" docker pull "${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.IMAGE_NAME }}:${{ secrets.PROD_TAG }}" + echo "4" docker run -d -p 8080:8080 --name "${{ secrets.PROD_CONTAINER_NAME }}" "${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.IMAGE_NAME }}:${{ secrets.PROD_TAG }}" + echo "5" - name: IP 제거 if: ${{ always() }} run: | - aws ec2 revoke-security-group-ingress --group-name ${{ secrets.AWS_SECURITY_GROUP_NAME }} --protocol tcp --port ${{ secrets.PROD_EC2_PORT }} --cidr ${{ jobs.ip.set-up.ip.outputs.ipv4 }}/32 + aws ec2 revoke-security-group-ingress --group-name ${{ secrets.AWS_SECURITY_GROUP_NAME }} --protocol tcp --port ${{ secrets.PROD_EC2_PORT }} --cidr ${{ env.IP_ADDRESS }}/32 env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}