chore: github action #7
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: Dev - Build and Deploy to EC2 | |
on: | |
push: | |
branches: [ "dev" ] | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ./ | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
cache: gradle | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Clean Build with Gradle (without Test) | |
run: | | |
echo ${{ secrets.APPLICATION_DEV_YML }} | base64 --decode > ./src/main/resources/application-dev.yml | |
./gradlew clean build -x test | |
- name: Deploy to EC2 | |
env: | |
PRIVATE_KEY: ${{ secrets.YOURSSU_SECRET }} | |
HOST: ${{ secrets.YOURSSU_STG_HOST }} | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan -H $HOST >> ~/.ssh/known_hosts | |
echo "$PRIVATE_KEY" > private_key.pem | |
chmod 600 private_key.pem | |
mv build/libs/soongpt-0.0.1-SNAPSHOT.jar yourssu-soongpt-application.jar | |
scp -i private_key.pem yourssu-soongpt-application.jar ubuntu@$HOST:/home/ubuntu/soongpt-api | |
ssh -i private_key.pem ubuntu@$HOST "/home/ubuntu/soongpt-api/run.sh" |