Skip to content

Latest commit

ย 

History

History
191 lines (155 loc) ยท 13.1 KB

deploy.md

File metadata and controls

191 lines (155 loc) ยท 13.1 KB

๋ฌด์ค‘๋‹จ ๋ฐฐํฌ

๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ์ „๋žต์—๋Š” ์—ฌ๋Ÿฟ ์žˆ๋‹ค. ์šฐ์„ 

  1. Rolling

    • ์ผ๋ฐ˜์ ์ธ ๋ฐฐํฌ๋ฅผ ์˜๋ฏธํ•˜๊ณ , ๋‹จ์ˆœํ•˜๊ฒŒ ์„œ๋ฒ„๋ฅผ ๊ตฌ์„ฑํ•ด ๋ฐฐํฌํ•˜๋Š” ์ „๋žต์ด๋‹ค. ๋‹ค์‹œ ๋งํ•ด ๊ตฌ ๋ฒ„์ „์—์„œ ์‹  ๋ฒ„์ „์œผ๋กœ ํŠธ๋ž˜ํ”ฝ์„ ์ ์ง„์ ์œผ๋กœ ์ „ํ™˜ํ•˜๋Š” ๋ฐฐํฌ์ด๋‹ค. ๊ด€๋ฆฌ๊ฐ€ ํŽธํ•˜์ง€๋งŒ, ๋ฐฐํฌ ์ค‘ ํ•œ์ชฝ ์ธ์Šคํ„ด์Šค์˜ ์ˆ˜๊ฐ€ ๊ฐ์†Œ๋˜๋ฏ€๋กœ ์„œ๋ฒ„ ์ฒ˜๋ฆฌ ์šฉ๋Ÿ‰์„ ๋ฏธ๋ฆฌ ๊ณ ๋ คํ•œ๋‹ค.
    • ์ถ”๊ฐ€์ ์ธ ์„œ๋ฒ„๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋‹ค.
    • ์ด์ „๋ฒ„์ „๊ณผ ์ƒˆ๋กœ์šด๋ฒ„์ „์˜ ํ™˜๊ฒฝ์ด ๊ณ ๋ฆฝ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— Blue-green๋ณด๋‹ค ๋น ๋ฅด์ง€๋งŒ ๋‹จ์ ์€ ๊ณ ๋ฆฝ๋˜์ง€ ์•Š์•„ ๋กค๋ฐฑ์ด ์–ด๋ ต๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๋ฐฐํฌํ•œ ์„œ๋ฒ„๊ฐ€ ์ž˜๋ชป๋œ๋‹ค๋ฉด ๋กค๋ง๋ฐฉ์‹์„ ๋˜‘๊ฐ™์ด ์ด์šฉํ•ด ๋กค๋ฐฑํ•ด์•ผ ํ•œ๋‹ค.
  2. in-place

    • ์ธ์Šคํ„ด์Šค๊ฐ™์€ ์ธํ”„๋ผ ์ปดํฌ๋„ŒํŠธ์˜ ๊ต์ฒด ์—†์ด ๋ฒ„์ „์„ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.
    • ํ˜„์žฌ ๊ฐ€๋™์ค‘์ธ ์„œ๋ฒ„ ๊ทธ๋Œ€๋กœ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜„์žฌ์œ„์น˜ ๋ฐฐํฌ๋ผ๊ณ  ๋ถˆ๋ฆฐ๋‹ค.
  3. blue-green

    • ๋ถ„๋ฆฌ๋˜์ง€๋งŒ ๋™์ผํ•œ ํ™˜๊ฒฝ์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.
    • ๊ตฌ ๋ฒ„์ „์„ ๋ธ”๋ฃจ, ์‹  ๋ฒ„์ „์„ ๊ทธ๋ฆฐ ์ด๋ผ๊ณ  ํ•ด์„œ ๋ถ™์—ฌ์ง„ ์ด๋ฆ„์ด๋‹ค. ์‹  ๋ฒ„์ „์„ ๋ฐฐํฌํ•˜๊ณ  ์ผ์ œํžˆ ์ „ํ™˜ํ•˜์—ฌ ๋ชจ๋“  ์—ฐ๊ฒฐ์„ ์‹  ๋ฒ„์ „์„ ๋ฐ”๋ผ๋ณด๊ฒŒ ํ•˜๋Š” ์ „๋ ฅ์ด๋‹ค. ๊ตฌ ๋ฒ„์ „, ์‹  ๋ฒ„์ „ ์„œ๋ฒ„๋ฅผ ๋™์‹œ์— ๋‚˜๋ž€ํžˆ ๊ตฌ์„ฑํ•˜์—ฌ ๋ฐฐํฌ์‹œ์ ์— ํŠธ๋ž˜ํ”ฝ์ด ์ผ์ œํžˆ ์ „ํ™˜๋œ๋‹ค. ๋น ๋ฅธ ๋กค๋ฐฑ์ด ๊ฐ€๋Šฅํ•˜๊ณ , ์šด์˜ํ™˜๊ฒฝ์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ณ  ์‹ค์ œ ์„œ๋น„์Šค ํ™˜๊ฒฝ์œผ๋กœ ์‹ ๋ฒ„์ „ ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค. ๋‹จ ์ด๋Ÿฐ ๊ตฌ์„ฑ์€ ์‹œ์Šคํ…œ ์ž์›์ด ๋‘๋ฐฐ๋กœ ํ•„์š”ํ•˜์—ฌ ๋น„์šฉ์ด ๋” ๋งŽ์ด ๋ฐœ์ƒ
    • ์žฅ์ ์€ ๋ฐฐํฌ์†๋„๊ฐ€ ๋น ๋ฅด๋ฉฐ, ์žฅ์• ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„๋•Œ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ๊ธฐ์กด์„œ๋ฒ„๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ธฐ๋งŒ ํ•˜๋ฉด ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋กค๋ฐฑ์ด ์‰ฝ๋‹ค.
    • ์—…๋ฐ์ดํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋Š” ๋„์ค‘์—์„œ ์„œ๋ฒ„์ˆ˜๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€๋˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ์กด ์‚ฌ์šฉ๋˜๋˜ ๊ทธ๋Œ€๋กœ ์„œ๋ฒ„๋ฅผ ์—…๋ฐ์ดํŠธ ํ•˜๋ฉด๋œ๋‹ค. ๊ทธ๋ž˜์„œ ๋ถ€ํ•˜๊ฐ€ ๊ฑธ๋ฆด ๋ฌธ์ œ๋ฅผ ์ƒ๊ฐํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
    • ๋งŒ์•ฝ ์„œ๋ฒ„๊ฐ€ ๊ฐ€์ƒํ™˜๊ฒฝ์ด ์•„๋‹ˆ๊ณ  ๋ฌผ๋ฆฌ์ ์ธ ์„œ๋ฒ„๋กœ ์กด์žฌํ•œ๋‹ค๋ฉด ์•„๋ฌด๋ฆฌ ๋ˆ์ด ๋งŽ์€ ํšŒ์‚ฌ๋„ ์„œ๋ฒ„๋ฅผ ๋‘๋ฐฐ๋กœ ๋Š˜๋ ธ๋‹ค๊ฐ€ ํ•„์š”์—†์–ด์ง€๋ฉด ์ค„์ด๋Š” ๋น„ํšจ๋ฅ ์„ ์„ ํƒํ•  ์ˆ˜ ์—†๋‹ค. ๋”ฐ๋ผ์„œ ๋ฌผ๋ฆฌ์ ์œผ๋กœ ์กด์žฌํ•˜๋Š” ์„œ๋ฒ„์—์„œ๋Š” ์‚ฌ์šฉํ•˜๊ธฐ ์–ด๋ ค์šฐ๋ฉฐ ํ˜„์žฌ์œ„์น˜ ๋ฐฐํฌ ๋ฐฉ์‹์ด ๋” ์–ด์šธ๋ฆฐ๋‹ค. ๋˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์‰ฝ๊ฒŒ ์ƒ์„ฑํ•˜๊ณ  ์ง€์šธ ์ˆ˜ ์žˆ๋Š” ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์ด๋‚˜. ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์˜ฌ๋ ธ๋‹ค๊ฐ€ ๋‚ด๋ฆฌ๋Š” ๊ฒƒ์ด ์ž์œ ๋กœ์šด Docker๋“ฑ ๊ฐ€์ƒํ™˜๊ฒฝ์— ์–ด์šธ๋ฆฐ๋‹ค.
  4. carney

    • ์นด๋‚˜๋ฆฌ๋Š” ์ƒˆ๋ฅผ ์˜๋ฏธํ•˜๋Š”๋ฐ ์œ ๋…๊ฐ€์Šค์— ๊ต‰์žฅํžˆ ๋ฏผ๊ฐํ•œ ๋™๋ฌผ๋กœ ๊ด‘์‚ฐ์—์„œ ์œ„ํ—˜์„ ์•Œ๋ฆฌ๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉ๋˜์–ด์™”๋‹ค. ์ฆ‰, ๋ฏธ๋ฆฌ ์œ„ํ—˜์„ ๊ฐ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ๋ฐฐํฌ ๋ฐฉ์‹์ด๋‹ค.
    • ์นด๋‚˜๋ฆฌ ๋ฐฐํฌ๋Š” ์œ„ํ—˜์„ ๋น ๋ฅด๊ฒŒ ๊ฐ์ง€ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐํฌ ์ „๋žต์ด๋‹ค. ์ง€์ •ํ•œ ์„œ๋ฒ„ ๋˜๋Š” ํŠน์ • user์—๊ฒŒ๋งŒ ๋ฐฐํฌํ–ˆ๋‹ค๊ฐ€ ์ •์ƒ์ ์ด๋ฉด ์ „์ฒด๋ฅผ ๋ฐฐํฌํ•œ๋‹ค. ์„œ๋ฒ„์˜ ํŠธ๋ž˜ํ”ฝ์„ ์ผ๋ถ€๋ฅผ ์‹  ๋ฒ„์ „์œผ๋กœ ๋ถ„์‚ฐํ•˜์—ฌ ์˜ค๋ฅ˜ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋Ÿฐ ์ „๋žต์€ A/B ํ…Œ์ŠคํŠธ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์„ฑ๋Šฅ ๋ชจ๋‹ˆํ„ฐ๋ง์— ์œ ์šฉํ•˜๋‹ค. ํŠธ๋ž˜ํ”ฝ์„ ๋ถ„์ƒ์‹œํ‚ฌ ๋–„๋Š” ๋ผ์šฐํŒ…์„ ๋žœ๋คํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๊ณ  ์‚ฌ์šฉ์ž๋กœ ๋ถ„๋ฅ˜ ํ•  ์ˆ˜๋„ ์žˆ๋‹ค.
    • ๊ฐ€์žฅ ํฅ๋ฏธ๊ฐ€ ์ƒ๊ฒผ๋˜ ๋ฐฐํฌ๋ฐฉ์‹์ด๋‹ค.
      • ์กฐ๊ธˆ์”ฉ ์‚ฌ์šฉ์ž์˜ ๋ฒ”์œ„๋ฅผ ๋Š˜๋ ค๊ฐ€๋ฉฐ ํ”ผ๋“œ๋ฐฑ์„ ํ†ตํ•ด ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ์‹(์‹ค์ œ ์ธ์Šคํƒ€๊ทธ๋žจ์—์„œ ์นœ๊ตฌ๋“ค๊ณผ ๋‹ค๋ฅธ๋ฒ„์ „์˜ ์ธ์Šคํƒ€๋ฅผ ๋ชฉ๊ฒฉํ•œ์ ์ด ์žˆ๋‹ค.)
      • ๋‹จ๊ณ„๋ณ„ ๋ฐฐํฌ๋ฅผ ์˜๋ฏธํ•œ๋‹ค.
      • ์žฅ์ ๋งŒ ์กด์žฌํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋‹ค. ๋Œ€ํ‘œ์ ์ธ ์žฅ์ ์ด ๊ด€๋ฆฌ๋น„์šฉ์ด ๋„ˆ๋ฌด ํฌ๋‹ค๋Š” ๊ฒƒ.
      • ๋ฒ„์ „๊ด€๋ฆฌ๋ฅผ ์œ„ํ•ด ๋™์‹œ์— ์—ฌ๋Ÿฌ๊ฐœ์˜ ์†Œํ”„ํŠธ์›จ์–ด ๋ฒ„์ „์„ ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.
      • ๋กœ๋“œ๋ฒจ๋Ÿฐ์„œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค. ec2 nginx๋กœ ํ‰๋‚ด๋ฅผ ๋‚ผ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์ง€๋งŒ ๊ต‰์žฅํ•œ ๋‚ญ๋น„๋ผ๊ณ  ์ƒ๊ฐ
    • A/B Testing ๊ณผ์˜ ์ฐจ์ด
      • ๊ธฐ์ˆ ์  ๊ตฌํ˜„์˜ ์œ ์‚ฌ์„ฑ์œผ๋กœ A/B Testing์„ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ๋  ์ˆ˜ ์žˆ์ง€๋งŒ ๋‘˜์€ ๋‹ค๋ฅธ ๊ฐœ๋…
      • ์นด๋‚˜๋ฆฌ ๋ฐฐํฌ๋Š” ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๊ณ  ์ด์ƒ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ๋กค๋ฐฑํ•˜๋Š” ๊ฒƒ์— ์ดˆ์ ์ด ๋งž์ถฐ์ ธ ์žˆ์ง€๋งŒ
      • A/B Testing ์€ ํ•˜๋‚˜์˜ ๊ฐ€์„ค์„ ๋‹ค์–‘ํ•œ ๊ตฌํ˜„์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ…Œ์ŠคํŠธํ•˜๋Š”๊ฒƒ์„ ๋ชฉ์ ์œผ๋กœ ํ•˜๊ธฐ ๋–„๋ฌธ์ด๋‹ค.

in-place + Blue-Green ์ปจ์ƒ™ ์‚ฌ์šฉ

  • ์ด๋Ÿฐ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ ์ด์œ 

    ๊ฐ๊ฐ๋ฐฉ์‹์—๋Š” ์žฅ๋‹จ์ ์ด ์žˆ๋‹ค.

    ์šฐ์„  Rolling ์€ ์ถ”๊ฐ€์ ์ธ ์„œ๋ฒ„๊ฐ€ ํ•„์š”ํ•˜์ง€ ์•Š๋Š” ์žฅ์ ์ด ์žˆ์ง€๋งŒ ๋‹ค๋ฅธ ๋ฒ„์ „์˜ ์„œ๋ฒ„๋“ค์ด ๊ณ ๋ฆฝ๋˜์ง€ ์•Š์•„ ๋กค๋ฐฑ์ด ์–ด๋ ต๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ๋ฐฐํฌํ•œ ์„œ๋ฒ„๊ฐ€ ์ž˜๋ชป๋œ๋‹ค๋ฉด ๋ฐฐํฌโ†’ ๋กค๋ฐฑ โ†’ ๋ฐฐํฌ ๋กค๋ง ๋ฐฉ์‹์„ ๋˜‘๊ฐ™์ด ์ด์šฉํ•ด ๋กค๋ฐฑํ•ด์•ผ ํ•œ๋‹ค.

    ๋˜ ์„œ๋ฒ„๋ฅผ ๋‚˜๋ˆ ์„œ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ ๋–„๋ฌธ์— ์ค‘๋‹จ๋œ ์„œ๋ฒ„์˜ ์š”์ฒญ์„ ๋‚˜๋จธ์ง€ ์„œ๋ฒ„๊ฐ€ ๊ฐ๋‹นํ•ด์•ผํ•œ๋‹ค. ๊ฐ‘์ž๊ธฐ ์‚ฌ์šฉ์ž๊ฐ€ ๋ชฐ๋ฆฌ๋ฉด ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธธ ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

    ์šฐ๋ฆฌ๊ฐ€ ์•Œ๊ณ ์žˆ๋Š” Blue-Green์€ ๋ฆฌ์†Œ์Šค์˜ ๋‚ญ๋น„๊ฐ€ ํด ๊ฒƒ์ด๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋Œ๋ฆฐ๋‹ค๋Š” ๊ฒƒ์€ ์šฐ๋ฆฌ๊ฐ™์€ ํ•™์ƒ์ž…์žฅ์—์„œ ๋„ˆ๋ฌด ํฐ ๋‚ญ๋น„์ด๋‹ค. ๋˜ ๋กœ๋“œ๋ฒจ๋Ÿฐ์„œ๊ฐ€ ํ•„์š”ํ•œ๋ฐ ๋กœ๋“œ๋ฒจ๋Ÿฐ์„œ์—ญํ• ์„ ํ•  Nginx๋ฅผ ์œ„ํ•œ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“œ๋Š”๊ฒƒ ๋˜ํ•œ ๋‚ญ๋น„๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

    ์นด๋‚˜๋ฆฌ ๋ฐฐํฌ ๋˜ํ•œ ๋กœ๋“œ๋ฒจ๋Ÿฐ์„œ๊ฐ€ ํ•„์š”ํ–ˆ๊ณ  ๋งŒ์•ฝ์— ๋กœ๋“œ๋ฒจ๋Ÿฐ์„œ์™€ ๋ชจ๋“  ํ™˜๊ฒฝ์„ ๊ฐ–์ถ”๊ณ  ๋‚œ ๋’ค ํ•ด๋‹น ๋ฐฐํฌ์ „๋žต์„ ์‚ฌ์šฉํ•œ๋‹ค๊ณ  ํ•ด๋„ ๊ตฌ ๋ฒ„์ „์˜ ์„œ๋ฒ„์™€ ์‹  ๋ฒ„์ „์˜ ์„œ๋ฒ„๋ฅผ ๊ฐ™์ด ๊ด€๋ฆฌํ•ด์•ผํ•˜๋Š” ๊ฒƒ ๋˜ํ•œ ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ํŒ€์›์ด 5๋ช…์ด๋‹ค.

    ํ˜„์žฌ ์šฐ๋ฆฌ์„œ๋ฒ„๋Š” EC2์— docker ๋ฅผ ์‚ฌ์šฉํ•ด Nginx ์™€ application ์„œ๋ฒ„๋ฅผ ๋Œ๋ฆฌ๊ณ  ์žˆ๋‹ค.

    ์ฆ‰ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ง€์šฐ๋Š”๋ฐ ํŽธํ–ˆ๊ณ  htop๋ฅผ ์ด์šฉํ•ด ๋ณธ๊ฒฐ๊ณผ ํ˜„์žฌ 3๊ธฐ๊ฐ€์˜ ์ปดํ“จํ„ฐ ์ž์›์ค‘ 700m๋ฐ–์— ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค. ํผ์„ผํŠธ๋กœ ๊ณ„์‚ฐํ•ด๋ณด๋ฉด 20ํผ์ƒŒํŠธ๋„ ์•ˆ๋˜๋Š” ๊ฐ’์ด๋‹ค.

    ์•ˆ์ •์ ์ธ ์„œ๋น„์Šค๋ฅผ ์œ„ํ•œ CPU์‚ฌ์šฉ์œจ์ด ์ตœ๋Œ€ 70ํผ์„ผํŠธ์ธ ์ˆ˜์น˜์™€ ๋น„๊ต๋ฅผ ํ–ˆ์„๋•Œ ํฌ๊ฒŒ ๋ถ€์กฑํ•œ ์ˆ˜์น˜์ด๋‹ค. ๋”ฐ๋ผ์„œ

    ๋„์ปค๋ฅผ ์ด์šฉํ•ด ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค ๋‚ด์—์„œ ์—ฌ๋Ÿฌ ์„œ๋ฒ„ ๊ทธ๋ฃน์„ ๋งŒ๋“ค์–ด Blue-green ๋ฐฉ์‹์˜ ์ปจ์…‰์„ ์‚ฌ์šฉํ•ด ๋ฌด์ค‘๋‹จ๋ฐฐํฌ๋ฅผ ํ•˜๊ธฐ๋กœ ํ–ˆ๋‹ค.

#!/bin/bash
CURRENT_PORT=$(docker ps | grep springboot | awk {'print $11'}| awk -F '/' {'print $1'} | awk -F '->' {'print $2'})
CURRENT_IP=$(cat /etc/nginx/sites-available/service-url.inc | grep -o http://172.* | sed 's/;$//')
echo $CURRENT_PORT
SERVER1=8080
SERVER2=8081

if [ $CURRENT_PORT -eq $SERVER1 ]
then
        echo " > ํ˜„์žฌ SERVER_PORT: $CURRENT_PORT , SERVER2 CONTAINER ์‹คํ–‰"
        IDLE_PROFILE=$SERVER2
        IDLE_PORT=8081

        sudo docker build --force-rm -t springboot .
	sudo docker rmi $(docker images -f "dangling=true" -q)
        sudo docker stop springboot2
	sudo docker rm $(sudo docker ps -a -f "name=springboot2" -q)
        sudo docker run -d -p 8081:8081 --volume /home/ubuntu/seller-lee/log:/back/build/libs/log --name springboot2 springboot
        CONTAINER_ONE_IP=`sudo docker inspect -f "{{ .NetworkSettings.IPAddress }}" springboot1`
        CONTAINER_TWO_IP=`sudo docker inspect -f "{{ .NetworkSettings.IPAddress }}" springboot2`

        if [ "$(docker ps | grep springboot2)" ]
        then
		        for retry_count in {1..10}
			do
                        response=$(curl -s https://${CONTAINER_TWO_IP}:${SERVER2}/health)
                        count=$( echo $response | grep Download | wc -l)

                        if [ $count -ge 1 ]
                        then
                                echo " > health check ์„ฑ๊ณต"
                                break
                        else
                                echo "> Health check์˜ ์‘๋‹ต์„ ์•Œ ์ˆ˜ ์—†๊ฑฐ๋‚˜ ํ˜น์€ status๊ฐ€ UP์ด ์•„๋‹™๋‹ˆ๋‹ค."
                                echo "> Health check: ${response}"
                        fi

                        if [ $retry_count -eq 10 ]
                        then
                                echo "> Health check ์‹คํŒจ. "
                                echo "> Nginx์— ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๊ณ  ๋ฐฐํฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค."
                                exit 1
                        fi

                        echo "> Health check ์—ฐ๊ฒฐ ์‹คํŒจ. ์žฌ์‹œ๋„..."
                        sleep 10
              done
                echo " > ๋ณ€๊ฒฝํ•  SERVER_PORT: $SERVER1 , CONTAINER_IP: $CONTAINER_ONE_IP ์‹คํ–‰ ์™„๋ฃŒ"
                echo " > ๋ณ€๊ฒฝ SERVER_PORT: $SERVER2 , CONTAINER_IP: $CONTAINER_TWO_IP ์‹คํ–‰ ์™„๋ฃŒ"
                sudo sed -i "s/$CONTAINER_ONE_IP:$SERVER1;/$CONTAINER_TWO_IP:$SERVER2;/g" /etc/nginx/sites-available/service-url.inc
                docker exec nginx nginx -s reload
                docker stop springboot1
                echo " > CONTAINER_IP: $CONTAINER_ONE_IP ์ข…๋ฃŒ"
        fi

elif [ $CURRENT_PORT -eq $SERVER2  ]
then
        echo " > ํ˜„์žฌ SERVER_PORT: $CURRENT_PORT , SERVER1 CONTAINER ์‹คํ–‰"
        IDLE_PROFILE=$SERVER1
        IDLE_PORT=8080

        sudo docker build --force-rm -t springboot .
        sudo docker rmi $(docker images -f "dangling=true" -q)
        sudo docker stop springboot1
        sudo docker rm $(sudo docker ps -a -f "name=springboot1" -q)
        sudo docker run -d -p 8080:8080 --volume /home/ubuntu/seller-lee/log:/back/build/libs/log --name springboot1 springboot
        CONTAINER_ONE_IP=`sudo docker inspect -f "{{ .NetworkSettings.IPAddress }}" springboot1`
        CONTAINER_TWO_IP=`sudo docker inspect -f "{{ .NetworkSettings.IPAddress }}" springboot2`

        if [ "$(docker ps | grep springboot1)" ]
        then
               	for retry_count in {1..10}
               	do
                      	response=$(curl -s https://${CONTAINER_ONE_IP}:${SERVER1}/health)
                       	count=$( echo $response | grep Download | wc -l)

                       	if [ $count -ge 1 ]
                       	then
                       	        echo " > health check ์„ฑ๊ณต"
                       	        break
                       	else
                       	        echo "> Health check์˜ ์‘๋‹ต์„ ์•Œ ์ˆ˜ ์—†๊ฑฐ๋‚˜ ํ˜น์€ status๊ฐ€ UP์ด ์•„๋‹™๋‹ˆ๋‹ค."
                       	        echo "> Health check: ${response}"
                       	fi
	
                       	if [ $retry_count -eq 10 ]
                       	then
                       	        echo "> Health check ์‹คํŒจ. "
                       	        echo "> Nginx์— ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๊ณ  ๋ฐฐํฌ๋ฅผ ์ข…๋ฃŒํ•ฉ๋‹ˆ๋‹ค."
                       	        exit 1
                       	fi

                       	echo "> Health check ์—ฐ๊ฒฐ ์‹คํŒจ. ์žฌ์‹œ๋„..."
                       	sleep 10
		done
		sudo sed -i "s/$CONTAINER_TWO_IP:$SERVER2;/$CONTAINER_ONE_IP:$SERVER1;/g" /etc/nginx/sites-available/service-url.inc
		echo " > ๋ณ€๊ฒฝํ•  SERVER_PORT: $SERVER1 , CONTAINER_IP: $CONTAINER_ONE_IP ์‹คํ–‰ ์™„๋ฃŒ"
                docker exec nginx nginx -s reload
                docker stop springboot2
                echo " > CONTAINER_IP: $CONTAINER_TWO_IP ์ข…๋ฃŒ"
        fi
fi