[CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ข Application Docker Health Check)

2023. 7. 6. 17:25ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

 

 




๐Ÿ—‚ ๋ชฉ์ฐจ

โš ๏ธ ์•„๋ž˜ ๋ชฉ์ฐจ ์ค‘ ๋ช‡๋ช‡๊ฐœ์˜ ๋งํฌ๊ฐ€ ๊ฑธ๋ฆฌ์ง€ ์•Š๋Š” ๋ฌธ์ œ๋กœ ๊ธ€ ๋งจ ํ•˜๋‹จ์— ๋‹ค์Œ ๊ธ€๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ๋‘์—ˆ์Šต๋‹ˆ๋‹ค.

โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™
โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ
โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™
โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ 
โœ… [DevOps] JAVA Gradle JaCoCo (Code coverage) ์„ค์ •ํ•˜๊ธฐ (์ถ”๊ฐ€)(https://junyharang.tistory.com/392)

โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘  Application Linuxt(Ubuntu)์— SSH๋ฅผ ์ด์šฉํ•œ ํŒŒ์ผ ์ „์†ก
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ก Create Docker Image And BackUp
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘  Application ๋„์ปค ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)(https://junyharang.tistory.com/406)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ข Application Docker Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘  NGINX ๊ฐ ์ข… ์„ค์ •) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ก NGINX Docker ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ) 
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX Docker Run & Health Check)
โœ… [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘ข NGINX ์žฌ ์„ค์ •)



๐Ÿค” ๋‚ด๊ฐ€ ๋งŒ๋‚œ ๋ฌธ์ œ

โ›”๏ธ [Jenkins] java.lang.OutOfMemoryError: Java heap space

 




 

 

๋ฐฐํฌ ์ž๋™ํ™”์™€ ์ง€์†์  ์ธ๋„:๋„์ปค์™€ ์  ํ‚จ์Šค ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋กœ ๋งŒ๋“œ๋Š”

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

 

 

๐Ÿš€ Application Docker Health Check

    ๐Ÿ”ฝ ๊ฐœ์š”

        ๐Ÿ“ฆ ๊ตฌ์„ฑ๋„

CI/CD ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๊ตฌ์„ฑ๋„

 

deploy Directory Path

 

 

 

 

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ง€๋‚œ ๊ธ€์—์„œ ์ฃผ๋‹ˆ๋Š” Application Docker Container๋ฅผ ๊ธฐ๋™ ์‹œํ‚ค๊ณ , ์ •์ƒ์ ์œผ๋กœ ๊ธฐ๋™์ด ๋˜์—ˆ๋Š”์ง€๊นŒ์ง€ ํ™•์ธํ•˜์˜€์–ด์š”.

Spring Boot๋Š” ๊ฒฐ๊ตญ Web Application Service์ด๊ณ , curl ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ•ด๋‹น ์›น ์„œ๋น„์Šค๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™ ์ค‘์ธ์ง€
ํ™•์ธํ•ด์„œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ฐฐํฌ๋ฅผ ๋งˆ๋ฌด๋ฆฌ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

 

 

 

    ๐Ÿ”ฝ applicationHealthCheck.sh

#!/bin/bash

set -e

NOW=$(date +"%y-%m-%d_%H:%M:%S")
SAVE_LOG_DATE=$(date +"%y-%m-%d")

echo "====================================================================================================="
echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์„œ๋ฒ„ ์ž‘์—… ์ค‘ Application Health Check ์ž‘์—…์ด ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”."
echo "======================================[$NOW] ํ†ตํ•ฉ ๋ฐฑ ์˜คํ”ผ์Šค api Application Health Check======================================"
echo "[$NOW] [INFO] Author(๋งŒ๋“ ์ด): ์ฃผ๋‹ˆ(junyharang8592@gmail.com)"

APPLICATION_DOCKER_IMAGE_NAME="giggal-people/total-back-office-api"

APPLICATION_MAIN_CONTAINER_NAME="giggal-total-back-office-api-main"
APPLICATION_SUB_CONTAINER_NAME="giggal-total-back-office-api-sub"

APPLICATION_MAIN_EXTERNAL_PORT_NUMBER=1001
APPLICATION_SUB_EXTERNAL_PORT_NUMBER=1011

SERVER_IP=192.168.20.12

APPLICATION_SHELL_SCRIPT_DIRECTORY="/data/deploy/giggal-total-back-office/deploy/prod/was/shell-script/application"

checkLogDirectory() {
  sleep 5

  LOG_DIR="/var/log/deploy/giggal-total-back-office"

  if [ -d "$LOG_DIR" ]; then
    echo "=====================================================================================================" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์„œ๋ฒ„ ์ž‘์—… ์ค‘ Application Health Check ์ž‘์—…์ด ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "======================================[$NOW] ํ†ตํ•ฉ ๋ฐฑ ์˜คํ”ผ์Šค api Application Health Check======================================" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[$NOW] [INFO] Author(๋งŒ๋“ ์ด): ์ฃผ๋‹ˆ(junyharang8592@gmail.com)" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[$NOW] [INFO] LOG Directory ์กด์žฌ ํ•ฉ๋‹ˆ๋‹ค."
    echo "[$NOW] [INFO] LOG Directory ์กด์žฌ ํ•ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  else
    echo "[$NOW] [INFO] cicd-admin์€ mkdir ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์š”. ๊ด€๋ฆฌ์ž ํ˜น์€ DMSO ํฌ๋ฃจ์—๊ฒŒ ${LOG_DIR} ์ƒ์„ฑ์„ ์š”์ฒญํ•ด ์ฃผ์„ธ์š”. ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    exit 1
  fi

  applicationContainerHealthCheck
}

applicationContainerHealthCheck() {
  sleep 5

  for loopCount in {1..2}; do
    echo "[$NOW] [INFO] Application Container ๊ธฐ๋™ ์ƒํƒœ ํ™•์ธํ• ๊ฒŒ์š”."
    echo "[$NOW] [INFO] Application Container ๊ธฐ๋™ ์ƒํƒœ ํ™•์ธํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

    MAIN_CONTAINER_STATUS=$(docker ps --filter "name=$APPLICATION_MAIN_CONTAINER_NAME" --format "{{.Status}}")
    SUB_CONTAINER_STATUS=$(docker ps --filter "name=$APPLICATION_SUB_CONTAINER_NAME" --format "{{.Status}}")

    echo "[$NOW] [INFO] Application Container MAIN ๊ธฐ๋™ ์ƒํƒœ ์ •๋ณด : $MAIN_CONTAINER_STATUS"
    echo "[$NOW] [INFO] Application Container MAIN ๊ธฐ๋™ ์ƒํƒœ ์ •๋ณด : $MAIN_CONTAINER_STATUS" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[$NOW] [INFO] Application Container SUB ๊ธฐ๋™ ์ƒํƒœ ์ •๋ณด : $SUB_CONTAINER_STATUS"
    echo "[$NOW] [INFO] Application Container SUB ๊ธฐ๋™ ์ƒํƒœ ์ •๋ณด : $SUB_CONTAINER_STATUS" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

    echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ Application Container ๊ธฐ๋™ ์ƒํƒœ ํ™•์ธ"
    echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ Application Container ๊ธฐ๋™ ์ƒํƒœ ํ™•์ธ" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    if [[ $MAIN_CONTAINER_STATUS == "Up"* ]] && [[ "$SUB_CONTAINER_STATUS" == "Up"* ]]; then
      echo "[$NOW] [INFO] Application Container MAIN PORT ๋ฒˆํ˜ธ : $APPLICATION_MAIN_EXTERNAL_PORT_NUMBER"
      echo "[$NOW] [INFO] Application Container MAIN PORT ๋ฒˆํ˜ธ : $APPLICATION_MAIN_EXTERNAL_PORT_NUMBER" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
      echo "[$NOW] [INFO] Application Container SUB PORT ๋ฒˆํ˜ธ : $APPLICATION_SUB_EXTERNAL_PORT_NUMBER"
      echo "[$NOW] [INFO] Application Container SUB PORT ๋ฒˆํ˜ธ : $APPLICATION_SUB_EXTERNAL_PORT_NUMBER" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      if [[ $MAIN_CONTAINER_STATUS == "Up"* ]] && [ $loopCount == 1 ]; then
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด Application Container MAIN ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ์ •์ƒ์ž„์„ ํ™•์ธํ•˜์˜€์–ด์š”."
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด Application Container MAIN ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ์ •์ƒ์ž„์„ ํ™•์ธํ•˜์˜€์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationExternalPortNumber=$APPLICATION_SUB_EXTERNAL_PORT_NUMBER
        containerName="giggal-total-back-office-api-sub"

      elif [[ "$SUB_CONTAINER_STATUS" == "Up"* ]] && [ $loopCount == 2 ]; then
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด Application Container SUB ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ์ •์ƒ์ž„์„ ํ™•์ธํ•˜์˜€์–ด์š”."
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์„ ํ†ตํ•ด Application Container SUB ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ์ •์ƒ์ž„์„ ํ™•์ธํ•˜์˜€์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationExternalPortNumber=$APPLICATION_MAIN_EXTERNAL_PORT_NUMBER
        containerName="giggal-total-back-office-api-main"

      else
        echo "[$NOW] [ERROR] Application Container ์ƒํƒœ ํ™•์ธ ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”. Application ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ๋‹ค์‹œ ํ™•์ธํ• ๊ฒŒ์š”."
        echo "[$NOW] [ERROR] Application Container ์ƒํƒœ ํ™•์ธ ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”. Application ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ๋‹ค์‹œ ํ™•์ธํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        $APPLICATION_SHELL_SCRIPT_DIRECTORY/applicationCheckContainerExistenceStatus.sh
      fi

      echo "[$NOW] [INFO] ${containerName} Health Check ์‹œ์ž‘ํ• ๊ฒŒ์š”."
      echo "[$NOW] [INFO] ${containerName} Health Check ์‹œ์ž‘ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
      echo "[$NOW] [INFO] ์‚ฌ์šฉ ๋ช…๋ น์–ด: curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep -oP 'HTTP/1.1 \K\d+' "
      echo "[$NOW] [INFO] ์‚ฌ์šฉ ๋ช…๋ น์–ด: curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep -oP 'HTTP/1.1 \K\d+' " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      for retryCount in {1..10};
      do
        sleep 5
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ http ์ •์ƒ ์—ฐ๊ฒฐ ํ™•์ธ ${retryCount} ๋ฒˆ์งธ Health Check ์ž‘์—… ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”."
        echo "[$NOW] [INFO] ${loopCount} ๋ฒˆ์งธ ๋ฐ http ์ •์ƒ ์—ฐ๊ฒฐ ํ™•์ธ ${retryCount} ๋ฒˆ์งธ Health Check ์ž‘์—… ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        responseCode=$(curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep -oP 'HTTP/1.1 \K\d+')
        command="curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep -oP 'HTTP/1.1 \K\d+'"

        if [ "$responseCode" == "200" ]; then
          successCommand "${command}"

        else
          echo "[$NOW] [WARN] ${containerName}๊ฐ€ ๊ธฐ๋™ ์ค‘์ด์ง€๋งŒ, ๋‚ด๋ถ€ ์„œ๋น„์Šค์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
          echo "[$NOW] [WARN] ${containerName}๊ฐ€ ๊ธฐ๋™ ์ค‘์ด์ง€๋งŒ, ๋‚ด๋ถ€ ์„œ๋น„์Šค์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
          echo "[$NOW] [WARN] ${containerName} ์‚ญ์ œ ๋ฐ ์žฌ ๊ธฐ๋™ ์‹ค์‹œํ•ฉ๋‹ˆ๋‹ค."
          echo "[$NOW] [WARN] ${containerName} ์‚ญ์ œ ๋ฐ ์žฌ ๊ธฐ๋™ ์‹ค์‹œํ•ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          applicationDockerContainerChangeOldErrorRemove "${containerName}"
        fi

        responseCount=$(curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep "HTTP" | wc -l)
        command="curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile | grep "HTTP" | wc -l"

        if [ ${responseCount} -ge 1 ]; then
          echo "[$NOW] [INFO] ${containerName} Container ์ƒํƒœ๊ฐ€ ์ •์ƒ์ด์—์š”."
          echo "[$NOW] [INFO] ${containerName} Container ์ƒํƒœ๊ฐ€ ์ •์ƒ์ด์—์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          successCommand "${command}"
          break

        else
          errorResponse=$(curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile)

          echo "[$NOW] [ERROR] ${containerName} Container ์ƒํƒœ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
          echo "[$NOW] [ERROR] ${containerName} Container ์ƒํƒœ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
          echo "[$NOW] [ERROR] ๋ฌธ์ œ ๋‚ด์šฉ : ${errorResponse}"
          echo "[$NOW] [ERROR] ๋ฌธ์ œ ๋‚ด์šฉ : ${errorResponse}" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          echo "[$NOW] [ERROR] ${containerName} Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”."
          echo "[$NOW] [ERROR] ${containerName} Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          applicationDockerContainerChangeOldErrorRemove "${containerName}"
        fi

        if [ "${retryCount}" -eq 10 ]; then
          echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
          echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          echo "[$NOW] [ERROR] ${containerName} Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”."
          echo "[$NOW] [ERROR] ${containerName} Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

          applicationDockerContainerChangeOldErrorRemove "${containerName}"
        fi

        echo "[$NOW] [WARN] Health Check ์ž‘์—…์— ์‹คํŒจํ•˜์˜€์–ด์š”."
        echo "[$NOW] [WARN] Health Check ์ž‘์—…์— ์‹คํŒจํ•˜์˜€์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        echo "[$NOW] [ERROR] Nginx ์—ฐ๊ฒฐ ์—†์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ข…๋ฃŒ ํ•ฉ๋‹ˆ๋‹ค."
        echo "[$NOW] [ERROR] Nginx ์—ฐ๊ฒฐ ์—†์ด ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ข…๋ฃŒ ํ•ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        exit 1
      done

    else
      if [[ $MAIN_CONTAINER_STATUS != "Up"* ]] && [[ $SUB_CONTAINER_STATUS != "Up"* ]]; then

        echo "[$NOW] [ERROR] ๋ชจ๋“  Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
        echo "[$NOW] [ERROR] ๋ชจ๋“  Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        containerName=$APPLICATION_MAIN_CONTAINER_NAME
        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”."
        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationDockerContainerChangeOldErrorRemove "${containerName}"

        containerName=$APPLICATION_SUB_CONTAINER_NAME
        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”."
        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationDockerContainerChangeOldErrorRemove "${containerName}"

      elif [[ $MAIN_CONTAINER_STATUS != "Up"* ]]; then
        containerName=$APPLICATION_MAIN_CONTAINER_NAME
        echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
        echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        echo "[$NOW] [ERROR] ${containerName} Container ์žฌ ๊ธฐ๋™ ์‹œ๋„ํ• ๊ฒŒ์š”."
        echo "[$NOW] [ERROR] ${containerName} Container ์žฌ ๊ธฐ๋™ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationDockerContainerChangeOldErrorRemove "${containerName}"

      elif [[ $SUB_CONTAINER_STATUS != "Up"* ]]; then
        containerName=$APPLICATION_SUB_CONTAINER_NAME
        echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”."
        echo "[$NOW] [ERROR] ${containerName} Container Health ์ƒํƒœ ๋ฌธ์ œ๊ฐ€ ์žˆ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”."
        echo "[$NOW] [ERROR] ${containerName} ๋ฌธ์ œ ์žˆ๋Š” Container ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์‹œ๋„ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        applicationDockerContainerChangeOldErrorRemove "${containerName}"

      else
        echo "[$NOW] [ERROR] Application Container ์ƒํƒœ ํ™•์ธ ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”. ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค."
        echo "[$NOW] [ERROR] Application Container ์ƒํƒœ ํ™•์ธ ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์–ด์š”. ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ข…๋ฃŒ๋ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
        exit 1
      fi
    fi
  done
}

applicationDockerContainerChangeOldErrorRemove() {
  local containerName=$1

  echo "[$NOW] [INFO] ๊ธฐ์กด์— ๋™์ž‘ํ•˜๋˜ ์ •์ƒ ๊ตฌ๋™ ์ค‘์ด์ง€ ์•Š์€ ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] ๊ธฐ์กด์— ๋™์ž‘ํ•˜๋˜ ์ •์ƒ ๊ตฌ๋™ ์ค‘์ด์ง€ ์•Š์€ ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  if [ "$containerName" == "$APPLICATION_MAIN_CONTAINER_NAME" ]; then
    portNumber=$APPLICATION_MAIN_EXTERNAL_PORT_NUMBER
    stopContainerName="giggal-total-back-office-api-main"
    stopContainerId=$(docker ps --filter "name=$stopContainerName" --format "{{.ID}}")

  else
    portNumber=$APPLICATION_SUB_EXTERNAL_PORT_NUMBER
    stopContainerName="giggal-total-back-office-api-sub"
    stopContainerId=$(docker ps --filter "name=$stopContainerName" --format "{{.ID}}")
  fi

  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜ ์ •๋ณด : "
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜ ์ •๋ณด : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ๋ฐ Host Name : ${containerName} "
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ ๋ฐ Host Name : ${containerName} : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ Port Number : ${portNumber} "
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ Port Number : ${portNumber} : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ Docker Image Name : ${APPLICATION_DOCKER_IMAGE_NAME} "
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ Docker Image Name : ${APPLICATION_DOCKER_IMAGE_NAME} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐํ•  ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ : ${stopContainerName} "
  echo "[$NOW] [INFO] ${containerName} ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐํ•  ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„ : ${stopContainerName} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐํ•  ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ID : ${stopContainerId} "
  echo "[$NOW] [INFO] ${containerName} ์ข…๋ฃŒ ๋ฐ ์ œ๊ฑฐํ•  ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ID : ${stopContainerId} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  echo "[$NOW] [INFO] ๊ธฐ์กด์— ๋™์ž‘ํ•˜๋˜ ์ •์ƒ ๊ตฌ๋™ ์ค‘์ด์ง€ ์•Š์€ ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ ์ž‘์—…์„ ์‹œ์ž‘ํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] ๊ธฐ์กด์— ๋™์ž‘ํ•˜๋˜ ์ •์ƒ ๊ตฌ๋™ ์ค‘์ด์ง€ ์•Š์€ ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ข…๋ฃŒ ์ž‘์—…์„ ์‹œ์ž‘ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  command="docker stop $stopContainerId"

  if ! docker stop $stopContainerId; then
    failedCommand "${command}"
  else
    successCommand "${command}"

    command="docker rm $stopContainerId"

    if ! docker rm $stopContainerId; then
      failedCommand "${command}"
    else
      successCommand "${command}"

      unknownNameImageDelete

      applicationDockerContainerRun "${containerName}"
    fi
  fi
}

applicationDockerContainerRun() {
  local containerName=$1

  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ํ†ตํ•ด docker ๊ธฐ๋™ ๋ช…๋ น์–ด ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์„ ์‹œ์ž‘ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  if [ "$containerName" == "$APPLICATION_MAIN_CONTAINER_NAME" ]; then
    containerAndHostName="giggal-total-back-office-api-main"
    portNumber=$APPLICATION_MAIN_EXTERNAL_PORT_NUMBER

  else
    containerAndHostName="giggal-total-back-office-api-sub"
    portNumber=$APPLICATION_SUB_EXTERNAL_PORT_NUMBER
  fi

  echo "[$NOW] [INFO] ์„ค์ •๋œ ๋ณ€์ˆ˜ ์ •๋ณด: "
  echo "[$NOW] [INFO] ์„ค์ •๋œ ๋ณ€์ˆ˜ ์ •๋ณด: " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] Container Name And Container Host Name : ${containerAndHostName} "
  echo "[$NOW] [INFO] Container Name And Container Host Name : ${containerAndHostName} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] Container Port Number : ${portNumber} "
  echo "[$NOW] [INFO] Container Port Number : ${portNumber} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  dockerRunCommand="docker run -itd --privileged --name $containerAndHostName --hostname $containerAndHostName -e container=docker -p $portNumber:8080 --restart unless-stopped $APPLICATION_DOCKER_IMAGE_NAME"

  if ! docker run -itd --privileged --name $containerAndHostName --hostname $containerAndHostName -e container=docker -p $portNumber:8080 --restart unless-stopped $APPLICATION_DOCKER_IMAGE_NAME;
  then
    failedCommand "${dockerRunCommand}"
  else
    successCommand "${dockerRunCommand}"

    containerId=$(docker ps --filter "name=$containerAndHostName" --format "{{.ID}}")

    echo "[$NOW] [INFO] Container ID : ${containerId} "
    echo "[$NOW] [INFO] Container ID : ${containerId} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  fi

  echo "[$NOW] [INFO] ๊ธฐ๋™ ์‹œํ‚จ Container ${containerAndHostName} (ID: ${containerId}) ๋™์ž‘ ์ƒํƒœ ํ™•์ธํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] ๊ธฐ๋™ ์‹œํ‚จ Container ${containerAndHostName} (ID: ${containerId}) ๋™์ž‘ ์ƒํƒœ ํ™•์ธํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  checkContainerStatus=$(docker ps --filter "id=$containerId" --format "{{.Status}}")

  sleep 5

  containerLogs=$(docker logs "$containerId")

  if [[ $checkContainerStatus == "Up"* ]]; then
    echo "[$NOW] [INFO] ๊ธฐ๋™ ์‹œํ‚จ Container ๋‚ด๋ถ€ Log ์ •๋ณด : "
    echo "[$NOW] [INFO] ๊ธฐ๋™ ์‹œํ‚จ Container ๋‚ด๋ถ€ Log ์ •๋ณด : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[$NOW] [INFO] $containerLogs"
    echo "[$NOW] [INFO] $containerLogs" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

    successCommand "docker ps --filter "id=$containerId" --format "{{.Status}}" "

    applicationContainerHealthCheck

  else
    echo "[$NOW] [ERROR] ๋ฌธ์ œ ๋ฐœ์ƒํ•œ Container ๋‚ด๋ถ€ Log ์ •๋ณด : "
    echo "[$NOW] [ERROR] ๋ฌธ์ œ ๋ฐœ์ƒํ•œ Container ๋‚ด๋ถ€ Log ์ •๋ณด : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "[$NOW] [ERROR] $containerLogs"
    echo "[$NOW] [ERROR] $containerLogs" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    failedCommand "docker ps --filter "id=$containerId" --format "{{.Status}}" "
  fi
}

unknownNameImageDelete() {
  sleep 5
  echo "[$NOW] [INFO] createDockerImageAndBackup.sh์—์„œ ์ œ๊ฑฐํ•˜์ง€ ๋ชปํ•œ ์ด๋ฆ„ ์—†๋Š” (๊ณ ์•„) Docker Image ์‚ญ์ œ ์ž‘์—… ์‹œ์ž‘ํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] createDockerImageAndBackup.sh์—์„œ ์ œ๊ฑฐํ•˜์ง€ ๋ชปํ•œ ์ด๋ฆ„ ์—†๋Š” (๊ณ ์•„) Docker Image ์‚ญ์ œ ์ž‘์—… ์‹œ์ž‘ํ• ๊ฒŒ์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  checkDockerImage

  if ! docker images | grep "^<none>"; then
    echo "[$NOW] [INFO] ์ด๋ฆ„ ์—†๋Š” (๊ณ ์•„) Docker Image๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”."
    echo "[$NOW] [INFO] ์ด๋ฆ„ ์—†๋Š” (๊ณ ์•„) Docker Image๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

    checkDockerImage

  else
    if ! docker rmi $(docker images -f "dangling=true" -q); then
      echo "[$NOW] [WARN] ์ด๋ฆ„ ์—†๋Š” Docker Image ์‚ญ์ œ ์ž‘์—… ์‹คํŒจํ•˜์˜€์–ด์š”. Server์— ์ ‘์†ํ•˜์—ฌ ์ง์ ‘ ์‚ญ์ œ ์ž‘์—…์ด ํ•„์š”ํ•ด์š”. ์Šคํฌ๋ฆฝํŠธ๋Š” ์ข…๋ฃŒ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."
      echo "[$NOW] [WARN] ์ด๋ฆ„ ์—†๋Š” Docker Image ์‚ญ์ œ ์ž‘์—… ์‹คํŒจํ•˜์˜€์–ด์š”. Server์— ์ ‘์†ํ•˜์—ฌ ์ง์ ‘ ์‚ญ์ œ ์ž‘์—…์ด ํ•„์š”ํ•ด์š”. ์Šคํฌ๋ฆฝํŠธ๋Š” ์ข…๋ฃŒ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค." >>$LOG_DIR/"$NOW"-createImageAndBackup.log 2>&1

      checkDockerImage

    else
      echo "[$NOW] [INFO] ์ด๋ฆ„ ์—†๋Š” Docker Image ์‚ญ์ œ ์ž‘์—… ์„ฑ๊ณตํ•˜์˜€์–ด์š”."
      echo "[$NOW] [INFO] ์ด๋ฆ„ ์—†๋Š” Docker Image ์‚ญ์ œ ์ž‘์—… ์„ฑ๊ณตํ•˜์˜€์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      checkDockerImage
    fi
  fi
}

checkDockerImage() {
  DOCKER_IMAGES_LIST=$(docker images)

  echo "[$NOW] [INFO] ํ˜„์žฌ ์กด์žฌํ•˜๋Š” Docker Image ๋‚ด์—ญ : "
  echo "[$NOW] [INFO] ํ˜„์žฌ ์กด์žฌํ•˜๋Š” Docker Image ๋‚ด์—ญ : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  echo "[$NOW] [INFO] ${DOCKER_IMAGES_LIST} "
  echo "[$NOW] [INFO] ${DOCKER_IMAGES_LIST} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
}

failedCommand() {
  local command=$1

  echo "[$NOW] [ERROR] ${command} ๋ช…๋ น์–ด ์ž‘์—… ์‹คํŒจํ•˜์˜€์–ด์š”. ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค."
  echo "[$NOW] [ERROR] ${command} ๋ช…๋ น์–ด ์ž‘์—… ์‹คํŒจํ•˜์˜€์–ด์š”. ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
  exit 1
}

successCommand() {
  local command=$1

  echo "[$NOW] [INFO] ${command} ๋ช…๋ น์–ด ์ž‘์—… ์„ฑ๊ณตํ•˜์˜€์–ด์š”."
  echo "[$NOW] [INFO] ${command} ๋ช…๋ น์–ด ์ž‘์—… ์„ฑ๊ณตํ•˜์˜€์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
}

checkLogDirectory

operationDockerStatus=$(docker ps -a)

echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์ž‘์—… ์ค‘ Application Health Check ์ž‘์—…์ด ๋๋‚ฌ์–ด์š”."
echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ LOG ์œ„์น˜ : ${LOG_DIR}"
echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์ž‘์—… ์ค‘ Application Health Check ์ž‘์—…์ด ๋๋‚ฌ์–ด์š”." >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
echo "[$NOW] [INFO] ํ˜„์žฌ ์šด์˜ ์ค‘์ธ Docker Container ์ •๋ณด : "
echo "[$NOW] [INFO] ํ˜„์žฌ ์šด์˜ ์ค‘์ธ Docker Container ์ •๋ณด : " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
echo "[$NOW] [INFO] ${operationDockerStatus} "
echo "[$NOW] [INFO] ${operationDockerStatus} " >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
echo -e "=====================================================================================================\n"
echo -e "=====================================================================================================\n" >>$LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
728x90




        ๐Ÿ“ฆ applicationContainerHealthCheck()

Log๋ฅผ ๋‚จ๊ธธ Directory๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” checkLogDirectory()๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ž‘์—…์„ ๋งˆ๋ฌด๋ฆฌํ•˜๋ฉด ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋˜๊ณ , ์ž‘์—…์ด ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.

applicationHealthCheck.sh 46 ~ 86๋ฒˆ์งธ ์ค„


์ตœ์ดˆ ์ด ๊ณณ์—์„œ๋Š” ํ™•์ธํ•ด์•ผ ํ•  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•ด ๋‹ค์‹œ ํ•œ๋ฒˆ ๊ธฐ๋™ ์ƒํƒœ๋ฅผ ํ™•์ธํ•ด์ฃผ๊ณ  ์žˆ์–ด์š”.

49๋ฒˆ์งธ ์ค„์— ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋‘ ๊ฐœ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜๋ณต๋ฌธ์„ ๋‘๋ฒˆ ๋Œ๋ ค์ฃผ๊ณ , 53, 54๋ฒˆ์งธ ์ค„์— MAIN๊ณผ SUB ์ปจํ…Œ์ด๋„ˆ์— ๋„์ปค ๊ธฐ๋™ ์ƒํƒœ ํ™•์ธ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๊ฐ๊ฐ์˜ ๋ณ€์ˆ˜์— ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค 63๋ฒˆ์งธ ์ค„์—์„œ ๋‘ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ ๋ชจ๋‘ Up์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ , 69์™€ 75๋ฒˆ์งธ ์ค„์—์„œ ๊ฐ๊ฐ์˜ ์ปจํ…Œ์ด๋„ˆ Health Check๋ฅผ ์œ„ํ•œ ๋ณ€์ˆ˜ ์„ค์ •์„ ์œ„ํ•ด ๋ฐ˜๋ณต ํšŸ์ˆ˜์™€ ํ•จ๊ป˜ ๊ฐ๊ฐ์˜ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๊ณ ,
๊ทธ์— ๋งž๋Š” ๋ณ€์ˆ˜๋ฅผ ๋„ฃ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.

๋งŒ์•ฝ 81๋ฒˆ์งธ ์ค„์— else ๋ฌธ์ด ์ฐธ์ด ๋˜๋ฉด 63๋ฒˆ์งธ ์ค„์—์„œ๋Š” ๋‘ ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋‘ ์ •์ƒ์ด๋ผ๊ณ  ํ™•์ธํ–ˆ๋Š”๋ฐ, ๊ฐ๊ฐ์˜ ๊ธฐ๋™ ์ƒํƒœ๋ฅผ ํ™•์ธํ–ˆ์„ ๋•Œ๋Š” ๋ฌธ์ œ๊ฐ€ ๋‚˜์˜จ ๊ฒƒ์ด๊ฑฐ๋‚˜, ๋ฐ˜๋ณต๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํŒ๋‹จํ•˜๊ณ , 85๋ฒˆ์งธ ์ค„์—์„œ applicationCheckContainerExistenceStatus.sh๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋‹ค์‹œ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๋Š” ๋“ฑ์˜ ์ด ์ „ ๊ธ€์—์„œ ์ •๋ฆฌํ–ˆ์—ˆ๋˜ ์ผ๋ จ์˜ ๊ณผ์ •์„ ๊ฑฐ์น  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.

applicationHealthCheck.sh 93 ~ 135๋ฒˆ์งธ ์ค„

 



๋ณธ๊ฒฉ์ ์œผ๋กœ Health Check๊ฐ€ ์ด๋ค„์ง€๋Š” ๋ถ€๋ถ„์ด์—์š”.

์ตœ์ดˆ 93๋ฒˆ์งธ ์ค„์—์„œ Health Check๋ฅผ ์ตœ๋Œ€ 10๋ฒˆ๊นŒ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฐ˜๋ณต๋ฌธ์„ 10๋ฒˆ ๋Œ๋ฆฌ๋„๋ก ํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค 98๋ฒˆ์งธ ์ค„์—์„œ curl -I ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Responce Status Code๋ฅผ responseCode ๋ณ€์ˆ˜์— ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.


์ฐธ๊ณ ๋กœ /api/test/profile๋กœ HTTP Request๋ฅผ ๋˜์ง€๊ฒŒ ๋˜๋ฉด


์œ„์˜ Controller Code์— ์˜ํ•ด์„œ ํ˜„์žฌ ๊ธฐ๋™์ค‘์ธ Spring Boot ๊ตฌ๋™ ํ™˜๊ฒฝ ๊ฐ’์ด ๋ฐ˜ํ™˜๋˜๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.


101๋ฒˆ์งธ ์ค„์—์„œ ์‘๋‹ต ์ฝ”๋“œ๊ฐ€ 200์œผ๋กœ ๋–จ์–ด์ง€๊ฒŒ ๋˜๋ฉด ์ •์ƒ์ด๊ธฐ ๋•Œ๋ฌธ์— 

์œ„์—์„œ ํ™•์ธํ•˜๊ณ ์ž ํ•˜๋Š” curl ๋ช…๋ น์–ด์— ๋Œ€ํ•œ ์ž‘์—…์€ ๋๋‚˜๊ฒŒ ๋˜์š”.

ํ•˜์ง€๋งŒ, ๋งŒ์•ฝ 200์œผ๋กœ ์˜ค์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๋Š” ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ๊ฐ„ ๊ฒƒ์ธ๋ฐ,
๋‚ด๋ถ€ ์Šคํ”„๋ง ๋ถ€ํŠธ ์„œ๋น„์Šค๊ฐ€ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๊ฑฐ๋‚˜,
๋„์ปค ์ปจํ…Œ์ด๋„ˆ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—
๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€ ๋ฐ ์‚ญ์ œ ์ž‘์—…์„ ๋‹ด๋‹นํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.


๋งŒ์•ฝ ์œ„์—์„œ ํ™•์ธํ•œ curl ๊ฒฐ๊ณผ๊ฐ€ 200์ด๋ผ๋ฉด ์ด๋ฒˆ์—๋Š” ๋‹ค์‹œ ํ•œ๋ฒˆ curl ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด HTTP ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , ์‘๋‹ต ํ—ค๋”์—์„œ HTTP๋ฅผ ํ•„ํ„ฐ๋งํ•œ ๋’ค ๊ทธ ๊ฐœ์ˆ˜๋ฅผ ์„ธ๋Š” ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‹ค์‹œ ํ•œ๋ฒˆ ํ™•์ธ์„ ํ•ด์ฃผ๊ฒŒ ํ•˜์˜€์–ด์š”. 

 

{"originWidth":1872,"originHeight":159,"style":"CDM","link":" grep \\","caption":"curl -I http://${SERVER_IP}:${applicationExternalPortNumber}/api/test/profile




๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
curl ๋ช…๋ น์–ด

cURL์„ ์ด์šฉํ•˜์—ฌ HTTP ์š”์ฒญํ•˜๋Š” ๋ช…๋ น์–ด

Option

-I : Web Server๋กœ HEAD ์š”์ฒญ์„ ๋ณด๋‚ด๊ณ , Response Header๋งŒ ๋ฐ›์•„์˜ด.
| grep -oP 'HTTP/1.1 /K/d+' : ์ •๊ทœ ํ‘œํ˜„์‹์„ ์ด์šฉํ•˜์—ฌ Response Header์—์„œ HTTP Status Code ์ถ”์ถœ.
   - o: Pattern๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„๋งŒ ์ถœ๋ ฅ
   - P: Perl ํ˜ธํ™˜ ์ •๊ทœ ํ‘œํ˜„์‹ ์‚ฌ์šฉ.
   - 'HTTP/1.1 /K/d+': HTTP/1.1 ๊ณผ ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„์€ ๋ฌด์‹œํ•˜๊ณ , ์ดํ›„์— ๋‚˜์˜ค๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ์ˆซ์ž(/d+)์— ์ผ์น˜ํ•˜๋Š” ๋ถ€๋ถ„ ์ถ”์ถœ.

| grep "HTTP" : ํŒŒ์ดํ”„๋ผ์ธ ์—ฐ์‚ฐ์ž๋กœ ์•ž์˜ ๋ช…๋ น์–ด์˜ ์ถœ๋ ฅ์„ ๋’ค์˜ ๋ช…๋ น์–ด ์ž…๋ ฅ์œผ๋กœ ์ „๋‹ฌํ•˜๋Š”๋ฐ, HTTP ๋ฌธ์ž์—ด์„ ํ•„ํ„ฐ๋งํ•˜์—ฌ ํ•ด๋‹น ๋ฌธ์ž์—ด์„ ํฌํ•จํ•˜๋Š” Line๋งŒ ์ถœ๋ ฅ
wc -l : ์ถœ๋ ฅ๋œ Line ๊ฐœ์ˆ˜ ์„ธ๋Š” ๋ช…๋ น์–ด
๋ฐ˜์‘ํ˜•


116๋ฒˆ์งธ ์ค„์—์„œ ๊ฒฐ๊ณผ๊ฐ’ ๊ฐœ์ˆ˜๊ฐ€ 1์ด๋ผ๋ฉด ์ •์ƒ์ ์œผ๋กœ ๊ตฌ๋™๋œ ๊ฒƒ์ด ํ™•์ธ ๋˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—
๋ฐ˜๋ณต๋ฌธ์„ ์ข…๋ฃŒ ์‹œํ‚ค๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.

ํ•˜์ง€๋งŒ, 1์ด ์•„๋‹ˆ๋ผ๋ฉด ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด๊ณ , ํ•ด๋‹น ๋‚ด์šฉ์„ ์ถœ๋ ฅ ๋ฐ Log์— ์ €์žฅํ•œ ๋’ค
ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ์žฌ ๊ธฐ๋™ ์ „ ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์ž‘์—…์ด ์ด๋ค„์งˆ ์ˆ˜ ์žˆ๋„๋ก ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.

 

applicationHealthCheck.sh 139 ~ 149๋ฒˆ์งธ ์ค„


์œ„์—์„œ Health Check๋ฅผ 10๋ฒˆํ•˜๊ธฐ ์œ„ํ•œ ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ€ 10์ด ๋˜๋ฉด ๊ฒฐ๊ตญ ์ด ์—ญ์‹œ๋„ ์ปจํ…Œ์ด๋„ˆ์— ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ์žฌ ๊ธฐ๋™ ์ „ ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ์ž‘์—…์ด ์ด๋ค„์งˆ ์ˆ˜ ์žˆ๋„๋ก ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ฃผ์—ˆ์–ด์š”.


applicationHealthCheck.sh 159 ~ 200๋ฒˆ์งธ ์ค„


63๋ฒˆ์งธ ์ค„์—์„œ ๋‘ ์ปจํ…Œ์ด๋„ˆ์˜ ์ƒํƒœ๊ฐ€ Up์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€๋ฅผ ํ™•์ธํ•˜์˜€๋Š”๋ฐ, ์•„๋‹ˆ๋ผ๊ณ  ํ•œ๋‹ค๋ฉด ์ด ๊ณณ์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

์ตœ์ดˆ 160๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด ๋‘ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ชจ๋‘ ๋น„ ์ •์ƒ์ ์œผ๋กœ ์˜ฌ๋ผ์™€ ์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ณ , ๋‘ ๊ฐœ์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ ๊ธฐ๋™ ์ „ ์ข…๋ฃŒ ๋ฐ ์‚ญ์ œ ํ•  ์ˆ˜ ์žˆ๋„๋ก 165 ~ 173๋ฒˆ์งธ ์ค„์„ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ๋ฐ, ๋‘ ๊ฐœ ๋ชจ๋‘๊ฐ€ ์•„๋‹ˆ๋ผ ํ•˜๋‚˜์˜ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋ฌธ์ œ ์žˆ์„ ์ˆ˜๋„ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— 175 ~ 191๋ฒˆ์งธ ์ค„๊นŒ์ง€๋Š”
๊ฐ๊ฐ์˜ ์ปจํ…Œ์ด๋„ˆ์— ๋งž๊ฒŒ ์ž‘์—…๋  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.


193๋ฒˆ์งธ else ๋ฌธ์— ๋“ค์–ด์™”๋‹ค๋Š” ๊ฒƒ์€ ๊ธฐ๋™ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜์ง€ ๋ชปํ–ˆ์„ ๊ฒฝ์šฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ข…๋ฃŒํ•˜๊ณ , ํ•ด๋‹น ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ˜ธ์ถœํ–ˆ๋˜ ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋กœ ๋„˜์–ด๊ฐ€๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.



 



      ๐Ÿ“ฆ applicationDockerContainerChangeOldErrorRemove()

Health Check๋ฅผ ํ•˜๋ฉด์„œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒ๋œ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋น ๋ฅด๊ฒŒ ์ œ๊ฑฐํ•˜๊ณ , ๋‹ค์‹œ ๊ธฐ๋™ํ•ด ์ฃผ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ด ํ•จ์ˆ˜๋กœ ๋“ค์–ด์˜ค๊ฒŒ ํ•ด ์ฃผ์—ˆ๊ณ , ์ด ํ•จ์ˆ˜๋Š” ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ๋ฐ›์•„ ์ž‘๋™ํ•˜๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

applicationHealthCheck.sh 202 ~ 217๋ฒˆ์งธ ์ค„


์ตœ์ดˆ ์ด ๊ณณ์—์„œ ๋ฌธ์ œ ๋ฐœ์ƒ ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์–ด๋–ค ๊ฒƒ์ธ์ง€๋ฅผ ํ™•์ธํ•˜๊ณ , ์ค‘์ง€ ๋ฐ ์‚ญ์ œ ๋ช…๋ น์–ด์— ๋“ค์–ด๊ฐˆ ๋ณ€์ˆ˜ ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.


applicationHealthCheck.sh 235 ~ 254๋ฒˆ์งธ ์ค„


๋ณธ๊ฒฉ์ ์œผ๋กœ ์ด ๊ณณ์—์„œ ๋ฌธ์ œ ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€ ๋ฐ ์‚ญ์ œ๋ฅผ ์ง„ํ–‰ํ•˜๋Š”๋ฐ,
๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋Š” docker stop ๋ช…๋ น์–ด๋กœ ๋จผ์ € ์ค‘์ง€๋ฅผ ์‹œ์ผœ์•ผ์ง€ docker rm ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์‚ญ์ œ๊ฐ€ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์—
stop ๋ช…๋ น์–ด๊ฐ€ ์„ฑ๊ณตํ–ˆ์„ ๋•Œ, rm ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰ ๋  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.

rm ๋ช…๋ น์–ด๊นŒ์ง€ ์ •์ƒ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์—ˆ๋‹ค๋ฉด ์ด๋ฆ„ ์—†๋Š” ๋„์ปค ์ด๋ฏธ์ง€๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ง€์šธ ์ˆ˜ ์žˆ๋Š” ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด ์ฃผ์—ˆ๊ณ , 251๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด ์ฃผ์—ˆ์–ด์š”.


applicationHealthCheck.sh 256 ~ 299๋ฒˆ์งธ ์ค„


์ด์ œ ์ด ๊ณณ์—์„œ ๋‹ค์‹œ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์„ ์‹ค์‹œํ•ด ์ค๋‹ˆ๋‹ค.

์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ๊ด€๋ จํ•ด์„œ๋Š” ์ด ์ „์— ์ž‘์„ฑํ•œ ์ด ๊ณณ์— ์ •์„ฑ์Šค๋Ÿฝ๊ฒŒ ๋‚ด์šฉ์„ ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.
ํ˜น์‹œ๋ผ๋„ ์ดํ•ด๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋‹ค์‹œ ํ•œ๋ฒˆ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

 

[CI/CD] Jekins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)

๐Ÿ—‚ ๋ชฉ์ฐจ โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™ โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™ โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ โœ… [DevOps] JAVA Gradle JaCoCo

junyharang.tistory.com



applicationHealthCheck.sh 300 ~ 319๋ฒˆ์งธ ์ค„


์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ๋’ค ์ •์ƒ ๊ธฐ๋™ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ณ , ์ •์ƒ ๊ธฐ๋™์ด ๋˜์—ˆ๋‹ค๋ฉด
๋‹ค์‹œ Health Check๊ฐ€ ์ด๋ค„์ง€๋„๋ก ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด ์ฃผ์—ˆ์–ด์š”.

ํ•˜์ง€๋งŒ ๊ทธ๋Ÿผ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ , ๊ธฐ๋™ ์—ฌ๋ถ€๊ฐ€ ์ •์ƒ์ด ์•„๋‹ˆ๋ผ๋ฉด ๋ฌธ์ œ ๋‚ด์šฉ์„ ์ถœ๋ ฅ ๋ฐ ๋กœ๊ทธ ์ €์žฅ ํ•œ ๋’ค ๋๋‚˜๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.


applicationHealthCheck.sh 321 ~ 357๋ฒˆ์งธ ์ค„


unknownNameImageDelete()๋Š” ์ด๋ฆ„ ์—†๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์ง€์šฐ๋Š” ํ•จ์ˆ˜์—์š”.

์ตœ์ดˆ checkDockerImage()๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ docker images ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์กด์žฌํ•˜๋Š”
๋„์ปค ์ด๋ฏธ์ง€ ์ •๋ณด๋ฅผ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.


๊ทธ๋Ÿฐ ๋’ค 328๋ฒˆ์งธ ์ค„์—์„œ docker images ๋ช…๋ น์–ด๋กœ grep์„ ์žก์•„ <none> ์ด ํฌํ•จ๋œ ํ–‰์ด ์žˆ๋Š”์ง€๋ฅผ ํ™•์ธํ•ด ์ฃผ๊ณ ,
์žˆ๋‹ค๊ณ  ํ•˜๋ฉด 335๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ง€์šธ ์ˆ˜ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.


์œ„ ๋ช…๋ น์–ด๋“ค์— ๋Œ€ํ•ด์„œ๋Š” ์ด ์ „์— ์ž‘์„ฑํ–ˆ๋˜ ์ด ๊ณณ์— ์ž์„ธํžˆ ์ž‘์„ฑํ•ด ๋‘์—ˆ์œผ๋‹ˆ
ํ˜น์‹œ ์ดํ•ด๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ๋‹ค์‹œ ํ•œ๋ฒˆ ์ฐธ๊ณ  ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

 

[CI/CD] Jekins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ก Create Docker Image And BackUp

๐Ÿ—‚ ๋ชฉ์ฐจ โœ… [CI/CD] Jenkins์™€ Gitea ์—ฐ๋™ โœ… [CI/CD] Jenkins Trigger ์ •๋ณด Discord๋กœ ๋ณด๋‚ด๊ธฐ โœ… [CI/CD] ์ •์  ์ฝ”๋“œ ๋ถ„์„ ํˆด SonarQube์™€ Jenkins ์—ฐ๋™ โœ… [CI/CD] SonarQube๋ฅผ ํ†ตํ•ด Code Convention ์ ์šฉ โœ… [DevOps] JAVA Gradle JaCoCo

junyharang.tistory.com

 

applicationHealthCheck.sh 376 ~ 386๋ฒˆ์งธ ์ค„


์ด๋ ‡๊ฒŒ ์‰˜ ์Šคํฌ๋ฆฝํŠธ ์ž‘์—…์ด ๋ชจ๋‘ ๋๋‚˜๋ฉด ์ด ๊ณณ์œผ๋กœ ์™€์„œ ์ž‘์—…์ด ๋๋‚œ ๊ฒƒ์„ ์•Œ๋ ค์ฃผ๊ณ , docker ps -a ๋ช…๋ น์–ด๋ฅผ ์ถœ๋ ฅํ•˜์—ฌ ํ˜„์žฌ ๊ธฐ๋™์ค‘์ธ ๋„์ปค ๋ชฉ๋ก์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.

์ด ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋๋‚˜๋ฉด ํ•ด๋‹น ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ˜ธ์ถœํ•œ ์Šคํฌ๋ฆฝํŠธ๋กœ ์ž‘์—…์ด ๋„˜์–ด๊ฐ€๊ฒŒ ๋˜์š”.

 

์ด๋ฒˆ ๊ธ€์—๋Š” ์—ฌ๊ธฐ๊นŒ์ง€ ์ •๋ฆฌํ•˜๊ณ , ๋‹ค์Œ ๊ธ€์—์„œ๋Š” NGINX ๋„์ปค ๋งŒ๋“ค๊ธฐ ์ „ ์„ค์ • ๊ด€๋ จ ์ž‘์—… ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด ๋ณผ๊ฒŒ์š”.

 

 

 

๋„์ปค ๊ต๊ณผ์„œ:์„ค์น˜๋ถ€ํ„ฐ ์‹ค์ „ ์šด์˜ ํˆฌ์ž…๊นŒ์ง€ ํ•œ ๊ถŒ์— ๋‹ด์•˜๋‹ค!

COUPANG

www.coupang.com

"์ด ํฌ์ŠคํŒ…์€ ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์˜ ์ผํ™˜์œผ๋กœ, ์ด์— ๋”ฐ๋ฅธ ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์Šต๋‹ˆ๋‹ค."

 

 

์ด์ „ ๊ธ€: [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ข Application Server Docker Job (โ‘ก Application Docker Run)

๋‹ค์Œ ๊ธ€: [CI/CD] Jenkins + Docker๋ฅผ ์ด์šฉํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ - โ‘ฃ NGINX Server Docker Job (โ‘  NGINX ๊ฐ ์ข… ์„ค์ •)

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•