From 5ab906e6954caf3df324d063d8ac4f8c269d28a0 Mon Sep 17 00:00:00 2001 From: Dev Uni Date: Sun, 10 Sep 2023 22:55:06 +0900 Subject: [PATCH] =?UTF-8?q?[JT-59]=20feat:=20CD=20=EB=AC=B4=EC=A4=91?= =?UTF-8?q?=EB=8B=A8=20=EB=B0=B0=ED=8F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/jtoon-ci.yml | 2 +- .github/workflows/jtoon-deploy.yml | 14 +++++++------- infrastructure/docker-compose.yml | 4 ++-- infrastructure/hooks.json | 18 ++++++++++++++++++ infrastructure/hooks.service | 10 ++++++++++ infrastructure/nginx/nginx.conf | 8 ++++---- infrastructure/scripts/deploy.sh | 9 +++++---- .../security/presentation/AuthController.java | 8 ++++++++ 8 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 infrastructure/hooks.json create mode 100644 infrastructure/hooks.service diff --git a/.github/workflows/jtoon-ci.yml b/.github/workflows/jtoon-ci.yml index 21f5d6b4..f88ff672 100644 --- a/.github/workflows/jtoon-ci.yml +++ b/.github/workflows/jtoon-ci.yml @@ -1,4 +1,4 @@ -name: JToon CI/CD +name: JToon CI actions on: push: diff --git a/.github/workflows/jtoon-deploy.yml b/.github/workflows/jtoon-deploy.yml index 7e64a915..a4d23856 100644 --- a/.github/workflows/jtoon-deploy.yml +++ b/.github/workflows/jtoon-deploy.yml @@ -1,11 +1,11 @@ -name: JToon CI/CD +name: JToon deployment on: push: branches: [ "main" ] permissions: - contents: read + contents: write jobs: build: @@ -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 diff --git a/infrastructure/docker-compose.yml b/infrastructure/docker-compose.yml index 861e46f8..507c660e 100644 --- a/infrastructure/docker-compose.yml +++ b/infrastructure/docker-compose.yml @@ -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} diff --git a/infrastructure/hooks.json b/infrastructure/hooks.json new file mode 100644 index 00000000..cece825f --- /dev/null +++ b/infrastructure/hooks.json @@ -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}" + } + } + } + } +] diff --git a/infrastructure/hooks.service b/infrastructure/hooks.service new file mode 100644 index 00000000..86d0a8bd --- /dev/null +++ b/infrastructure/hooks.service @@ -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 \ No newline at end of file diff --git a/infrastructure/nginx/nginx.conf b/infrastructure/nginx/nginx.conf index 4065409f..b0f9f8bb 100644 --- a/infrastructure/nginx/nginx.conf +++ b/infrastructure/nginx/nginx.conf @@ -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; diff --git a/infrastructure/scripts/deploy.sh b/infrastructure/scripts/deploy.sh index 1d84043f..95a5ab43 100644 --- a/infrastructure/scripts/deploy.sh +++ b/infrastructure/scripts/deploy.sh @@ -2,11 +2,11 @@ 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 @@ -14,7 +14,7 @@ if [ $IS_BLUE ];then 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; @@ -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 컨테이너 종료" diff --git a/module-application/src/main/java/com/devtoon/jtoon/security/presentation/AuthController.java b/module-application/src/main/java/com/devtoon/jtoon/security/presentation/AuthController.java index 23b8befd..8e2708a6 100644 --- a/module-application/src/main/java/com/devtoon/jtoon/security/presentation/AuthController.java +++ b/module-application/src/main/java/com/devtoon/jtoon/security/presentation/AuthController.java @@ -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; @@ -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 */ } }