-
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 #77 from capstone-five-ai/dev
Prod 서버 CD 테스트
- Loading branch information
Showing
46 changed files
with
2,490 additions
and
301 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,62 @@ | ||
name: deploy on prod server | ||
|
||
on: | ||
push: | ||
branches: [test/main-cd] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 체크아웃 | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
|
||
- name: 서브모듈 업데이트 | ||
run: | | ||
git submodule update --remote | ||
- name: JDK 11 설치 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'corretto' | ||
java-version: '11' | ||
cache: 'gradle' | ||
|
||
- name: Gradle에 실행 권한 부여 | ||
run: chmod +x gradlew | ||
|
||
- name: 빌드 | ||
run: ./gradlew build -x test | ||
|
||
- name: DockerHub 로그인 | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Docker 이미지 빌드 & DockerHub에 Push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile-prod | ||
push: true | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:prod | ||
|
||
- name: EC2 서버에 배포 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.PROD_SERVER_HOST }} | ||
username: ${{ secrets.PROD_SERVER_USERNAME }} | ||
key: ${{ secrets.PROD_SERVER_PEM_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker stop $(sudo docker ps -a -q) | ||
sudo docker rm $(sudo docker ps -a -q) | ||
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod | ||
sudo docker run -d -p 8080:8080 --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server:prod | ||
sudo docker image prune -f |
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,62 @@ | ||
name: deploy on stage server | ||
|
||
on: | ||
push: | ||
branches: [dev] | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 체크아웃 | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
|
||
- name: 서브모듈 업데이트 | ||
run: | | ||
git submodule update --remote | ||
- name: JDK 11 설치 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'corretto' | ||
java-version: '11' | ||
cache: 'gradle' | ||
|
||
- name: Gradle에 실행 권한 부여 | ||
run: chmod +x gradlew | ||
|
||
- name: 빌드 | ||
run: ./gradlew build -x test | ||
|
||
- name: DockerHub 로그인 | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Docker 이미지 빌드 & DockerHub에 Push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./docker/Dockerfile-stg | ||
push: true | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/qtudy-server:latest | ||
|
||
- name: EC2 서버에 배포 | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.STG_SERVER_HOST }} | ||
username: ${{ secrets.STG_SERVER_USERNAME }} | ||
key: ${{ secrets.STG_SERVER_PEM_KEY }} | ||
envs: GITHUB_SHA | ||
script: | | ||
sudo docker stop $(sudo docker ps -a -q) | ||
sudo docker rm $(sudo docker ps -a -q) | ||
sudo docker pull ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server | ||
sudo docker run -d -p 8080:8080 --network="host" --name qtudy-server-container ${{secrets.DOCKERHUB_USERNAME}}/qtudy-server | ||
sudo docker image prune -f |
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,38 @@ | ||
name: run test | ||
|
||
on: | ||
pull_request: | ||
branches: [main, dev] | ||
types: [opened, synchronize, reopened] | ||
|
||
permissions: | ||
checks: write | ||
pull-requests: write | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 체크아웃 | ||
uses: actions/checkout@v4 | ||
|
||
- name: JDK 11 설치 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'corretto' | ||
java-version: '11' | ||
cache: 'gradle' | ||
|
||
- name: Gradle에 실행 권한 부여 | ||
run: chmod +x gradlew | ||
|
||
- name: Test 실행 | ||
run: ./gradlew clean test | ||
|
||
- name: Test 결과를 PR에 코멘트로 등록 | ||
uses: EnricoMi/publish-unit-test-result-action@v2 | ||
if: always() | ||
with: | ||
files: '**/build/test-results/test/TEST-*.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,23 @@ | ||
version: 0.0 | ||
os: linux | ||
files: | ||
- source: / | ||
destination: /home/ubuntu | ||
overwrite: yes | ||
|
||
permissions: | ||
- object: /home/ubuntu | ||
pattern: "**" | ||
owner: ubuntu | ||
group: ubuntu | ||
|
||
hooks: | ||
AfterInstall: | ||
- location: scripts/shutdown-prev-application.sh | ||
timeout: 120 | ||
runas: ubuntu | ||
|
||
ApplicationStart: | ||
- location: scripts/build-and-run-new-application.sh | ||
timeout: 120 | ||
runas: ubuntu |
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
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 amazoncorretto:11-alpine-jdk | ||
EXPOSE 8080 | ||
COPY ./build/libs/Qtudy-server-0.0.1-SNAPSHOT.jar /app.jar | ||
CMD ["java", "-jar", "app.jar", "--spring.profiles.active=deploy"] |
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 amazoncorretto:11-alpine-jdk | ||
EXPOSE 8080 | ||
COPY ./build/libs/Qtudy-server-0.0.1-SNAPSHOT.jar /app.jar | ||
CMD ["java", "-jar", "app.jar", "--spring.profiles.active=stage"] |
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,5 @@ | ||
PROJECT_PATH=/home/ubuntu/Qtudy-BE | ||
BUILD_PATH=$PROJECT_PATH/build/libs | ||
BUILD_JAR=$BUILD_PATH/Qtudy-server-0.0.1-SNAPSHOT.jar | ||
|
||
nohup java -jar $BUILD_JAR --spring.profiles.active=stage > $PROJECT_PATH/nohup.out 2>&1 & |
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,7 @@ | ||
JAVA_PID=`sudo lsof -i :8080 -t` | ||
if [ -z $JAVA_PID ] | ||
then echo "실행되고 있는 애플리케이션이 없습니다." | ||
else | ||
sudo kill -9 $JAVA_PID | ||
echo "기존에 실행되고 있던 애플리케이션을 종료했습니다." | ||
fi |
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
6 changes: 5 additions & 1 deletion
6
src/main/java/com/app/domain/categorizedproblem/repository/CategorizedProblemRepository.java
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
package com.app.domain.categorizedproblem.repository; | ||
|
||
import com.app.domain.categorizedproblem.entity.CategorizedProblem; | ||
import feign.Param; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface CategorizedProblemRepository extends JpaRepository<CategorizedProblem, Long> { | ||
boolean existsByCategoryCategoryIdAndProblemProblemId(Long categoryId, Long problemId); | ||
|
||
boolean existsByProblemProblemId(Long problemId); | ||
|
||
Page<CategorizedProblem> findByCategoryCategoryId(Long categoryId, Pageable pageable); | ||
@Query(value = "SELECT cp FROM CategorizedProblem cp JOIN FETCH cp.problem p JOIN FETCH cp.category c WHERE c.categoryId = :categoryId", | ||
countQuery = "SELECT count(cp) FROM CategorizedProblem cp WHERE cp.category.categoryId = :categoryId") | ||
Page<CategorizedProblem> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable); | ||
|
||
List<CategorizedProblem> findByCategoryCategoryId(Long categoryId); | ||
} |
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
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
6 changes: 5 additions & 1 deletion
6
src/main/java/com/app/domain/categorizedsummary/repository/CategorizedSummaryRepository.java
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 |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package com.app.domain.categorizedsummary.repository; | ||
|
||
import com.app.domain.categorizedsummary.entity.CategorizedSummary; | ||
import feign.Param; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface CategorizedSummaryRepository extends JpaRepository<CategorizedSummary, Long> { | ||
boolean existsByCategoryCategoryIdAndSummarySummaryId(Long categoryId, Long summaryId); | ||
|
||
boolean existsBySummarySummaryId(Long summaryId); | ||
|
||
Page<CategorizedSummary> findByCategoryCategoryId(Long categoryId, Pageable pageable); | ||
@Query(value = "SELECT cs FROM CategorizedSummary cs JOIN FETCH cs.summary s JOIN FETCH cs.category c WHERE c.categoryId = :categoryId", | ||
countQuery = "SELECT count(cs) FROM CategorizedSummary cs WHERE cs.category.categoryId = :categoryId") | ||
Page<CategorizedSummary> findByCategoryCategoryId(@Param("categoryId") Long categoryId, Pageable pageable); | ||
} |
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
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
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
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
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
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
Oops, something went wrong.