Skip to content

Update deploy.yml

Update deploy.yml #11

Workflow file for this run

name: Deploy to Prod via Bastion
on:
pull_request:
types: [closed]
branches: [main]
jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Build JAR
run: ./gradlew clean build -x test
- name: Setup SSH known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.BASTION_IP }} >> ~/.ssh/known_hosts || true
ssh-keyscan -H ${{ secrets.PROD_IP }} >> ~/.ssh/known_hosts || true
- name: Setup SSH Agent
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Transfer JAR to EC2 via Bastion (ProxyCommand)
run: |
scp -o "ProxyCommand=ssh -W %h:%p -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.BASTION_IP }}" \
build/libs/busan-0.0.1-SNAPSHOT.jar \
${{ secrets.SSH_USER }}@${{ secrets.PROD_IP }}:/home/ubuntu/app/jar/app.jar
- name: Trigger Deployment (ProxyCommand)
run: |
ssh -o "ProxyCommand=ssh -W %h:%p -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.BASTION_IP }}" \
${{ secrets.SSH_USER }}@${{ secrets.PROD_IP }} << 'EOF'
cd /home/ubuntu/app
./switch.sh
EOF