Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JT-59] feat: CD 무중단 배포 구현 #22

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jtoon-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: JToon CI/CD
name: JToon CI actions

on:
push:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/jtoon-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: JToon CI/CD
name: JToon deployment

on:
push:
branches: [ "main" ]

permissions:
contents: read
contents: write

jobs:
build:
Expand All @@ -20,13 +20,13 @@ jobs:
VERSION=$(grep -o -E "v[0-9]+\.[0-9]+\.[0-9]+" <<< "${{ github.event.head_commit.message }}")
echo "VERSION=${VERSION}" >> $GITHUB_ENV

- name: Github release 생성
uses: actions/create-release@v1
with:
tag_name: ${{ env.VERSION }}
release_name: JTOON - ${{ env.VERSION }}
- name: Github release 자동생성
uses: action-pack/github-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ env.VERSION }}
title: JTOON - ${{ env.VERSION }}

- name: JDK 17 설정
uses: actions/setup-java@v3
Expand Down
4 changes: 2 additions & 2 deletions infrastructure/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ services:
container_name: jtoon-blue
restart: always
expose:
- 8080
- ${SERVER_PORT}
jtoon-green:
image: ${DOCKER_HUB_USERNAME}/${DOCKER_HUB_REPOSITORY}:latest
container_name: jtoon-green
restart: always
expose:
- 8080
- ${SERVER_PORT}
18 changes: 18 additions & 0 deletions infrastructure/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"id": "${id}",
"execute-command": "${execute-command}",
"command-working-directory": "${command-working-directory}",
"response-message": "${response-message}",
"trigger-rule": {
"match": {
"type": "value",
"value": "${value}",
"parameter": {
"source": "url",
"name": "${parameter}"
}
}
}
}
]
10 changes: 10 additions & 0 deletions infrastructure/hooks.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# /etc/systemd/system/hooks.service

[Unit]
Description=jtoon-auto-deploy-endpoint

[Service]
ExecStart=webhook -hooks ${HOOKS_JSON_PATH} -port ${HOOKS_PORT} --verbose

[Install]
WantedBy=multi-user.target
8 changes: 4 additions & 4 deletions infrastructure/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
upstream jtoon-server{
server jtoon-blue:8080;
upstream jtoon{
server jtoon-blue:${SERVER_PORT};
}

server {
listen 80;
server_name api.jtoon.shop;
server_name ${JTOON_SERVER_DOMAIN};

location / {
proxy_pass http://jtoon-server;
proxy_pass http://jtoon;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand Down
9 changes: 5 additions & 4 deletions infrastructure/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

IS_BLUE=$(docker ps | grep jtoon-blue)

NGINX_CONF="./nginx/nginx.conf"
NGINX_CONF="${PWD}/nginx/nginx.conf"

docker-compose up -d nginx

if [ $IS_BLUE ];then
if [ -n "$IS_BLUE" ]; then
echo "### BLUE => GREEN ###"
echo "1. jtoon-green 이미지 가져오고 실행"
docker-compose pull jtoon-green
docker-compose up -d jtoon-green
while [ 1 = 1 ]; do
echo "2. jtoon-green health check"
sleep 5
REQUEST=$(docker exec nginx curl http://jtoon-green:8080)
REQUEST=$(docker exec nginx curl http://jtoon-green:${SERVER_PORT})
if [ -n "$REQUEST" ]; then
echo "health check 성공"
break;
Expand All @@ -33,13 +33,14 @@ else
while [ 1 = 1 ]; do
echo "2. jtoon-blue health check"
sleep 5
REQUEST=$(docker exec nginx curl http://jtoon-blue:8080)
REQUEST=$(docker exec nginx curl http://jtoon-blue:${SERVER_PORT})
if [ -n "$REQUEST" ]; then
echo "health check 성공"
break;
fi
done;
sed -i 's/jtoon-green/jtoon-blue/g' $NGINX_CONF
echo $NGINX_CONF
echo "3. nginx 설정파일 reload"
docker exec nginx service nginx reload
echo "4. jtoon-green 컨테이너 종료"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import static com.devtoon.jtoon.security.util.SecurityConstant.*;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.devtoon.jtoon.security.application.AuthService;
import com.devtoon.jtoon.security.request.LogInReq;
import com.devtoon.jtoon.security.response.LoginRes;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,4 +30,8 @@ public void login(@RequestBody @Valid LogInReq logInReq, HttpServletResponse res
response.setHeader(ACCESS_TOKEN_HEADER, BEARER_VALUE + loginRes.accessToken());
response.setHeader(REFRESH_TOKEN_HEADER, BEARER_VALUE + loginRes.refreshToken());
}

@GetMapping
@ResponseStatus(HttpStatus.OK)
public void healthCheck() { /* HealthCheck 용 Root Path */ }
}