Update auto-deployment.yml #52
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: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
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: | |
# The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file | |
java-version: 17 | |
# Java distribution. See the list of supported distributions in README file | |
distribution: temurin | |
# The package type (jdk, jre, jdk+fx, jre+fx) | |
java-package: jdk | |
# The architecture of the package (defaults to the action runner's architecture) | |
architecture: x64 | |
cache: gradle | |
- name: Build Jar | |
run: | | |
chmod 755 gradlew | |
./gradlew bootJar | |
working-directory: JWT | |
- 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 | |
working-directory: JWT | |
- name: Upload deployment scripts | |
run: | | |
scp -i private_key.pem -r deploy "${username}@${host}:~" | |
working-directory: JWT | |
- name: Remote SSH Commands | |
uses: fifsky/[email protected] | |
with: | |
command: | | |
echo $JAVA_HOME | |
echo $PATH | |
java --version | |
host: ${{ secrets.EC2_HOST }} | |
user: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
- name: Kill current running Spring process | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
echo $JAVA_HOME | |
sudo chmod 755 deploy/* | |
deploy/shutdown.sh | |
deploy/backup.sh | |
- name: Send jar file to EC2 | |
run: | | |
jarPath=$(./gradlew -q jarPath) | |
scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" | |
working-directory: JWT | |
- name: Run new uploaded jar | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script: | | |
sudo chmod 755 deploy/* | |
deploy/startup.sh |