-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Nexters/dev
[feature-2] CI/CD 구축
- Loading branch information
Showing
4 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## #️⃣연관된 이슈 | ||
|
||
> ex) #이슈번호, #이슈번호 | ||
## 📝작업 내용 | ||
|
||
> 이번 PR에서 작업한 내용을 간략히 설명해주세요(이미지 첨부 가능) | ||
### 스크린샷 (선택) | ||
|
||
## 💬리뷰 요구사항(선택) | ||
|
||
> 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 | ||
> | ||
> ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요? |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: CD | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
permissions: write-all #테스트 결과 작성을 위해 쓰기권한 추가 | ||
|
||
jobs: | ||
# 빌드 | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
#jdk 세팅 | ||
- name: check out | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
#gradle 캐싱 | ||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
### CD | ||
#배포를 위한 prod properties 설정 | ||
- name: Make application-prod.properties | ||
run: | | ||
cd ./src/main/resources | ||
touch ./application-prod.properties | ||
echo "${{ secrets.PROPERTIES_PROD }}" > ./application-prod.properties | ||
shell: bash | ||
|
||
#test를 제외한 프로젝트 빌드 | ||
- name: Build With Gradle | ||
run: ./gradlew build -x test | ||
# 도커 | ||
docker: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/donmani:latest | ||
|
||
# 배포 | ||
deploy: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy to Prod | ||
uses: appleboy/ssh-action@master | ||
id: deploy-prod | ||
with: | ||
host: ${{ secrets.SERVER_IP }} | ||
username: ${{ secrets.SERVER_USER }} | ||
key: ${{ secrets.SERVER_PASSWORD }} | ||
envs: GITHUB_SHA | ||
script: | | ||
docker stop donmani | ||
docker rm donmani | ||
sudo docker pull ${{ secrets.DOCKER_HUB_USERNAME }}/donmani | ||
docker run -d --name donmani -p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/donmani | ||
docker rmi -f $(docker images -f "dangling=true" -q) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
name: Java CI with Gradle | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- dev | ||
|
||
permissions: write-all # 테스트 결과 작성을 위해 쓰기 권한 추가 | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
mysql: | ||
image: mysql:8 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: testdb | ||
MYSQL_USER: testuser | ||
MYSQL_PASSWORD: testpassword | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd="mysqladmin ping --host=localhost --user=testuser --password=testpassword" | ||
--health-interval=10s | ||
--health-timeout=10s | ||
--health-retries=5 | ||
env: | ||
SPRING_DATASOURCE_URL: jdbc:mysql://localhost:3306/testdb | ||
SPRING_DATASOURCE_USERNAME: testuser | ||
SPRING_DATASOURCE_PASSWORD: testpassword | ||
SPRING_JPA_DATABASE_PLATFORM: org.hibernate.dialect.MySQL8Dialect | ||
|
||
steps: | ||
# JDK 세팅 | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
# Gradle 캐싱 | ||
- name: Gradle Caching | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
# CI | ||
- name: Grant Execute Permission For Gradlew | ||
run: chmod +x gradlew | ||
|
||
# MySQL이 제대로 실행되도록 대기 (선택 사항) | ||
- name: Wait for MySQL to be ready | ||
run: sleep 15 | ||
|
||
# 테스트를 제외한 프로젝트 빌드 | ||
- name: Build With Gradle | ||
run: ./gradlew build -x test | ||
|
||
# 테스트 실행 | ||
- name: Build With Test | ||
run: ./gradlew test | ||
|
||
# 테스트 결과 파일 생성 | ||
- name: Publish Unit Test Results | ||
uses: EnricoMi/publish-unit-test-result-action@v1 | ||
if: ${{ always() }} | ||
with: | ||
files: build/test-results/**/*.xml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:17-ea-11-jdk-slim | ||
ARG JAR_FILE=./build/libs/donmani_server-0.0.1-SNAPSHOT.jar | ||
COPY ${JAR_FILE} donmani_server.jar | ||
ENTRYPOINT ["java", "-jar", "/donmani_server.jar", "--spring.profiles.active=prod"] |