-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/ssu-Recipable/BackEnd in…
…to develop
- Loading branch information
Showing
11 changed files
with
301 additions
and
27 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 |
---|---|---|
|
@@ -14,7 +14,7 @@ assignees: '' | |
|
||
--- | ||
|
||
### 📝 Todo | ||
### 📝 Todo(중간 체크용) | ||
|
||
- [ ] : 구현할 내용 1 | ||
- [ ] : 구현할 내용 2 |
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,88 @@ | ||
name: Java CI & CD with Gradle | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
# pull_request: | ||
# branches: [ "develop" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: application.yml 설정 | ||
run: | | ||
cd ./src/main | ||
mkdir resources | ||
cd ./resources | ||
touch ./application.yml | ||
echo "$APPLICATION_MAIN" > ./application.yml | ||
env: | ||
APPLICATION_MAIN: ${{ secrets.APPLICATION_MAIN }} | ||
|
||
|
||
# gradle build | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew build -x test | ||
|
||
|
||
## 웹 이미지 빌드 및 도커허브에 push | ||
- name: web docker build and push | ||
run: | | ||
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | ||
docker build -t ${{ secrets.DOCKER_REPO }}/capstone . | ||
docker push ${{ secrets.DOCKER_REPO }}/capstone | ||
## deploy.sh 파일 서버로 전달하기(복사 후 붙여넣기) | ||
- name: Send deploy.sh | ||
uses: appleboy/scp-action@master | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.HOST }} | ||
key: ${{ secrets.KEY }} | ||
port: 22 | ||
source: "./scripts/" | ||
target: "/home/ubuntu/" | ||
|
||
|
||
## docker-compose.yml 파일을 EC2 development server로 전달 | ||
- name: Send docker-compose.yml | ||
uses: appleboy/scp-action@master | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.HOST }} | ||
key: ${{ secrets.KEY }} | ||
port: 22 | ||
source: "./docker-compose.yml" | ||
target: "/home/ubuntu/" | ||
|
||
|
||
## 도커 허브에서 jar파일 및 pull후에 컴포즈 up | ||
- name: Deploy to Dev | ||
uses: appleboy/ssh-action@master | ||
with: | ||
username: ubuntu | ||
host: ${{ secrets.HOST }} | ||
key: ${{ secrets.KEY }} | ||
script: | | ||
sudo docker pull ${{ secrets.DOCKER_REPO }}/capstone | ||
chmod 777 ./scripts/deploy.sh | ||
cp ./scripts/deploy.sh ./deploy.sh | ||
./deploy.sh | ||
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 |
---|---|---|
|
@@ -35,3 +35,5 @@ out/ | |
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
application.yml |
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-alpine | ||
ARG JAR_FILE=./build/libs/recipable-0.0.1-SNAPSHOT.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java","-jar","app.jar"] |
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 +1,75 @@ | ||
# BackEnd | ||
## 🔀 Git-Flow | ||
- 각자의 feature branch에서 작업한 후, develop branch로 merge합니다. | ||
- {브랜치 종류}/{이슈 번호}/{대표적인 내용 or 기능 도메인명} 순으로 작명합니다. | ||
- `ex) feat/3/login` | ||
|
||
## 💬 Commit Convention | ||
Commit Convention을 따르는 것을 지향하되 유동적으로 변경하셔도 됩니다. | ||
|
||
|작업 태그|설명| | ||
|------|---| | ||
|`feat`|새로운 기능 추가 / 일부 코드 추가 / 일부 코드 수정 (리팩토링과 구분) / 디자인 요소 수정| | ||
|`fix`|버그 수정| | ||
|`refactor`|코드 리팩토링| | ||
|`style`|코드 의미에 영향을 주지 않는 변경사항 (코드 포맷팅, 오타 수정, 변수명 변경, 에셋 추가)| | ||
|`chore`|빌드 부분 혹은 패키지 매니저 수정 사항 / 파일 이름 변경 및 위치 변경 / 파일 삭제| | ||
|`docs`|문서 추가 및 수정| | ||
|`rename`|패키지 혹은 폴더명, 클래스명 수정 (단독으로 시행하였을 시)| | ||
|`remove`|패키지 혹은 폴더, 클래스를 삭제하였을 때 (단독으로 시행하였을 시)| | ||
|
||
- `ex) [feat] : 로그인 기능 구현` | ||
|
||
## Project Structure | ||
package 구조는 아래 패키지 구조를 따릅니다. 때에 따라 유동적으로 변경해도 상관없습니다. | ||
|
||
``` | ||
├── domain | ||
│ ├── member | ||
│ │ ├── api | ||
│ │ │ └── MemberApi.java | ||
│ │ ├── application | ||
│ │ │ ├── MemberProfileService.java | ||
│ │ │ ├── MemberSearchService.java | ||
│ │ │ ├── MemberSignUpService.java | ||
│ │ ├── repository | ||
│ │ │ ├── MemberRepository.java | ||
│ │ │ ├── MemberSupportRepository.java | ||
│ │ │ └── MemberSupportRepositoryImpl.java | ||
│ │ ├── domain | ||
│ │ │ ├── MemberEntity.java | ||
│ │ ├── dto | ||
│ │ │ ├── LoginRequest.java | ||
│ │ │ └── LoginResponse.java | ||
│ │ └── exception | ||
│ │ ├── EmailNotFoundException.java | ||
│ │ └── MemberNotFoundException.java | ||
│ │ | ||
│ │ | ||
├── global | ||
│ ├── config | ||
│ │ ├── SwaggerConfig.java | ||
│ │ ├── properties | ||
│ │ └── security | ||
│ │ | ||
│ ├── ApiResponse.java | ||
│ ├── error | ||
│ │ ├── code | ||
│ │ ├── BaseCode.java | ||
│ │ ├── BaseCodeError.java | ||
│ │ ├── dto | ||
│ │ ├── ErrorReasonDto.java | ||
│ │ ├── ReasonDto.java | ||
│ │ ├── exception | ||
│ │ ├── ExceptionAdvice.java | ||
│ │ ├── GeneralException.java | ||
│ │ └── status | ||
│ │ ├── ErrorStatus.java | ||
│ │ ├── SuccessStatus.java | ||
│ ├── util | ||
``` | ||
|
||
|
||
|
||
[//]: # (## Deploy) | ||
|
||
[//]: # (Ec2 + Github Actions + Docker + Nginx - Blue/Green으로 진행합니다.) |
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,20 @@ | ||
version: '3' | ||
services: | ||
blue: | ||
container_name: blue | ||
image: chahs1012/capstone | ||
expose: | ||
- 8080 | ||
ports: | ||
- 8080:8080 | ||
environment: | ||
- TZ=Asia/Seoul | ||
green: | ||
container_name: green | ||
image: chahs1012/capstone | ||
expose: | ||
- 8080 | ||
ports: | ||
- 8081:8080 | ||
environment: | ||
- TZ=Asia/Seoul |
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,51 @@ | ||
#!/bin/bash | ||
|
||
IS_GREEN_EXIST=$(docker ps | grep green) | ||
DEFAULT_CONF=" /etc/nginx/nginx.conf" | ||
|
||
# blue가 실행 중이면 green을 up합니다. | ||
if [ -z $IS_GREEN_EXIST ];then | ||
echo "### BLUE => GREEN ####" | ||
echo ">>> green image를 pull합니다." | ||
docker-compose pull green | ||
echo ">>> green container를 up합니다." | ||
docker-compose up -d green | ||
while [ 1 = 1 ]; do | ||
echo ">>> green health check 중..." | ||
sleep 3 | ||
REQUEST=$(curl http://127.0.0.1:8081) | ||
if [ -n "$REQUEST" ]; then | ||
echo ">>> 🍃 health check success !" | ||
break; | ||
fi | ||
done; | ||
sleep 3 | ||
echo ">>> nginx를 다시 실행 합니다." | ||
sudo cp /etc/nginx/nginx.green.conf /etc/nginx/nginx.conf | ||
sudo nginx -s reload | ||
echo ">>> blue container를 down합니다." | ||
docker-compose stop blue | ||
|
||
# green이 실행 중이면 blue를 up합니다. | ||
else | ||
echo "### GREEN => BLUE ###" | ||
echo ">>> blue image를 pull합니다." | ||
docker-compose pull blue | ||
echo ">>> blue container up합니다." | ||
docker-compose up -d blue | ||
while [ 1 = 1 ]; do | ||
echo ">>> blue health check 중..." | ||
sleep 3 | ||
REQUEST=$(curl http://127.0.0.1:8080) | ||
if [ -n "$REQUEST" ]; then | ||
echo ">>> 🍃 health check success !" | ||
break; | ||
fi | ||
done; | ||
sleep 3 | ||
echo ">>> nginx를 다시 실행 합니다." | ||
sudo cp /etc/nginx/nginx.blue.conf /etc/nginx/nginx.conf | ||
sudo nginx -s reload | ||
echo ">>> green container를 down합니다." | ||
docker-compose stop green | ||
fi |
12 changes: 12 additions & 0 deletions
12
src/main/java/capstone/recipable/domain/HealthCheckApi.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package capstone.recipable.domain; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class HealthCheckApi { | ||
@GetMapping("/health-check") | ||
public String hello() { | ||
return "Hello, Recipable!"; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/capstone/recipable/global/config/SwaggerConfig.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package capstone.recipable.global.config; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@OpenAPIDefinition( | ||
info = @io.swagger.v3.oas.annotations.info.Info( | ||
title = "Recipable's API Specifications" | ||
,description = "캡스톤 종합 디자인 프로젝트 2" | ||
, version = "v1") | ||
) | ||
public class SwaggerConfig { | ||
private static final String BEARER_TOKEN_PREFIX = "Bearer"; | ||
private static final String JWT = "JWT"; | ||
@Bean | ||
public OpenAPI openAPI() { | ||
SecurityRequirement securityRequirement = new SecurityRequirement().addList(JWT); | ||
Components components = new Components().addSecuritySchemes(JWT, new SecurityScheme() | ||
.name(JWT) | ||
.type(SecurityScheme.Type.HTTP) | ||
.scheme(BEARER_TOKEN_PREFIX) | ||
.bearerFormat(JWT) | ||
); | ||
return new OpenAPI() | ||
.components(new Components()) | ||
.info(new Info()) | ||
.addSecurityItem(securityRequirement) | ||
.components(components); | ||
} | ||
} | ||
|
||
|