Skip to content

Update ci.cd.prod.yml #10

Update ci.cd.prod.yml

Update ci.cd.prod.yml #10

Workflow file for this run

name: Java CI with Gradle
on:
push:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: make application-key.properties
run: |
cd ./src/main/resources
touch ./application-key.properties
echo "${{ secrets.APPLICATION_KEY }}" > ./application-key.properties
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Build with Gradle
#uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
#with:
#arguments: build
run : ./gradlew clean build --exclude-task test
# 빌드해서 생긴 JAR 파일을 깃허브 아티팩트로 업로드!!
- 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: build/libs/
- 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 build/libs/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 &"