Skip to content

Commit

Permalink
feat: ci/cd 구축
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjookang committed Oct 24, 2024
1 parent 5f8d529 commit 6cc7bc8
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Java CD with Gradle

on:
push:
branches: [ "main" ]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Connect to EC2 via SSH
uses: appleboy/ssh-action@master
env:
APPLICATION_YML: ${{ secrets.APPLICATION_YML }}
APPLICATION_TEST_YML: ${{ secrets.APPLICATION_TEST_YML }}
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script_stop: true
envs: APPLICATION_YML, APPLICATION_TEST_YML
# git clone 같은 초기 작업은 ec2에서 먼저 진행
script: |
cd /home/server/purelabel/PureLabel
git switch dev
git pull origin dev
rm -rf src/main/resources/application.yml
mkdir -p src/main/resources
echo "$APPLICATION_YML" > src/main/resources/application.yml
rm -rf src/test/resources/application.yml
mkdir -p src/test/resources
echo "$APPLICATION_TEST_YML" > src/test/resources/application.yml
chmod +x gradlew
./gradlew clean
./gradlew build
sudo fuser -k -n tcp "${{ secrets.SERVER_PORT }}" || true
nohup java -jar build/libs/*SNAPSHOT.jar > ./output.log 2>&1 &
59 changes: 59 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Java CI with Gradle

#dev 브랜치로 pr할 때 CI 적용
on:
pull_request:
branches: [ "main" ]
types: [ opened, synchronize ]
push: # push 이벤트 발생 시
branches: # 타겟 브랜치
- main

#build 작업
jobs:
build:
#작업이 실행될 환경 지정
runs-on: ubuntu-latest
permissions:
contents: read
#각 단계가 순자적으로 진행
steps:
- uses: actions/checkout@v4
#JDK 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Create main resources directory
run: mkdir -p src/main/resources

- name: Create test resources directory
run: mkdir -p src/test/resources

# main의 application.yml 생성
- name: Set Release YML File
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
# test의 application.yml 생성
- name: Set Release Test YML File
run: |
cd ./src/test/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_TEST_YML }}" > ./application.yml
#Gradle 설정 및 의존성 다운
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

#Permission Denied 해결
- name: Make gradlew executable
run: chmod +x ./gradlew

#빌드 작업 실행(테스트도 같이 진행)
- name: Build with Gradle Wrapper
run: ./gradlew build

0 comments on commit 6cc7bc8

Please sign in to comment.