-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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'" |