Skip to content

Commit

Permalink
Update cicd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
miiiinju1 authored Aug 26, 2024
1 parent a4dc479 commit 7840bb0
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ on:
push:
branches: [ "cicd-test" ]
env:
JAR_FILE: logbat.jar
BASTION_HOST_IP: ${{ secrets.BASTION_HOST_IP }}
BACKEND_HOST_IP: ${{ secrets.BACKEND_HOST_IP }}

permissions:
contents: read
jobs:
build-and-deploy:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -34,6 +35,21 @@ jobs:
run: |
cd logbat
./gradlew clean bootJar -x test
- name: Upload JAR file as artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.JAR_FILE }}
path: logbat/build/libs/*.jar

deploy:
name: Deploy to EC2
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Download JAR file
uses: actions/download-artifact@v2
with:
name: ${{ env.JAR_FILE }}
- name: Start SSH Agent and Add Bastion Key
uses: webfactory/[email protected]
with:
Expand All @@ -43,8 +59,8 @@ jobs:
- name: SCP JAR file to EC2 via Bastion
run: |
scp -o StrictHostKeyChecking=no -o ProxyCommand="ssh -W %h:%p -o StrictHostKeyChecking=no ubuntu@${{ secrets.BASTION_HOST_IP }}" \
logbat/build/libs/*.jar ubuntu@${{ secrets.BACKEND_HOST_IP }}:/home/ubuntu/logbat.jar
- name: Execute deploy script on EC2
${{ env.JAR_FILE }} ubuntu@${{ secrets.BACKEND_HOST_IP }}:/home/ubuntu/${{ env.JAR_FILE }}
- name: Connect to Bastion and Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no -A ubuntu@${{ secrets.BASTION_HOST_IP }} \
"ssh -o StrictHostKeyChecking=no ubuntu@${{ secrets.BACKEND_HOST_IP }} 'bash /home/ubuntu/deploy.sh'"

0 comments on commit 7840bb0

Please sign in to comment.