Dev (#762) #12
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: Caucse QA Java CI/DE with Gradle(qa branch) | |
on: | |
push: | |
branches: [ "qa" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
name: Build in Github Actions | |
runs-on: ubuntu-22.04 | |
steps: | |
# 작업 엑세스 가능하게 $GITHUB_WORKSPACE에서 저장소를 체크아웃 | |
- name: Checkout branch | |
uses: actions/checkout@v3 | |
# java 버전 세팅(JDK 17) | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'zulu' | |
# git ignore한 yml 파일들 github secret에서 복사해 오기 | |
- name: Copy secret | |
env: | |
APPLICATION_FILE: ${{ secrets.APPLICATION_PROFILE_QA }} | |
APPLICATION_QA_FILE: ${{ secrets.APPLICATION_QA }} | |
DIR: ./src/main/resources | |
APPLICATION_FILE_NAME: application.yml | |
APPLICATION_QA_FILE_NAME: application-qa.yml | |
run: | | |
touch $DIR/$APPLICATION_FILE_NAME | |
touch $DIR/$APPLICATION_QA_FILE_NAME | |
echo "$APPLICATION_FILE" > $DIR/$APPLICATION_FILE_NAME | |
echo "$APPLICATION_QA_FILE" > $DIR/$APPLICATION_QA_FILE_NAME | |
# gradlew 실행 권한 부여 | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
shell: bash | |
# Build -> jar 파일 생성 | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test | |
shell: bash | |
- name: Upload Build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: | | |
build/libs/*.jar | |
deploy: | |
name: CD with SSH | |
needs: build | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Download build artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
# JAR 파일을 EC2에 배포하는 step | |
- name: SCP JAR to EC2 | |
uses: appleboy/scp-action@master | |
with: | |
key: ${{ secrets.EC2_KEY_QA }} | |
host: ${{ secrets.EC2_HOST_QA }} | |
username: ${{ secrets.EC2_USER_QA }} | |
source: "*.jar" | |
target: "/home/ubuntu/app" | |
# 전체 프로젝트 코드 Github Actions에서 어떻게 Build 되고, 업로드 될 지 Debugging 원할 시 주석 해제 | |
# - name: Upload project code | |
# uses: appleboy/scp-action@master | |
# with: | |
# key: ${{ secrets.EC2_KEY_QA }} | |
# host: ${{ secrets.EC2_HOST_QA }} | |
# username: ${{ secrets.EC2_USER_QA }} | |
# target: /home/ubuntu/app/spring_source | |
# source: . | |
# Redis Server 구동 | |
- name: Start redis-server | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.EC2_KEY_QA }} | |
host: ${{ secrets.EC2_HOST_QA }} | |
username: ${{ secrets.EC2_USER_QA }} | |
script: | | |
sudo systemctl start redis-server | |
# EC2에 SSH로 배포 커맨드를 입력하는 step | |
- name: Deploy SSH | |
uses: appleboy/ssh-action@master | |
with: | |
key: ${{ secrets.EC2_KEY_QA }} | |
host: ${{ secrets.EC2_HOST_QA }} | |
username: ${{ secrets.EC2_USER_QA }} | |
# 기존 실행 중인 서버 종료 후 jar 파일 실행 | |
script: | | |
sudo fuser -k -n tcp 8080 | |
sleep 15 | |
sudo nohup java -jar /home/ubuntu/app/*.jar > ./nohup.out 2>&1 & | |