Update ci.cd.prod.yml #13
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: CI/CD | |
on: | |
push: | |
branches: [ main ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: Setup application properties | |
run: | | |
echo "${{ secrets.APPLICATION_KEY }}" > ./src/main/resources/application-key.properties | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: easyLeadServer | |
path: build/libs/easyLeadServer-0.0.1-SNAPSHOT.jar | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get current time | |
uses: josStorer/[email protected] | |
id: current-time | |
with: | |
format: YYYY-MM-DDTHH-mm-ss | |
utcOffset: "+09:00" | |
- name: Download build artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: easyLeadServer | |
path: ./artifact/ | |
- name: EC2 Deploy | |
env: | |
EC2_SSH_PRIVATE_KEY: ${{ secrets.EC2_KEY }} | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
EC2_USER: ${{ secrets.EC2_USER }} | |
run: | | |
# SSH Key 파일 생성 | |
echo "$EC2_SSH_PRIVATE_KEY" > ec2_ssh_key | |
chmod 600 ec2_ssh_key | |
# 패키지 파일을 EC2 인스턴스로 복사 | |
scp -i ec2_ssh_key -o StrictHostKeyChecking=no artifact/easyLeadServer-0.0.1-SNAPSHOT.jar ${EC2_USER}@${EC2_HOST}:/home/${EC2_USER}/easylead-server | |
# 인스턴스에서 JAR 파일 실행 | |
ssh -i ec2_ssh_key -o StrictHostKeyChecking=no ${EC2_USER}@${EC2_HOST} "pgrep java | xargs kill -9; nohup java -jar /home/${EC2_USER}/easylead-server/easyLeadServer-0.0.1-SNAPSHOT.jar > /home/${EC2_USER}/easylead-server/log/app.log 2>&1 &" |