Skip to content

Commit

Permalink
Create cicd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
CEO-Nick authored Apr 18, 2024
1 parent 7870175 commit 6ded76b
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workfows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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'

# application.properties 파일 설정
- name: Setup application properties
run: |
echo "${{ secrets.APPLICATION }}" > ./src/main/resources/application.properties
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run : ./gradlew clean build -x test

# 빌드해서 생긴 JAR 파일을 깃허브 아티팩트로 업로드!!
- name: Upload build artifact
uses: actions/upload-artifact@v2
with:
name: linkeepServer
path: build/libs/linkeepServer-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: linkeepServer
path: build/libs/
- name: EC2 Deploy
env:
EC2_SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_PRIVATE_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/linkeepServer-0.0.1-SNAPSHOT.jar ${EC2_USER}@${EC2_HOST}:/home/${EC2_USER}/linkeep-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}/linkeep-server/linkeepServer-0.0.1-SNAPSHOT.jar > /home/${EC2_USER}/linkeep-server/log/app.log 2>&1 &"
# java -jar /home/${EC2_USER}/linkeep-server/linkeepServer-0.0.1-SNAPSHOT.jar
# # EC2 인스턴스에서 배포 스크립트 실행
# ssh -i ec2_ssh_key -o StrictHostKeyChecking=no ${EC2_USER}@${EC2_HOST} "cd /home/${EC2_USER}/linkeep-server && ./deploy_script.sh"

0 comments on commit 6ded76b

Please sign in to comment.