update auto-deployment.yml #67
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
name: AWS EC2 자동 배포 | |
on: | |
pull_request: | |
branches: [ "Dev" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
steps: | |
- uses: actions/[email protected] | |
- name: Show git status | |
run: git status | |
- name: Setup Java JDK | |
uses: actions/[email protected] | |
with: | |
java-version: 17 | |
distribution: temurin | |
java-package: jdk | |
architecture: x64 | |
cache: gradle | |
- name: Build Jar | |
run: | | |
cd JWT | |
chmod 755 gradlew | |
./gradlew bootJar | |
- name: Prepare SSH connect | |
env: | |
private_key: ${{ secrets.EC2_PRIVATE_KEY }} | |
run: | | |
echo "$private_key" > private_key.pem | |
chmod 400 private_key.pem | |
mkdir ~/.ssh | |
ssh-keyscan -t rsa $host > ~/.ssh/known_hosts | |
- name: Upload deployment scripts | |
run: | | |
sudo chmod 755 JWT/deploy/* | |
scp -i private_key.pem -r JWT/deploy "${username}@${host}:~" | |
- name: Kill current running Spring process | |
run: ssh -i private_key.pem "${username}@${host}" "deploy/shutdown.sh; deploy/backup.sh" | |
- name: Send jar file to EC2 | |
run: | | |
cd JWT | |
jarPath=$(./gradlew -q jarPath) | |
cd .. | |
scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" | |
- name: Startup new uploaded jar | |
run: ssh -i private_key.pem "${username}@${host}" "source ~/.profile; deploy/startup.sh" | |
- name: Wait 30 seconds for server to startup | |
run: sleep 30 | |
- name: Check and Recover | |
run: ssh -i private_key.pem "${username}@${host}" "source ~/.profile; deploy/check_and_recover.sh" |