Skip to content

Commit

Permalink
서버를 무중단 배포할 수 있게 한다. (#11)
Browse files Browse the repository at this point in the history
commit 33a9606
Author: alstn113 <[email protected]>
Date:   Wed Jan 8 16:19:39 2025 +0900

    feat: deploy 스크립트 사용

commit 51ec497
Author: alstn113 <[email protected]>
Date:   Wed Jan 8 16:19:23 2025 +0900

    refactor: 컨테이너 이름 변경 및 blue, green 컨테이너로 변경

commit d734939
Author: alstn113 <[email protected]>
Date:   Wed Jan 8 16:18:58 2025 +0900

    feat: spring actuator 의존성 추가

commit 989b1bb
Author: alstn113 <[email protected]>
Date:   Wed Jan 8 16:18:38 2025 +0900

    feat: container switching shell script

commit 9ea9ac5
Author: alstn113 <[email protected]>
Date:   Wed Jan 8 10:27:09 2025 +0900

    docs: 서비스 개발 블로그 주소를 등록한다.

commit cad802e
Author: alstn113 <[email protected]>
Date:   Sat Jan 4 11:24:40 2025 +0900

    refactor: V1__init.sql format

commit 40e31a9
Author: alstn113 <[email protected]>
Date:   Fri Jan 3 14:13:29 2025 +0900

    feat: question template에 passage textarea를 추가한다.

commit 85aa0fe
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 17:44:04 2025 +0900

    feat: 시험 제출 후 결과로 이동

commit 2e2cecb
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 17:19:02 2025 +0900

    feat: question passage 필드 추가

commit 5b6751e
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 16:31:22 2025 +0900

    refactor: question의 passage 필드에 관련된 테스트 코드를 수정한다.

commit 81b5226
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 16:30:56 2025 +0900

    feat: question에 passage 필드를 추가하고 관련된 것들을 수정한다.

commit e5d421b
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 14:18:17 2025 +0900

    feat: question entity에 passage column 추가

commit 924c1ce
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 13:56:27 2025 +0900

    docs: 서버, API 명세서, 웹 주소를 추가한다.

commit 03f7869
Author: alstn113 <[email protected]>
Date:   Thu Jan 2 13:52:27 2025 +0900

    refactor: issue template에 불필요한 이모티콘을 제거한다.

commit 47d716c
Author: alstn113 <[email protected]>
Date:   Wed Jan 1 20:44:01 2025 +0900

    refactor: CardBody의 공통 부분을 통일하고 분리한다.
  • Loading branch information
alstn113 committed Jan 8, 2025
1 parent 95ab2e2 commit 8c6612e
Show file tree
Hide file tree
Showing 55 changed files with 1,257 additions and 2,951 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ body:
- type: markdown
attributes:
value: |
버그 신고를 작성해주셔서 감사합니다! 🙏
버그 신고를 작성해주셔서 감사합니다!
- type: textarea
id: what-happened
attributes:
label: 어떤 일이 발생했나요? 🤔
label: 어떤 일이 발생했나요?
description: 또한, 어떤 결과를 기대했었는지 알려주세요.
placeholder: 예상치 못한 버그가 발생했습니다...
validations:
Expand All @@ -31,8 +31,8 @@ body:
- type: checkboxes
id: terms
attributes:
label: 동의 👍
label: 동의
description: 아래 항목을 모두 확인하고 체크해주세요.
options:
- label: 다른 이슈가 있는지 확인했습니다.
- label: 다른 이슈가 있는지 확인했습니다.
required: true
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ body:
- type: markdown
attributes:
value: |
새로운 기능을 제안해주셔서 감사합니다! 🙏
새로운 기능을 제안해주셔서 감사합니다!
- type: textarea
id: new-feature
attributes:
label: 어떤 기능을 제안하시나요? 🤔
description: 이 새로운 기능으로 어떤 효과를 기대하시나요? 🚀
label: 어떤 기능을 제안하시나요?
description: 이 새로운 기능으로 어떤 효과를 기대하시나요?
placeholder: 이 기능이 있으면 좋겠다면, 이유를 적어주세요...
validations:
required: true
- type: textarea
id: how
attributes:
label: 이 기능은 어떻게 구현할 수 있을까요? 🛠️
description: 필요한 기술 스택이나 구현 방법 등을 알려주세요. 💻
label: 이 기능은 어떻게 구현할 수 있을까요?
description: 필요한 기술 스택이나 구현 방법 등을 알려주세요.
placeholder: 이러한 방법으로 구현할 수 있습니다...
- type: checkboxes
id: terms
attributes:
label: 동의 👍
label: 동의
description: 아래 항목을 모두 확인하고 체크해주세요.
options:
- label: 다른 이슈가 있는지 확인했습니다.
- label: 다른 이슈가 있는지 확인했습니다.
required: true
6 changes: 4 additions & 2 deletions .github/workflows/server_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ jobs:
- name: View
run: cat .env

- name: Compose Docker image
- name: Compose Docker image and Update Nginx configuration
env:
DOCKER_APP_IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}

run: docker compose -f compose.yml up -d
run: |
chmod +x ./scripts/deploy.sh # 실행 권한 부여
sudo -E ./scripts/deploy.sh # 환경 변수 유지 및 실행
- name: Docker remove unused images
run: docker image prune -af
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
# 플러피, 온라인 시험 문제 제작 및 관리 서비스
# 플러피(Fluffy), 온라인 시험 문제 제작 및 관리 서비스

**▷ 개발 기간 : 2024.11 ~ 현재</br>**
**▷ 개발 인원 : 1명**

## Server
## 프로젝트 소개

플러피(Fluffy)는 온라인 시험 문제 제작 및 관리 서비스입니다.

## 프로젝트 개요

- 서버 주소: https://api.fluppy.run
- API 명세서: https://api.fluffy.run/docs/index.html
- 웹 프론트엔드 주소: https://fluppy.run
- 서비스 개발 블로그: https://alstn113.tistory.com/tag/플러피

## 서버

### 기술 스택

Expand All @@ -12,7 +23,7 @@
- redis
- supabase(postgreSQL)

## Web Frontend
## 웹 프론트엔드

### 기술 스택

Expand Down
3 changes: 3 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dependencies {
annotationProcessor 'jakarta.annotation:jakarta.annotation-api'
annotationProcessor 'jakarta.persistence:jakarta.persistence-api'

// monitoring
implementation 'org.springframework.boot:spring-boot-starter-actuator'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
2 changes: 1 addition & 1 deletion server/compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
redis:
container_name: fluffy-redis
container_name: redis
image: redis:7.4.1
restart: always
ports:
Expand Down
34 changes: 22 additions & 12 deletions server/compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
x-app: &app
image: ${DOCKER_APP_IMAGE}
env_file:
- .env
environment:
TZ: Asia/Seoul
SPRING_PROFILES_ACTIVE: prod
restart: always
depends_on:
- redis

services:
app:
container_name: fluffy-app
image: ${DOCKER_APP_IMAGE}
ports:
- '8080:8080'
env_file:
- .env
environment:
TZ: Asia/Seoul
SPRING_PROFILES_ACTIVE: prod
restart: always
redis:
container_name: fluffy-redis
container_name: redis
image: redis:7.4.1
restart: always
ports:
- '6379:6379'
app-blue:
<<: *app
container_name: app-blue
ports:
- '8080:8080'
app-green:
<<: *app
container_name: app-green
ports:
- '8081:8080'
50 changes: 50 additions & 0 deletions server/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

NGINX_CONFIG_PATH="/etc/nginx/sites-available/api.fluffy.run"
HOST_HEALTH_CHECK_ENDPOINT="http://localhost:8082/actuator/health"
HEALTH_CHECK_ATTEMPTS=5
HEALTH_CHECK_DELAY=3

health_check() {
for i in $(seq 1 $HEALTH_CHECK_ATTEMPTS); do
echo "Health check attempt ($i/$HEALTH_CHECK_ATTEMPTS)"
response=$(curl -s -o /dev/null -w "%{http_code}" $HOST_HEALTH_CHECK_ENDPOINT)

if [ $response -eq 200 ]; then
echo "Health check passed"
return 0
fi

sleep $HEALTH_CHECK_DELAY
done

echo "Health check failed"
return 1
}

switch_container() {
local prev_container=$1
local next_container=$2

docker compose -f compose.yml up $next_container -d

if ! health_check; then
echo "Health check failed, rolling back"
docker compose -f compose.yml down $next_container
return 1
fi

sed -i "s/server $prev_container:8080;/server $next_container:8080;/" "$NGINX_CONFIG_PATH"

sudo nginx -s reload
}

IS_GREEN=$(docker container ps | grep app-green)

if [ -z "$IS_GREEN" ]; then
echo "### BLUE >> GREEN ###"
switch_container "app-blue" "app-green"
else
echo "### GREEN >> BLUE ###"
switch_container "app-green" "app-blue"
fi
Loading

0 comments on commit 8c6612e

Please sign in to comment.