๐Ÿ‹๐Ÿณ1) Travis CI + Docker + S3 + CodeDeploy + nginx + springboot ์ด๋ฏธ์ง€, ์ปจํ…Œ์ด๋„ˆ๋ฅผ EC2 ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•˜๊ธฐ

๊น€์„ฑ์ธยท2023๋…„ 9์›” 20์ผ
1

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
6/62

์ด์ „์— Travis CI + S3 + CodeDeploy ๋ฅผ ํ†ตํ•ด ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ EC2 ์ธ์Šคํ„ด์Šค์— ๋ฐฐํฌํ•˜๋Š” ๊ณผ์ •๊นŒ์ง€ ์ง„ํ–‰ํ•˜์˜€๋‹ค.

๋‚˜๋Š” ๋„์ปค๋ฅผ ํ†ตํ•œ ๋ฐฐํฌ๋ฅผ ์›ํ•ด์„œ ๊ตฌ๊ธ€๋ง์„ ํ•ด๋ณด๊ธด ํ–ˆ๋Š”๋ฐ, ๋Œ€๋ถ€๋ถ„ "EC2 ํ™˜๊ฒฝ์— ํ”„๋กœ์ ํŠธ๋ฅผ ์˜ฌ๋ฆฌ๊ณ , ์‰˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•ด ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ ํ›„ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ์‹" ์œผ๋กœ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ๊ณผ์ •์ด ์•„๋‹ˆ์—ˆ๋‹ค..

์ฐธ๊ณ ๋ฅผ ๋งŽ์ด ํ–ˆ๋˜ ๋ธ”๋กœ๊ทธ
https://devlog-wjdrbs96.tistory.com/317


๐Ÿณ๐Ÿ”ง๋„์ปค ํ—ˆ๋ธŒ + Travis CI

๋‚ด๊ฐ€ ์›ํ•œ ๋ฐฉ์‹์€ ๋„์ปคํ—ˆ๋ธŒ๋ฅผ ๊ฐ™์ด ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด์—ˆ์Œ.
๊ทธ๋ž˜์„œ ์ƒ๊ฐํ•œ ๋ฐฉ๋ฒ•์€ Travis CI ํ™˜๊ฒฝ์—์„œ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋นŒ๋“œํ•˜์—ฌ ๋„์ปค ํ—ˆ๋ธŒ์— Push, EC2์—์„œ ์ด๋ฏธ์ง€ํŒŒ์ผ์„ Pull ํ•ด์™€์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰์‹œํ‚ค๋Š” ๋™์ž‘์œผ๋กœ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ž‘์„ฑํ•ด๋ณด๊ธฐ๋กœ ํ•˜์˜€๋‹ค.

    1. Git Hub ์ปค๋ฐ‹
    1. Travis CI ์ด๋ฏธ์ง€ ๋นŒ๋“œ ๋ฐ ํ‘ธ์‹œ
    • 2-1) SpringBoot .jarํŒŒ์ผ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด gradle build
    • 2-2) ๋„์ปค ํ—ˆ๋ธŒ์— ํ”„๋กœ์ ํŠธ ์ด๋ฏธ์ง€ Push (SpringBoot .jar๋กœ ์ด๋ค„์ง„)
    • 2-3) Nginx์˜ conf ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ Nginx ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋„์ปคํ—ˆ๋ธŒ์— Push
    1. Travis CI Deploy
    • 3-1) AWS S3์— [์‰˜ ์Šคํฌ๋ฆฝํŠธ, ๋„์ปค ์ปดํฌ์ฆˆ ํŒŒ์ผ, Appspec ํŒŒ์ผ]์„ ์••์ถ•ํ•˜์—ฌ ์—…๋กœ๋“œ
    • 3-2) CodeDeploy๋ฅผ ํ†ตํ•ด EC2์— ํ•ด๋‹น ์••์ถ• ํŒŒ์ผ์„ ์••์ถ•ํ•ด์ œํ•˜์—ฌ ๋ฐฐํฌ
    1. EC2์—์„œ appspecํŒŒ์ผ์˜ ์‰˜ ์Šคํฌ๋ฆฝํŠธ ํŠธ๋ฆฌ๊ฑฐ ๋™์ž‘
    • 4-1) ์‹คํ–‰ ์ค‘์ธ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ํ™•์ธ -> ์ข…๋ฃŒ
    • 4-2) ๋„์ปค ์ตœ์‹  ์ด๋ฏธ์ง€ Pull
    • 4-3) Pullํ•œ ์ตœ์‹  ์ด๋ฏธ์ง€๋กœ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰

๐Ÿ”ง Travis CI ์›Œํฌํ”Œ๋กœ์šฐ

๋‚ด๊ฐ€ ์ƒ๊ฐํ•œ travis.yml ๋™์ž‘ ๋‹จ๊ณ„

  1. Gradle์„ ํ†ตํ•ด jarํŒŒ์ผ ๋นŒ๋“œ
  2. Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ
  3. Docker ํ—ˆ๋ธŒ์— ํ‘ธ์‹œ
  4. ์ปดํฌ๋„ŒํŠธ ๊ด€๋ จ ํŒŒ์ผ ๋””ํ”Œ๋กœ์ด
  5. EC2์—์„œ ๋ฐฐํฌ ํ™•์ธ, Docker Image Pull & Docker Compose Up (์ด๋ฏธ์ง€ ํ’€ ๋ฐ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰) -> ์‰˜ ์Šคํฌ๋ฆฝํŠธ

๋ฐฐํฌ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…


1) .travis.yml ํŒŒ์ผ

์•„๋ž˜ ์ฐฌ์ฐฌํžˆ ๋œฏ์–ด์„œ ์„ค๋ช…ํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค.

branches:
  only:
    - master

services:
  - docker

jobs:
  include:
    - stage: SpringBoot gradle build & Build Gradle Docker Image
      language: java
      jdk:
        - openjdk11

      #cache:
      #  directories:
      #    - '$HOME/ .m2/repository'
      #    - '$HOME/ .gradle'
      before_install:
        - chmod +x gradlew
      script:
        - ./gradlew clean build
        - docker build -t $SPRING_REPO -f ./Dockerfile .
        - echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
        - docker push $SPRING_REPO

    - stage: Build Nginx Docker image
      sudo: required
      language: generic
      script:
        - docker build -t $NGINX_REPO -f ./Dockerfile-nginx .
        - echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
        - docker push $NGINX_REPO

    - stage: Deploy Stage
      language: generic

      before_deploy:
        - zip -r "s3์— ๋“ฑ๋กํ•  ํŒŒ์ผ ์ด๋ฆ„" ./docker-compose.yaml ./appspec.yml
        - mkdir -p deploy -- ๋ฐฐํฌ์‹œ ์ฐธ์กฐํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ
        - mv "s3์— ๋“ฑ๋กํ•  ํŒŒ์ผ ์ด๋ฆ„".zip deploy/prac-built.zip
      after_success:
        - wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
        - chmod +x send.sh
        - ./send.sh success $WEBHOOK_URL
      deploy:
        - provider: s3
          access_key_id: $AWS_ACCESS_KEY
          secret_access_key: $AWS_ACCESS_SECRET
          bucket: s3 ๋ฒ„ํ‚ท์ด๋ฆ„
          region: ap-northeast-2
          skip_cleanup: true
          acl: private
          local_dir: deploy -- ๋ฐฐํฌ์‹œ ์ฐธ์กฐํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ
          wait-until-deployed: true

        - provider: codedeploy
          access_key_id: $AWS_ACCESS_KEY
          secret_access_key: $AWS_ACCESS_SECRET
          bucket: s3 ๋ฒ„ํ‚ท์ด๋ฆ„
          key: s3์— ๋“ฑ๋ก๋œ ํŒŒ์ผ ๊ฐ์ฒด ํ‚ค ๊ฐ’
          bundle_type: zip
          application: ์ฝ”๋“œ ๋””ํ”Œ๋กœ์ด ์•ฑ ์ด๋ฆ„
          deployment_group: ์ฝ”๋“œ ๋””ํ”Œ๋กœ์ด ๊ทธ๋ฃน ์ด๋ฆ„
          region: ap-northeast-2
          wait-until-deployed: true

1-1) ๊ธฐ๋ณธ ์„ค์ •

branches:
  only:
    - master

services:
  - docker
  • branches: Travis CI๊ฐ€ github์— ์–ด๋–ค ๋ธŒ๋ Œ์น˜์— ์ปค๋ฐ‹์ด ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ํ•ด๋‹น travis ํŒŒ์ผ์„ ์‹คํ–‰ํ• ์ง€ ์ •ํ•จ.
  • services: Travis ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰ํ•  ์„œ๋น„์Šค

docker build

docker build -t ์ด๋ฏธ์ง€์ด๋ฆ„:latest -f ./๋„์ปคํŒŒ์ผ .
// -f : ํŠน์ • ๋„์ปคํŒŒ์ผ์„ ์ง€์ •ํ• ๋•Œ ์“ฐ๋Š” ์˜ต์…˜
// ์ด๋ฏธ์ง€์ด๋ฆ„ : ํ—ˆ๋ธŒ์— ์ €์žฅ๋œ ์œ ์ €๋„ค์ž„/๋ ˆํฌ์ด๋ฆ„ ์ด๋ ‡๊ฒŒ๋„ ์“ธ์ˆ˜์žˆ์Œ
// . : ๋„์ปคํŒŒ์ผ์ด ์žˆ๋Š” ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ

language

language: ์‚ฌ์šฉํ•  ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋‚˜ ํ”„๋ ˆ์ž„ ์›Œํฌ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋ถ€๋ถ„.
ex) language: java -> ์ž๋ฐ”๋กœ ์„ค์ •, language: generic

1-2) Travis CI ๋‹จ๊ณ„๋ณ„ ์ž‘์—…

https://docs.travis-ci.com/user/job-lifecycle/
https://docs.travis-ci.com/user/build-stages/

jobs:
  include:
    - stage:
  • jobs: ๋‹จ๊ณ„๋ณ„ ์ž‘์—…์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ธ”๋Ÿญ. jobs ๋ธ”๋ก์— ์ •์˜๋œ ์ž‘์—…์€ ์ˆœ์„œ๋Œ€๋กœ ์‹คํ–‰๋˜๋ฉฐ, ๊ฐ ์ž‘์—…์ด ์ด์ „ ์ž‘์—…์ด ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋˜์–ด์•ผ๋งŒ ์‹คํ–‰
  • include: ์ž‘์—…์˜ ์„ธ์…˜ ์ •์˜๋ฅผ ์œ„ํ•œ ๋ธ”๋Ÿญ
  • stage: ์œ„->์•„๋ž˜๋กœ ์ง„ํ–‰๋˜๋Š” ๋‹จ๊ณ„๋ณ„ ์ž‘์—…, ์ด๋ฆ„์„ ๋ถ€์—ฌํ•˜๊ณ , Travis CI์˜ ๋นŒ๋“œ ์Šคํ…Œ์ด์ง€์—์„œ ์ด๋ฅผ ํ™•์ธ ๊ฐ€๋Šฅํ•จ.
jobs:
  include:
    - stage: SpringBoot gradle build & Build Gradle Docker Image
      language: java
      jdk:
        - openjdk11

      #cache:
      #  directories:
      #    - '$HOME/ .m2/repository'
      #    - '$HOME/ .gradle'
      before_install:
        - chmod +x gradlew
      script:
        - ./gradlew clean build
        - docker build -t $SPRING_REPO -f ./Dockerfile .
        - echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
        - docker push $SPRING_REPO
  • SpringBoot ํ”„๋กœ์ ํŠธ๋ฅผ gradle ํŒŒ์ผ์„ ์ด์šฉํ•ด ๋นŒ๋“œํ•˜๊ณ ,
  • ๋นŒ๋“œ๋œ .jarํŒŒ์ผ์„ ์ด์šฉํ•ด ๋„์ปค ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋นŒ๋“œํ•˜๊ณ  ๋„์ปคํ—ˆ๋ธŒ์— ํ‘ธ์‰ฌ.
  • .jarํŒŒ์ผ์„ ๋นŒ๋“œ ํ•˜์ž๋งˆ์ž ๋„์ปค ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋นŒ๋“œํ•œ ์ด์œ ๋Š” ๋‘ ์ž‘์—…์„ ๋ถ„๋ฆฌํ•˜์—ฌ stage๋ฅผ ์ž‘์„ฑํ• ์‹œ์— ๊ฐ stage๋Š” ์„œ๋กœ ๋‹ค๋ฅธ vm ํ™˜๊ฒฝ์—์„œ ์‹คํ–‰๋˜์–ด์„œ ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ์‹œ .jarํŒŒ์ผ์„ ์ฐพ์„์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ..
    ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…
    - stage: Build Nginx Docker image
      sudo: required
      language: generic
      script:
        - docker build -t $NGINX_REPO -f ./Dockerfile-nginx .
        - echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
        - docker push $NGINX_REPO
  • SpringBoot์— ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋ฅผ ํ†ตํ•ด ํฌํŠธํฌ์›Œ๋”ฉ์„ ํ•ด์ค„ nginx ๋„์ปค ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ›„ ๋„์ปค ํ—ˆ๋ธŒ์— ํ‘ธ์‹œ
    - stage: Deploy Stage
      language: generic

      before_deploy:
        - zip -r "s3์— ๋“ฑ๋กํ•  ํŒŒ์ผ ์ด๋ฆ„" ./docker-compose.yaml ./appspec.yml
        - mkdir -p deploy -- ๋ฐฐํฌ์‹œ ์ฐธ์กฐํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ
        - mv "s3์— ๋“ฑ๋กํ•  ํŒŒ์ผ ์ด๋ฆ„".zip deploy/prac-built.zip
      after_success:
        - wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
        - chmod +x send.sh
        - ./send.sh success $WEBHOOK_URL
      deploy:
        - provider: s3
          access_key_id: $AWS_ACCESS_KEY
          secret_access_key: $AWS_ACCESS_SECRET
          bucket: s3 ๋ฒ„ํ‚ท์ด๋ฆ„
          region: ap-northeast-2
          skip_cleanup: true
          acl: private
          local_dir: deploy -- ๋ฐฐํฌ์‹œ ์ฐธ์กฐํ•  ๋””๋ ‰ํ„ฐ๋ฆฌ
          wait-until-deployed: true

        - provider: codedeploy
          access_key_id: $AWS_ACCESS_KEY
          secret_access_key: $AWS_ACCESS_SECRET
          bucket: s3 ๋ฒ„ํ‚ท์ด๋ฆ„
          key: s3์— ๋“ฑ๋ก๋œ ํŒŒ์ผ ๊ฐ์ฒด ํ‚ค ๊ฐ’
          bundle_type: zip
          application: ์ฝ”๋“œ ๋””ํ”Œ๋กœ์ด ์•ฑ ์ด๋ฆ„
          deployment_group: ์ฝ”๋“œ ๋””ํ”Œ๋กœ์ด ๊ทธ๋ฃน ์ด๋ฆ„
          region: ap-northeast-2
          wait-until-deployed: true
  • before_deploy: ๋ฐฐํฌ์ „ ํ•  ๋™์ž‘์„ ์Šคํฌ๋ฆฝํŠธ ๋™์ž‘์„ ์ •์˜

    • ๋ฐฐํฌํ•  ํŒŒ์ผ์„ s3์— ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด zipํŒŒ์ผ์— ๋‹ด์Œ.
    • ๋ฐฐํฌ๋ฅผ ์ฐธ์กฐํ•  ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ƒ์„ฑ
    • ๋ฐฐํฌํ•  ํŒŒ์ผ์„ ํ•ด๋‹น ์ฐธ์กฐ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™
  • after_success: ๋ฐฐํฌ ์„ฑ๊ณต ํ›„ ๋™์ž‘

  • deploy: ๋ฐฐํฌํ•˜๋Š” ๋™์ž‘์„ ์ •์˜ํ•˜๋Š” ๋ธ”๋Ÿญ

    • provider: s3: ๋ฒ„ํ‚ท์— ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์„ ์ •์˜
      access_key_id ๋ฐ secret_access_key: AWS ๊ณ„์ •์˜ ์•ก์„ธ์Šค ํ‚ค ID ๋ฐ ๋น„๋ฐ€ ์•ก์„ธ์Šค ํ‚ค๋ฅผ ์„ค์ •
      bucket: S3 ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์„ ์ง€์ •
      region: AWS ๋ฆฌ์ „์„ ์ง€์ •
      skip_cleanup: ๋นŒ๋“œ ํ›„์— ์ž‘์—… ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ •๋ฆฌํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •
      acl: S3 ๊ฐ์ฒด์— ๋Œ€ํ•œ ์•ก์„ธ์Šค ์ œ์–ด๋ฅผ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค (์—ฌ๊ธฐ์„œ๋Š” private์œผ๋กœ ์„ค์ •).
      local_dir: ๋ฐฐํฌ์— ์‚ฌ์šฉํ•  ๋กœ์ปฌ ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์ง€์ • (์ด ๋””๋ ‰ํ„ฐ๋ฆฌ์˜ ํŒŒ์ผ๋“ค์„ S3๋กœ ์—…๋กœ๋“œ).
      wait-until-deployed: ๋ฐฐํฌ๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆด์ง€ ์—ฌ๋ถ€

    • provider: codedeploy: AWS CodeDeploy๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐฐํฌ๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •
      access_key_id ๋ฐ secret_access_key: AWS ๊ณ„์ •์˜ ์•ก์„ธ์Šค ํ‚ค ID ๋ฐ ๋น„๋ฐ€ ์•ก์„ธ์Šค ํ‚ค๋ฅผ ์„ค์ •
      bucket: CodeDeploy์—์„œ ์‚ฌ์šฉํ•  S3 ๋ฒ„ํ‚ท์˜ ์ด๋ฆ„์„ ์ง€์ •
      key: S3 ๋ฒ„ํ‚ท์— ๋“ฑ๋ก๋œ ํŒŒ์ผ ๊ฐ์ฒด์˜ ํ‚ค ๊ฐ’
      bundle_type: ๋ฐฐํฌํ•  ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๋ฒˆ๋“ค ํƒ€์ž…์„ ์ง€์ •(์—ฌ๊ธฐ์„œ๋Š” zip).
      application: CodeDeploy ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ด๋ฆ„์„ ์ง€์ •
      deployment_group: CodeDeploy ๋ฐฐํฌ ๊ทธ๋ฃน์˜ ์ด๋ฆ„์„ ์ง€์ •
      region: AWS ๋ฆฌ์ „
      wait-until-deployed: ๋ฐฐํฌ๊ฐ€ ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆด์ง€ ์—ฌ๋ถ€๋ฅผ ์„ค์ •


2) Docker ํŒŒ์ผ

2-1) Dockerfile

FROM openjdk:11
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=${active}", "-Duser.timezone=Asia/Seoul", "/app.jar"]

2-2) Docker-nginx

FROM nginx
COPY nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf

2-3) docker-compose.yaml

version: "3"
services:
  web:
    image: adultkim/jpa-nginx:latest
    container_name: nginx
    restart: always
    ports:
      - "80:80"

  spring:
    build: .
    image: adultkim/jpapractice:latest
    container_name: server
    expose:
      - 8081
    ports:
      - "8081:8081"
    environment:
      active: prod


3) appspec.yml

version: 0.0
os: linux
files:
  - source:  /
    destination: /home/ubuntu/app/docker/zip
    overwrite: yes

hooks:
  AfterInstall:
    - location: docker-hub.sh
      timeout: 300
      runas: root

https://jinmay.github.io/2020/05/13/aws/run-shell-script-aws-code-deploy/
https://docs.aws.amazon.com/ko_kr/codedeploy/latest/userguide/reference-appspec-file.html

4) Shell Script

#!/bin/bash

container_id=$(docker ps -qa)

if [ -z ${container_id} ]
then
        echo "ํ˜„์žฌ ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ X"
else
        echo "ํ˜„์žฌ ์‹คํ–‰์ค‘์ธ ์ปจํ…Œ์ด๋„ˆ: ${container_id}"
        echo "์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€"
        sudo docker stop ${container_id}
        echo "์ปจํ…Œ์ด๋„ˆ ์‚ญ์ œ"
        sudo docker rm -f ${container_id}

        sleep 3
fi

echo "์ด๋ฏธ์ง€ ํŒŒ์ผ Pull"
sudo docker pull adultkim/jpapractice:latest
sudo docker pull adultkim/jpa-nginx:latest

echo "์ปจํ…Œ์ด๋„ˆ ์žฌ ์‹œ์ž‘"
docker-compose -f /home/ubuntu/app/docker/zip/docker-compose.yaml up -d

๐ŸŽจ๊ฐœ๋… ์ ๋ฆฝ

๋ฐฐํฌ ๊ณผ์ •๊ณผ ๋„์ปค ์ด๋ฏธ์ง€/์ปจํ…Œ์ด๋„ˆ ์˜ ์ฐจ์ด์— ๋Œ€ํ•œ ์ „๋ฐ˜์ ์ธ ํ๋ฆ„์— ๋Œ€ํ•œ ์ดํ•ด๊ฐ€ ๋ถ€์กฑํ–ˆ์—ˆ์ง€๋งŒ ๋ชจ๋“  ๊ณผ์ •์„ ํ•˜๋ฉด์„œ ์•Œ๊ฒŒ ๋œ ์‚ฌ์‹ค๋“ค์„ ์ ์–ด ๋ณด์•˜๋‹ค..
GPT ๋„์›€์„ ๋งŽ์ด ๋ฐ›์Œ..ใ…Žใ…Ž

1) Travis CI

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์—์„œ TravisCI ์˜ ์—ญํ• ์€ GitHub์— ์ปค๋ฐ‹๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด์ž๋งˆ์ž ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ํ†ตํ•ฉํ•˜๊ณ , ๋ฐฐํฌํ•˜๊ธฐ ์œ„ํ•œ ์ •ํ•ด์ง„ ์ผ๋ จ์˜ ์ž‘์—…๋“ค์„ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. (๋น„์Šทํ•œ ์˜ˆ๋กœ๋Š” GitHub Action ๋„ ์กด์žฌํ•จ)

2) S3

S3๋Š” Travis CI์—์„œ ๋นŒ๋“œ๋œ ํŒŒ์ผ๊ณผ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ผ, ์ด๋ฏธ์ง€ํŒŒ์ผ์„ Pullํ•˜๊ณ  ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‹คํ–‰ํ•  ์‰˜ ์Šคํฌ๋ฆฝํŠธ ๋“ฑ EC2์—์„œ ํ•„์š”ํ•œ ํŒŒ์ผ๋“ค์„ ๋ฐฐํฌํ•˜๊ธฐ์ „์— ์ €์žฅํ•ด๋†“๋Š” ์™ธ๋ถ€ ์ €์žฅ์†Œ ์—ญํ• ์„ ํ•  ๊ฒƒ์ด๋‹ค.

3) Code Deploy

CodeDeploy๋Š” S3์— ์ €์žฅ๋œ ํŒŒ์ผ๋“ค์„ EC2์ธ์Šคํ„ด์Šค์— ๋ฐฐํฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

4) ์ด๋ฏธ์ง€(Image)

  • ๋‚˜๋Š” ์ฒ˜์Œ์— ์ด๋ฏธ์ง€๋ผ๋Š” ๊ฐœ๋…์ด ๋„ˆ๋ฌด ์ƒ์†Œํ•˜๊ณ , ์–ด๋–ป๊ฒŒ ๋ฐ›์•„๋“ค์—ฌ์•ผ ํ• ์ง€ ๋ชฐ๋ž๋‹ค.

  • ํ•˜์ง€๋งŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ชจ๋“  ์„ค์ •์ด ๋ชจ๋‘ ๋๋‚œ ํŒจํ‚ค์ง€๋ผ๋Š” ๋ง์„ ๋ณด๊ณ , ๊ทธ๋ƒฅ ์‹คํ–‰ํ•˜๊ธฐ ์ „ ๋นŒ๋“œ ์™„๋ฃŒ๋œ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ์‰ฝ๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด ๋˜๊ฒ ๋‹ค๊ณ  ๋Š๋‚Œ..
    ๋˜ ๋ฐฐํฌํ•˜๋Š” ๊ณผ์ •์—์„œ ๋„์ปคํŒŒ์ผ์ด SpringBoot ํ”„๋กœ์ ํŠธ์—์„œ ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋งŒ๋“œ๋Š” ๊ธฐ์ค€์€ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์˜ .jarํŒŒ์ผ์„ ๊ฐ€์ง€๊ณ  ์ง„ํ–‰ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— ๋นŒ๋“œ๊ฐ€ ์™„๋ฃŒ๋˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ๊ธฐ ์ „์šฉ ํŒŒ์ผ์ด๊ตฌ๋‚˜ ๋ผ๊ณ  ๋Š๋ผ๊ฒŒ ๋˜์—ˆ๋‹ค.
    ex) .jarํŒŒ์ผ, Ubuntu ์ด๋ฏธ์ง€ ํŒŒ์ผ

5) ์ปจํ…Œ์ด๋„ˆ(Container)

  • ์ปจํ…Œ์ด๋„ˆ๋Š” ๋งˆ์นจ๋‚ด ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ํ•˜๋‚˜์˜ ์ธ์Šคํ„ด์Šค๋กœ ์‹คํ–‰ํ•˜๊ฒŒ ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.
  • ์ปจํ…Œ์ด๋„ˆ๋ผ ํ•จ์€ ์šฐ๋ฆฌ๊ฐ€ ๊ฐ€์ƒ๋จธ์‹ ์„ ์ด์šฉํ•ด์„œ ํ•œ OS์—์„œ ์—ฌ๋Ÿฌ OS๋ฅผ ๋Œ๋ฆฌ๋“ฏ์ด, ์ด๋ฏธ์ง€ ํŒŒ์ผ์ด ๊ฒฉ๋ฆฌ๋œ ๊ณต๊ฐ„์˜ ๋…๋ฆฝ๋œ ํ”„๋กœ์„ธ์Šค๋กœ์„œ ๋Œ์•„๊ฐ€๊ฒŒ๋œ๋‹ค.
  • ์ฆ‰ ๋„์ปค์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ด๋ฏธ์ง€ ํŒŒ์ผ๋กœ ๋นŒ๋“œํ•œ ํ›„, ์ปจํ…Œ์ด๋„ˆ๋ฅผ ํ†ตํ•ด ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ!

0๊ฐœ์˜ ๋Œ“๊ธ€