From 7fbdfbe67d6408a37dbad7b9c4bb279f2e368030 Mon Sep 17 00:00:00 2001 From: Seonjun Kim Date: Thu, 11 Dec 2025 17:25:40 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=8B=A4=EC=A4=91=EC=9D=B8?= =?UTF-8?q?=EC=8A=A4=ED=84=B4=EC=8A=A4=20ci/cd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd.yaml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index 66bd81a..f11b956 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -39,6 +39,20 @@ jobs: deploy: needs: build-and-push runs-on: ubuntu-latest + strategy: + matrix: + server: + - host: "3.36.57.151" + name: "front" + - host: "3.36.112.194" + name: "front" + - host: "13.124.239.162" + name: "front" + - host: "3.38.247.224" + name: "front" + - host: "43.201.37.211" + name: "front" + fail-fast: false # 한 서버 실패해도 다른 서버는 계속 배포 steps: - name: Set up SSH uses: webfactory/ssh-agent@v0.9.0 @@ -48,12 +62,11 @@ jobs: - name: Add known_hosts run: | mkdir -p ~/.ssh - ssh-keyscan -H ${{ secrets.SERVER_HOST }} >> ~/.ssh/known_hosts + ssh-keyscan -H ${{ matrix.server.host }} >> ~/.ssh/known_hosts - - - name: Deploy to EC2 + - name: Deploy to EC2 (${{ matrix.server.name }}) run: | - ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} 'bash -s' <>> docker compose up -d" docker compose up -d - echo ">>> Deployed!" + echo ">>> Deployed to ${{ matrix.server.name }}!" EOF From 5ee24aa565fab912caf16259c139e108bbb59270 Mon Sep 17 00:00:00 2001 From: Seonjun Kim Date: Fri, 12 Dec 2025 07:52:55 +0900 Subject: [PATCH 2/2] feat: ci/cd --- .github/workflows/cicd.yaml | 64 +++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index f11b956..7fa5d3b 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -39,34 +39,53 @@ jobs: deploy: needs: build-and-push runs-on: ubuntu-latest - strategy: - matrix: - server: - - host: "3.36.57.151" - name: "front" - - host: "3.36.112.194" - name: "front" - - host: "13.124.239.162" - name: "front" - - host: "3.38.247.224" - name: "front" - - host: "43.201.37.211" - name: "front" - fail-fast: false # 한 서버 실패해도 다른 서버는 계속 배포 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Get EC2 instance IPs + id: get-instances + run: | + INSTANCE_IPS=$(aws ec2 describe-instances \ + --filters \ + "Name=tag:Role,Values=frontend" \ + "Name=instance-state-name,Values=running" \ + --query 'Reservations[*].Instances[*].PublicIpAddress' \ + --output json | jq -r '.[] | .[]' | tr '\n' ' ') + + if [ -z "$INSTANCE_IPS" ]; then + echo "No EC2 instances found." + exit 1 + fi + + echo "INSTANCE_IPS=$INSTANCE_IPS" >> $GITHUB_OUTPUT + echo "Found IPs: $INSTANCE_IPS" + - name: Set up SSH uses: webfactory/ssh-agent@v0.9.0 with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Add known_hosts + - name: Deploy to EC2 instances + env: + INSTANCE_IPS: ${{ steps.get-instances.outputs.INSTANCE_IPS }} run: | - mkdir -p ~/.ssh - ssh-keyscan -H ${{ matrix.server.host }} >> ~/.ssh/known_hosts + for IP in $INSTANCE_IPS; do + echo ">>> Deploying to $IP" - - name: Deploy to EC2 (${{ matrix.server.name }}) - run: | - ssh ${{ secrets.SERVER_USER }}@${{ matrix.server.host }} 'bash -s' <> ~/.ssh/known_hosts + + # Deploy + ssh ${{ secrets.SERVER_USER }}@$IP 'bash -s' <>> docker compose up -d" docker compose up -d - echo ">>> Deployed to ${{ matrix.server.name }}!" + echo ">>> Deployed successfully!" EOF + + echo ">>> Deployment to $IP completed" + done