Skip to content

Update cicd.yml

Update cicd.yml #47

Workflow file for this run

name: cicd pipeline
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-push:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Liberica JDK 17
uses: actions/setup-java@v3
with:
distribution: 'liberica'
java-version: '17'
- name: Cleanup application.yml
run: |
cd logbat
rm -f src/main/resources/application.yml
- name: Create application-dev.yml from GitHub Secret
run: |
cd logbat
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml
- name: Build with Gradle
env:
ORG_GRADLE_OPTS: "-Duser.timezone=Asia/Seoul"
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
- name: Start SSH Agent and Add Bastion Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.BASTION_SSH_SECRET_KEY }}
- name: Add Target Server Key to SSH Agent
run: echo "${{ secrets.PRIVATE_SSH_SECRET_KEY }}" | ssh-add -
- name: SCP JAR file to EC2 via Bastion
run: |
cd logbat/build/libs
scp -o StrictHostKeyChecking=no -o ProxyCommand="ssh -W %h:%p -o StrictHostKeyChecking=no ubuntu@${{ secrets.BASTION_HOST_IP }}" \
*.jar ubuntu@${{ secrets.BACKEND_HOST_IP }}:/home/ubuntu/${{ env.JAR_FILE }}
deploy:
name: Deploy to EC2
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Start SSH Agent and Add Bastion Key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.BASTION_SSH_SECRET_KEY }}
- name: Add Target Server Key to SSH Agent
run: echo "${{ secrets.PRIVATE_SSH_SECRET_KEY }}" | ssh-add -
- 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'"