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

2023. 7. 5. 20:06ใ†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 Server Docker Job

    ๐Ÿ”ฝ ๊ฐœ์š”

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

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

 

deploy Directory Path

 

 

 

 

        ๐Ÿ“ฆ ์†Œ๊ฐœ

์ง€๋‚œ ๊ธ€์—์„œ ์ฃผ๋‹ˆ๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋นŒ๋“œํ•˜๊ณ , ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์•„์นด์ด๋ธŒ ํ˜•ํƒœ๋กœ ๋ฐฑ์—…ํ•˜๋Š” ๊ฒƒ๊นŒ์ง€ ์ž‘์—…์„ ์™„๋ฃŒ ํ•˜์˜€์–ด์š”.
์ด๋ฒˆ์—๋Š” ๊ฐ ์ข… ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ™œ์šฉํ•˜์—ฌ Spring Boot Application ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋งŒ๋“ค๊ณ , ๊ธฐ๋™ ์‹œํ‚ค๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

ํ•ด๋‹น ์ž‘์—…์—๋Š” 3๊ฐœ์˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋‚˜๋ˆ ์„œ ์ค€๋น„ํ•˜์˜€๊ณ , ๊ฐ ์Šคํฌ๋ฆฝํŠธ ๋ณ„๋กœ ๋‚˜๋ˆ ์„œ ๊ธ€์„ ์ž‘์„ฑํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

๋จผ์ € ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•˜๊ณ , ๊ทธ์— ๋”ฐ๋ฅธ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋Š” ์Šคํฌ๋ฆฝํŠธ์— ๋Œ€ํ•ด ์ •๋ฆฌํ•ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.

 

 

 

    ๐Ÿ”ฝ ์  ํ‚จ์Šค

        ๐Ÿ“ฆ Jenkinsfile

jenkinsfile 449 ~ 489 ๋ฒˆ์งธ ์ค„

728x90


์ด๋ฒˆ ์ž‘์—…์— ํ•ด๋‹นํ•˜๋Š” ์  ํ‚จ์Šค stage ๋ถ€๋ถ„์ด์—์š”.

464๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด applicationContainerExistenceStatusCheck.sh๋ฅผ ์‹คํ–‰ํ•˜๊ฒŒ ๋˜๊ณ ,
์ด๋ฅผ ํ†ตํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋„์ปค ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ๋จผ์ € ํ™•์ธํ•˜๋Š” ์ž‘์—…์ด ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

    ๐Ÿ”ฝ applicationContainerExistenceStatusCheck.sh

#!/bin/bash

set -e

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

echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์„œ๋ฒ„ ์ž‘์—… ์ค‘ Application Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ ์ž‘์—…์ด ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”."
echo "======================================[$NOW] ํ†ตํ•ฉ ๋ฐฑ ์˜คํ”ผ์Šค api Application Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ======================================"
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

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 "[INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์„œ๋ฒ„ ์ž‘์—… ์ค‘ Application Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ ์ž‘์—…์ด ์‹œ์ž‘ ๋˜์—ˆ์–ด์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1
    echo "======================================[$NOW] ํ†ตํ•ฉ ๋ฐฑ ์˜คํ”ผ์Šค api Application Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ======================================" >> $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

  checkApplicationContainerExistenceStatus
}

checkApplicationContainerExistenceStatus() {
  echo "[$NOW] [INFO] Application ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] Application ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  echo "[$NOW] [INFO] Blue ํ™˜๊ฒฝ ๊ธฐ์ค€ ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] Blue ํ™˜๊ฒฝ ๊ธฐ์ค€ ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  APPLICATION_DOCKER_MAIN_STATUS=$(docker ps -aqf "name=$APPLICATION_MAIN_CONTAINER_NAME")

  echo "[$NOW] [INFO] Green ํ™˜๊ฒฝ ๊ธฐ์ค€ ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] Green ํ™˜๊ฒฝ ๊ธฐ์ค€ ์ปจํ…Œ์ด๋„ˆ ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธํ• ๊ฒŒ์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

  APPLICATION_DOCKER_SUB_STATUS=$(docker ps -aqf "name=$APPLICATION_SUB_CONTAINER_NAME")

  if [[ -z "$APPLICATION_DOCKER_MAIN_STATUS" ]] || [[ -z "$APPLICATION_DOCKER_SUB_STATUS" ]];
  then
    if [[ -z "$APPLICATION_DOCKER_MAIN_STATUS" ]] && [[ -z "$APPLICATION_DOCKER_SUB_STATUS" ]];
    then
      echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME}, ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋‘ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”."
      echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME}, ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋‘ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      for loopCount in {1..2}
      do
        if [ $loopCount -eq 1 ];
        then
          containerName=$APPLICATION_MAIN_CONTAINER_NAME
        else
          containerName=$APPLICATION_SUB_CONTAINER_NAME
        fi

        echo "[$NOW] [INFO] ${containerName} ๊ณง ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์ด ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค."
        echo "[$NOW] [INFO] ${containerName} ๊ณง ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์ด ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

        applicationDockerContainerRun "${containerName}"
      done

    elif [[ -z "$APPLICATION_DOCKER_MAIN_STATUS" ]] && [[ -n "$APPLICATION_DOCKER_SUB_STATUS" ]];
    then
      echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”."
      echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      applicationDockerContainerRun "${APPLICATION_MAIN_CONTAINER_NAME}"

    else
      echo "[$NOW] [INFO] ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”."
      echo "[$NOW] [INFO] ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•˜์ง€ ์•Š์•„์š”." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

      applicationDockerContainerRun "${APPLICATION_SUB_CONTAINER_NAME}"
    fi

  else
    echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME}, ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•ฉ๋‹ˆ๋‹ค."
    echo "[$NOW] [INFO] ${APPLICATION_MAIN_CONTAINER_NAME}, ${APPLICATION_SUB_CONTAINER_NAME} ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌ ํ•ฉ๋‹ˆ๋‹ค." >> $LOG_DIR/"$SAVE_LOG_DATE"-deploy.log 2>&1

    $APPLICATION_SHELL_SCRIPT_DIRECTORY/applicationContainerNewRun.sh;

    $APPLICATION_SHELL_SCRIPT_DIRECTORY/applicationHealthCheck.sh;
  fi
}

applicationDockerContainerRun() {
  sleep 5
  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
    containerAndHostName=$APPLICATION_MAIN_CONTAINER_NAME
    portNumber=$APPLICATION_MAIN_EXTERNAL_PORT_NUMBER

  else
    containerAndHostName=$APPLICATION_SUB_CONTAINER_NAME
    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
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์„ ์‹œ์ž‘ํ• ๊ฒŒ์š”."
  echo "[$NOW] [INFO] ${containerName} ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ž‘์—…์„ ์‹œ์ž‘ํ• ๊ฒŒ์š”." >> $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}}" "

  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
}

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 Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ ์ž‘์—…์ด ๋๋‚ฌ์–ด์š”."
echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ LOG ์œ„์น˜ : ${LOG_DIR}"
echo "[$NOW] [INFO] ๊ธฐ๊น”๋‚˜๋Š” ์‚ฌ๋žŒ๋“ค ํ†ตํ•ฉ ๊ด€๋ฆฌ ์„œ๋ฒ„ API ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์ž‘์—… ์ค‘ Application Docker Container ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ ์ž‘์—…์ด ๋๋‚ฌ์–ด์š”." >> $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


ํ•ด๋‹น ์‰˜ ์Šคํฌ๋ฆฝํŠธ์— ์ „์ฒด ๋‚ด์šฉ์€ ์œ„์™€ ๊ฐ™์•„์š”.

 

 

 

        ๐Ÿ“ฆ checkApplicationContainerExistenceStatus()

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

applicationContainerExistenceStatusCheck.sh 44 ~ 55๋ฒˆ์งธ ์ค„


50๋ฒˆ์งธ ์ค„๊ณผ 55๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด docker ps -apf ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•˜์—ฌ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ID ๊ฐ’์„ ํ™•์ธํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ์ด ๋•Œ, "name=$APPLICATION_MAIN_CONTAINER_NAME"์„ ํ†ตํ•ด ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ์ „๋‹ฌํ•˜๊ฒŒ ๋˜๊ณ , ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌํ•˜๋ฉด ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์˜ ID ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ๋ช…๋ น์ด์—์š”.

ํ•ด๋‹น ๋ช…๋ น์–ด์— ๊ฒฐ๊ณผ๋ฅผ APPLICATION_DOCKER_MAIN_STATUS์™€ APPLICATION_DOCKER_SUB_STATUS ์ƒ์ˆ˜ ๋ณ€์ˆ˜์— ๊ฐ๊ฐ ๋‹ด์•„ ์กด์žฌ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ด ์ฃผ๋ ค๊ณ  ํ–ˆ์–ด์š”.

applicationContainerExistenceStatusCheck.sh 57 ~ 77๋ฒˆ์งธ ์ค„


์ตœ์ดˆ 57๋ฒˆ์งธ ์ค„์—์„œ ์œ„์— ๋ช…๋ น์–ด ๊ฒฐ๊ณผ ๋‚ด์šฉ์ด ๋‹ด๊ธด ์ƒ์ˆ˜ ๋ณ€์ˆ˜์— MAIN๊ณผ SUB ์ปจํ…Œ์ด๋„ˆ ๊ฒฐ๊ณผ ๊ฐ’์ด ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ if๋ฌธ์—์„œ or์„ ํ†ตํ•ด ํ™•์ธํ•ด ์ฃผ๊ณ  ์žˆ์–ด์š”.

์ฆ‰, ๋‘˜ ์ค‘ ํ•˜๋‚˜๋ผ๋„ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ฐธ์ด ๋˜์–ด 59๋ฒˆ์งธ ์ค„๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ ๋ ๊ฑฐ์—์š”.

-z Option์„ ํ†ตํ•ด ์ด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ณ , ์ฐธ์ด๋ฉด ๋ช…๋ น์–ด ๊ฒฐ๊ณผ์— ์•„๋ฌด ๊ฐ’๋„ ์—†์—ˆ๋˜ ๊ฑฐ๊ณ ,
๊ฑฐ์ง“์ด๋ฉด ์ถœ๋ ฅ๋œ ๊ฒฐ๊ณผ๊ฐ€ ์žˆ๋Š” ๊ฒƒ์ด์—์š”.


59๋ฒˆ์งธ ์ค„์—์„œ๋Š” ๋‘ ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋‘ ์กด์žฌํ•˜์ง€ ์•Š๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ณ  ์žˆ์–ด์š”.

์ฐธ์ด๋ผ๋ฉด ๋‘˜ ๋‹ค ๋‹ค์‹œ ๊ธฐ๋™ ์‹œ์ผœ์ฃผ๊ธฐ ์œ„ํ•ด for๋ฌธ์„ ๋Œ๋ ค ์ปจํ…Œ์ด๋„ˆ ๊ฐœ์ˆ˜๊ฐ€ 2๊ฐœ์ด๋‹ˆ 2๋ฒˆ์„ ๋Œ๋ ค์„œ ์ฒซ๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์—์„œ๋Š” MAIN ์ปจํ…Œ์ด๋„ˆ, ๋‘๋ฒˆ์งธ ๋ฐ˜๋ณต๋ฌธ์—์„œ๋Š” SUB ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•œ ๊ธฐ๋™ ์ž‘์—…์„ ์œ„ํ•œ applicationDockerContainerRun()์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋„๋ก containerName ๋ณ€์ˆ˜์— ๊ฐ๊ฐ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์ด ๋‹ด๊ธด ์ „์—ญ ์ƒ์ˆ˜ ๋ณ€์ˆ˜๋ฅผ ๋„ฃ์–ด ์ฃผ์—ˆ์–ด์š”.

๋‘ ๋ฒˆ ๋ฐ˜๋ณต์ด ๋๋‚˜๋ฉด done์— ๋‹ค๋‹ค๋ฅด๊ณ , ํ•ด๋‹น ๋ฐ˜๋ณต๋ฌธ์€ ๋๋‚˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

applicationContainerExistenceStatusCheck.sh 79 ~ 101๋ฒˆ์งธ ์ค„


๋งŒ์•ฝ ๋‘ ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋‘ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๊ณ , ๋ชจ๋‘ ์กด์žฌํ•˜๋Š” ๊ฒƒ๋„ ์•„๋‹ˆ๋ผ๋ฉด
์–ด๋–ค ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”์ง€ ์ฐพ์•„๋ด์•ผ ํ•ด์š”.

์ด๋ฅผ ์œ„ํ•ด 79๋ฒˆ์งธ ์ค„์—์„œ MAIN ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๊ณ , SUB ์ปจํ…Œ์ด๋„ˆ๋Š” ์กด์žฌํ•˜๋Š”์ง€
(-n Option = ๋Œ€์ƒ์— ๊ฐ’์ด ๋น„์–ด์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” Option์œผ๋กœ ๋น„์–ด์žˆ์ง€ ์•Š์œผ๋ฉด ์ฐธ์ด๋˜๊ณ , ๋น„์–ด ์žˆ์œผ๋ฉด ๊ฑฐ์ง“์œผ๋กœ ์ฒ˜๋ฆฌ)

ํ™•์ธํ•ด์ฃผ๊ณ , ๋งŒ์•ฝ ์ฐธ์ด๋ผ๋ฉด MAIN ์ปจํ…Œ์ด๋„ˆ๋งŒ ๊ธฐ๋™ ์‹œํ‚ฌ ์ˆ˜ ์žˆ๊ฒŒ
applicationDockerContainerRun() ํ˜ธ์ถœํ•  ๋•Œ, MAIN ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ์–ด์š”.

86๋ฒˆ์งธ else ๋ฌธ์„ ๋งŒ๋‚˜๋ฉด MAIN ์ปจํ…Œ์ด๋„ˆ๋Š” ์กด์žฌํ•˜๋Š”๋ฐ,

SUB ์ปจํ…Œ์ด๋„ˆ๋Š” ์กด์žฌํ•˜์ง€ ์•Š๋Š”์ง€์— ๋Œ€ํ•œ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.

์—ญ์‹œ applicationDockerContainerRun() ํ˜ธ์ถœํ•  ๋•Œ, SUB ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ์–ด์š”.

93๋ฒˆ์งธ ์ค„์— else ๋ฌธ์„ ๋งŒ๋‚˜๊ฒŒ ๋˜๋ฉด ๋ชจ๋“  ์ปจํ…Œ์ด๋„ˆ ๋™์ž‘ ์—ฌ๋ถ€์™€ ์ƒ๊ด€ ์—†์ด ์กด์žฌํ•˜๋Š” ๊ฒƒ์€ ํ™•์ธ์ด ๋˜์—ˆ๋‹ค๋Š” ๊ฒƒ์ด๊ณ , ์ด๋ฅผ ํ†ตํ•ด 97๋ฒˆ์งธ ์ค„์— ์ƒˆ๋กœ์šด ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ๋ช…๋ น์–ด๊ฐ€ ๋‹ด๊ธด ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋˜๊ณ , ํ•ด๋‹น ์‰˜ ์Šคํฌ๋ฆฝํŠธ ์ž‘์—…์ด ์™„๋ฃŒ๋˜๋ฉด 99๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ Health Check ์ž‘์—…์ด ์ด๋ค„์ง€๋„๋ก ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.





        ๐Ÿ“ฆ applicationDockerContainerRun()

applicationContainerExistenceStatusCheck.sh 103 ~ 127๋ฒˆ์งธ ์ค„


๋งŒ์•ฝ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์žˆ์—ˆ๋‹ค๋ฉด

์ฆ‰, docker ps ๋ช…๋ น์–ด๋กœ ์กฐํšŒ๋˜์ง€ ์•Š๋Š” ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์žˆ์—ˆ๋‹ค๋ฉด ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์„ ๊ฐ€์ง€๊ณ  ์ด ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๊ฒŒ ๋œ๋‹ต๋‹ˆ๋‹ค.

์ตœ์ดˆ 110๋ฒˆ์งธ ์ค„์—์„œ ๋งค๊ฐœ ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋œ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์ด MAIN์˜ ๊ฒƒ์ธ์ง€ SUB์— ๊ฒƒ์ธ์ง€๋ฅผ ํ™•์ธํ•˜๊ณ ,

์ง€์—ญ ๋ณ€์ˆ˜์— ๊ฐ๊ฐ์˜ ์ปจํ…Œ์ด๋„ˆ ์„ค์ •์— ๋งž๊ฒŒ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋„๋ก ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด ์ฃผ์—ˆ์–ด์š”.


applicationContainerExistenceStatusCheck.sh 129 ~ 146๋ฒˆ์งธ ์ค„

๋ฐ˜์‘ํ˜•

 

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

docker run: Docker Container ์‹คํ–‰ ๋ช…๋ น

Option

-- itd: Docker Container๋ฅผ ๋Œ€ํ™”ํ˜•์œผ๋กœ ์‹คํ–‰ํ•˜๊ณ , ํ„ฐ๋ฏธ๋„์— ์—ฐ๊ฒฐํ•œ ๋’ค Back Ground์—์„œ ์‹คํ–‰.
-- name: Docker Container ์ด๋ฆ„ ์„ค์ •.
-- hostname: Docker Container ๋‚ด๋ถ€ Host ์ด๋ฆ„ ์„ค์ •.
- e container: Docker Container ๋‚ด์—์„œ container๋ผ๋Š” ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋ฅผ docker๋กœ ์„ค์ •.
- p: :์„ ๊ธฐ์ค€์œผ๋กœ ์•ž์—๋Š” Host Server์˜ Port ๋ฒˆํ˜ธ์™€ ๋’ค์—๋Š” Docker Container ๋‚ด๋ถ€ ํฌํŠธ ๋ฒˆํ˜ธ Mapping.
--restart unless-stopped: Container๊ฐ€ ๋น„์ •์ƒ์ ์œผ๋กœ ์ข…๋ฃŒ๋œ ๊ฒฝ์šฐ์—๋งŒ ์žฌ์‹œ์ž‘. ๋ช…์‹œ์ ์œผ๋กœ ์ค‘์ง€๋  ๋•Œ๊นŒ์ง€ Container ์‹คํ–‰.

์ถ”๊ฐ€ Option

-- privileged: Docker Container์˜ ํŠน๊ถŒ ๋ชจ๋“œ๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ Container๊ฐ€ Host ์‹œ์Šคํ…œ์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์— Access ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•จ. ์ผ๋ฐ˜์ ์œผ๋กœ ๋ณด์•ˆ์ ์ธ ์ด์œ ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๊ถŒ๊ณ .


dockerRunCommand
๋ณ€์ˆ˜๋Š” ์‚ฌ์šฉํ•  ๋ช…๋ น์–ด๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋‹ด์€ ๊ฐ์ฒด๋กœ 133๊ณผ 135๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ๋ช…๋ น์–ด ์„ฑ๊ณต ์—ฌ๋ถ€์— ๋”ฐ๋ผ ๊ฐ๊ฐ์˜ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ ํ•  ๋•Œ, ๋ช…๋ น์–ด๋ฅผ ๊ฐ™์ด ์ „๋‹ฌํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.


131๋ฒˆ์งธ ์ค„์—์„œ Application Docker Container ๊ธฐ๋™ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๊ธฐ๋™ ์‹œ์ผœ ์ฃผ์—ˆ์–ด์š”.

137๋ฒˆ์งธ ์ค„์—์„œ ๊ธฐ๋™ ์‹œํ‚จ ์ปจํ…Œ์ด๋„ˆ ์ฆ‰, 131๋ฒˆ์งธ ๋ช…๋ น์–ด๊ฐ€ ์„ฑ๊ณตํ•˜์˜€๋‹ค๋ฉด ์ปจํ…Œ์ด๋„ˆ๋Š” ๊ธฐ๋™๋œ ๊ฒƒ์ด๊ณ , ์ด ๋•Œ containerId ๋ณ€์ˆ˜์— ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ ID ์กฐํšŒ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‹ด์€ ๋’ค ์ถœ๋ ฅ ๋  ์ˆ˜ ์žˆ๋„๋ก ์ฒ˜๋ฆฌ ํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋ฆฌ๊ณ  ๋‚˜์„œ 146๋ฒˆ์งธ ์ค„์—์„œ ํ•ด๋‹น ์ปจํ…Œ์ด๋„ˆ์— ๋™์ž‘ ์ƒํƒœ๋ฅผ ์กฐํšŒํ•˜์—ฌ
๊ฒฐ๊ณผ๊ฐ’์„ checkContainerStatus ๋ณ€์ˆ˜์— ๋‹ด์•„ ์ฃผ์—ˆ์–ด์š”.


applicationContainerExistenceStatusCheck.sh 150 ~ 168๋ฒˆ์งธ ์ค„


150๋ฒˆ์งธ ์ค„์—์„œ ๋„์ปค ๊ธฐ๋™ ์ƒํƒœ๋ฅผ ์ถœ๋ ฅํ•˜์—ฌ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด docker logs ๋ช…๋ น์–ด๋ฅผ ์“ฐ๊ณ ,
์ปจํ…Œ์ด๋„ˆ ID๋ฅผ ์ „๋‹ฌํ•˜์—ฌ ๋Œ€์ƒ ์ปจํ…Œ์ด๋„ˆ Log๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ทธ๋Ÿฐ ๋’ค 152๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด 146๋ฒˆ์งธ ์ค„์—์„œ ๋‹ด๊ธด ๋Œ€์ƒ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋™ ์ƒํƒœ๊ฐ€ Up์ด๋ผ๋Š” ๋ฌธ์ž์—ด๋กœ ์‹œ์ž‘ํ•˜๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๊ณ , ๋งž์œผ๋ฉด successCommand()๋ฅผ ํ˜ธ์ถœํ•˜๊ณ , ์‚ฌ์šฉํ–ˆ๋˜ ์ปจํ…Œ์ด๋„ˆ ์ƒํƒœ ์กฐํšŒ ๋ช…๋ น์–ด๋ฅผ ๋ฌธ์ž์—ด๋กœ ์ „๋‹ฌํ•ด ์ฃผ๊ณ , ์ž‘์—…์„ ๋งˆ์น˜๊ฒŒ ํ•ด ์ฃผ์—ˆ๊ณ ,

๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด ์—ญ์‹œ failedCommand()๋ฅผ ํ˜ธ์ถœํ•˜๊ณ , ์ƒํƒœ ์กฐํšŒ ๋ช…๋ น์–ด๋ฅผ ๋ฌธ์ž์—ด๋กœ
์ „๋‹ฌํ•œ ๋’ค ์ž‘์—…์„ ๋งˆ์น  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ์ฃผ์—ˆ์–ด์š”.


applicationContainerExistenceStatusCheck.sh 185 ~ 197๋ฒˆ์งธ ์ค„


์ž‘์—…์ด ๋๋‚˜๋ฉด ์ด ๋ถ€๋ถ„์„ ๋งŒ๋‚˜๊ฒŒ ๋˜๋Š”๋ฐ, 187๋ฒˆ์งธ ์ค„์—์„œ ํ˜„์žฌ ๊ตฌ๋™ ์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ ๋ชจ๋“  ๋‚ด์šฉ์„ ์ถœ๋ ฅํ•˜๊ฒŒ ํ•ด์„œ ํ•ด๋‹น ๊ฒฐ๊ณผ๊ฐ’์„ operationDockerStatus ๋ณ€์ˆ˜์— ๋‹ด๊ฒŒ ํ•ด ์ฃผ์—ˆ๊ณ ,
์ด๋ฅผ 194๋ฒˆ์งธ ์ค„์—์„œ๋Š” ์ถœ๋ ฅํ•˜๊ณ , 195๋ฒˆ์งธ ์ค„์—์„œ๋Š” ๋กœ๊ทธ๋กœ ์ €์žฅ๋  ์ˆ˜ ์žˆ๊ฒŒ ์ฒ˜๋ฆฌํ•ด ์ฃผ์—ˆ์–ด์š”.



        ๐Ÿ“ฆ failedCommnad() & successCommand()

applicationContainerExistenceStatusCheck.sh 170 ~ 183๋ฒˆ์งธ ์ค„


๋‘ ํ•จ์ˆ˜๋Š” ๋ช…๋ น์–ด ์ฒ˜๋ฆฌ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์‹ถ์–ด ๋งŒ๋“  ํ•จ์ˆ˜์—์š”.

171๋ฒˆ๊ณผ 179๋ฒˆ์งธ ์ค„์„ ํ†ตํ•ด command๋ผ๋Š” ๋ณ€์ˆ˜์— ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋‹ด๊ฒŒ ํ•ด ์ฃผ์—ˆ๊ณ , ํ•ด๋‹น ๋‚ด์šฉ์„ ์ถœ๋ ฅ ๋ฐ ๋กœ๊ทธ๋กœ ์ €์žฅํ•˜๊ณ ,
์‹คํŒจ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉด ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ์ข…๋ฃŒ๋˜๊ฒŒ ํ•ด ์ฃผ์—ˆ๊ณ ,

์„ฑ๊ณต ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๋ฉด ๋‹ค์‹œ ํ˜ธ์ถœํ–ˆ๋˜ ํ•จ์ˆ˜๋กœ ๋Œ์•„๊ฐˆ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.



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



 

 

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

COUPANG

www.coupang.com

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

 

 

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

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

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•