Skip to content

chore: 환경변수 주입 방식 변경 #4

chore: 환경변수 주입 방식 변경

chore: 환경변수 주입 방식 변경 #4

name: Deploy to EC2
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Build with Gradle
run: |
chmod +x ./gradlew
./gradlew build -x test
env:
DB_HOST: ${{ secrets.DB_HOST }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
envs: DB_HOST,DB_USERNAME,DB_PASSWORD
environment: |
DB_HOST=${{ secrets.DB_HOST }}
DB_USERNAME=${{ secrets.DB_USERNAME }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
script: |
echo "DB_HOST=${{ secrets.DB_HOST }}" >> ~/.profile
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ~/.profile
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ~/.profile
source ~/.profile
sudo systemctl restart spring-app
- name: Copy JAR
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: "build/libs/*.jar"
target: "/home/ubuntu/app"
strip_components: 2
- name: Restart Spring Boot App
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
sudo systemctl restart spring-app