Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/ssu-Recipable/BackEnd in…
Browse files Browse the repository at this point in the history
…to develop
  • Loading branch information
Jeongho427 committed May 1, 2024
2 parents 7d4872a + 10f325c commit 3c4dac2
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/-issue-생성-템플릿.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ assignees: ''

---

### 📝 Todo
### 📝 Todo(중간 체크용)

- [ ] : 구현할 내용 1
- [ ] : 구현할 내용 2
27 changes: 4 additions & 23 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
### ✅ PR 유형
어떤 변경 사항이 있었나요?

- [ ] 새로운 기능 추가
- [ ] 버그 수정
- [ ] 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
- [ ] 코드 리팩토링
- [ ] 주석 추가 및 수정
- [ ] 문서 수정
- [ ] 빌드 부분 혹은 패키지 매니저 수정
- [ ] 파일 혹은 폴더명 수정
- [ ] 파일 혹은 폴더 삭제
### ✏️ 관련 이슈
본인이 작업한 내용이 어떤 Issue Number와 관련이 있는지만 작성해주세요

- #13

---

Expand All @@ -21,17 +13,6 @@

---

### ✏️ 관련 이슈(선택 사항)
본인이 작업한 내용이 어떤 Issue Number와 관련이 있는지만 작성해주세요

ex)
- Fixes : #00 (수정중인 이슈)
- Resolves : #100 (무슨 이슈를 해결했는지)
- Ref : #00 #01 (참고할 이슈)
- Related to : #00 #01 (해당 커밋과 관려)

---

### 🎸 기타 사항 or 추가 코멘트


Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/cicd.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ out/

### VS Code ###
.vscode/

application.yml
4 changes: 4 additions & 0 deletions Dockerfile
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"]
76 changes: 75 additions & 1 deletion README.md
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으로 진행합니다.)
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

//security
// implementation 'org.springframework.boot:spring-boot-starter-security'

Expand All @@ -33,13 +36,13 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'

//db
// runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.mysql:mysql-connector-j'

//validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// testImplementation 'org.springframework.security:spring-security-test'
}

tasks.named('test') {
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
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
51 changes: 51 additions & 0 deletions scripts/deploy.sh
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 src/main/java/capstone/recipable/domain/HealthCheckApi.java
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 src/main/java/capstone/recipable/global/config/SwaggerConfig.java
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);
}
}


0 comments on commit 3c4dac2

Please sign in to comment.