Skip to content

Commit

Permalink
prod: test22 (#prod)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed May 28, 2024
1 parent d546c13 commit a436332
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion .github/workflows/prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}
Expand Down

0 comments on commit a436332

Please sign in to comment.