Skip to content

Commit

Permalink
fix: remove cd from execution command
Browse files Browse the repository at this point in the history
fix: ec2 target directory
fix: fix host key verification failed <- add remote server to known hosts
refactor: rename springboot action names
fix: add ssh script to run springboot app & add comments
  • Loading branch information
thisisWooyeol committed Nov 20, 2023
1 parent 1268060 commit 21f7549
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/springboot-on-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Springboot CI
name: Springboot CI on PR

on:
pull_request:
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/springboot-on-push.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Springboot CI
name: Springboot CI on Push

on:
push:
Expand All @@ -25,24 +25,34 @@ jobs:
distribution: 'temurin'
cache: gradle

# Build & Test
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean build
- name: Test with Gradle
run: ./gradlew test

- name: Set up SSH
# Setup SSH
- name: Set up SSH agent with private key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SPRINGBOOT_EC2_SSH_KEY }}
- name: Add remote server to known hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.SPRINGBOOT_HOST_DNS }} >> ~/.ssh/known_hosts
# Deploy
- name: SCP jar file to server
run: |
scp *jar ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}:~/\
scp *jar ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}:\
${{ secrets.SPRINGBOOT_TARGET_DIR }}
working-directory: ./springboot/build/libs
- name: Execute remote commands
run: |
ssh ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\
"fuser -k 8080/tcp"
ssh ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }}\
ssh -v ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }} \
"fuser -k 8080/tcp || true"
ssh -v ${{ secrets.SPRINGBOOT_USERNAME }}@${{ secrets.SPRINGBOOT_HOST_DNS }} \
"sudo nohup /usr/bin/java -jar ${{ secrets.SPRINGBOOT_TARGET_DIR }}/*.jar\
> {{ secrets.SPRINGBOOT_TARGET_DIR }}/app.log 2>&1 &"

0 comments on commit 21f7549

Please sign in to comment.