[๐Ÿš— ์ž๋™ํ™” ๊ฐœ๋ฐœ ํšŒ๊ณ ] Husky, git action, ECR, ECS๋ฅผ ์ด์šฉํ•œ ์•ˆ์ •์  ๋ฐฐํฌํ™˜๊ฒฝ ๊ตฌ์ถ• ( 2 )

devAndersonยท2024๋…„ 3์›” 20์ผ
0

๐Ÿš Intro

์ €๋ฒˆ ๊ธ€์˜ ๋‚ด์šฉ์ด ๊ธธ์–ด์ง์— ๋”ฐ๋ผ, ๋‚˜๋ˆ„์–ด์„œ ๊ธ€์„ ์ž‘์„ฑํ•œ๋‹ค.

๊ธฐ์กด ๊ธ€์˜ ๋งˆ์ง€๋ง‰ ๋ถ€๋ถ„์€ ์ตœ์ข… CICD ํŒŒ์ผ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๋ฌผ์„ ์ž‘์„ฑํ•˜๊ณ  ๋์ด ๋‚ฌ๋‹ค.

name: Continuous Integration and Deployment

on:
  pull_request:
    branches:
      - develop
    types: [closed]

jobs:
  ### step 1. code integration check
  CI:
    runs-on: self-hosted
    if: github.event.pull_request.merged == true
    env:
      BRANCH: develop
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          ref: ${{ env.BRANCH }}
          token: ${{ secrets.ACCESS_TOKEN }}

      - name: Set node environment
        uses: actions/setup-node@v4
        with:
          node-version: 20.11.1 # see .nvmrc

      - name: Caching Primes # for this case, node_modules
        id: cache-primes
        uses: actions/cache@v4
        with:
          path: node_modules
          key: npm-packages-${{ hashFiles('**/package-lock.json') }}

      - name: Install dependencies if no cache
        if: steps.cache-primes.outputs.cache-hit != 'true'
        run: npm install

      - run: npm run check:lint
      - run: npm run check:type

  ### step 2. publish code to external environment
  CD:
    needs: CI # If CI is done, then do CD
    runs-on: self-hosted
    steps:
      - name: AWS credential
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # IAM access key
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # IAM access
          aws-region: ${{ secrets.AWS_REGION }}

      # 1. ECR
      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v2 # result : registry (ECR repo uri)

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        env:
          ECR_REPO_URI: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPO_NAME: ${{ secrets.ECR_REPO_NAME }}
          IMAGE_TAG: ${{ github.sha }}
        run: |
          IMAGE_NAME='${{ env.ECR_REPO_URI }}/${{ env.ECR_REPO_NAME }}:${{ env.IMAGE_TAG }}'
          docker build -t ${IMAGE_NAME} .
          docker push ${IMAGE_NAME}
          docker system prune --volumes -a -f
          echo "image=${IMAGE_NAME}" >> $GITHUB_OUTPUT

      # 2. ECS
      # https://fig.io/manual/aws/ecs/describe-task-definition
      - name: Generate task-definition.json from latest active ECS task definition
        run: |
          aws ecs describe-task-definition \
            --task-definition ${{ secrets.ECS_TASK_DEFINITION }} \
            --query taskDefinition \
            > task-definition.json

      - name: Render Amazon ECS task definition
        id: render-task-definition
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          # this step exports the task-definition as an output automatically (used from next step)
          task-definition: task-definition.json
          container-name: ${{ secrets.ECS_TASK_CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}

      - name: Deploy Amazon ECS task definition
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: ${{ steps.render-task-definition.outputs.task-definition }}
          service: ${{ secrets.ECS_SERVICE }}
          cluster: ${{ secrets.ECS_CLUSTER }}
          wait-for-service-stability: true

CI๋Š” ์‚ฌ์‹ค์ƒ lint์™€ type ์ฒดํฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์— ๋ถˆ๊ณผํ•ด์„œ ํŠน๋ณ„ํ•œ ๋‚ด์šฉ์€ ์—†์ง€๋งŒ, CD ๋ถ€๋ถ„์€ ์•„๋ฌด๋ž˜๋„ composite action์ด ๋งŽ๋‹ค๋ณด๋‹ˆ, ๊ฐ๊ฐ์˜ ์•ก์…˜๋“ค์ด ์„ค๋ช…ํ•˜๋Š” ์กฐ๊ฑด๋“ค์„ ์ž˜ ์ดํ•ดํ•ด์•ผ ํ–ˆ๋‹ค.

์šฐ์„  ๋‚˜๋Š” ECR ๋ฐ ECS๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ž‘์„ฑํ•˜์˜€๋‹ค.

AWS์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ ๊ธฐ์—๋Š” ๋‚˜๋„ ์•„์ง ๊ณต๋ถ€๊ฐ€ ๋ถ€์กฑํ•˜๊ธฐ์— ๊ทธ๋ƒฅ ํ•„์š”ํ•œ ํ•ต์‹ฌ๋งŒ ์„ค๋ช…์œผ๋กœ ๋‚จ๊ฒจ๋†“๋Š”๋‹ค.

์ฐธ๊ณ ๋กœ, ์ €๋ ‡๊ฒŒ ํ•œ ํŒŒ์ผ๋กœ ์ž…๋ ฅํ•˜์ง€ ์•Š๊ณ  ๋‹น์—ฐํžˆ CIํŒŒ์ผ, CD ํŒŒ์ผ์„ ๋ถ„๋ฆฌํ•ด์„œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ๋‚ซ๋‹ค. ์œ„ ๋‚ด์šฉ์€ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด์„œ ํ•œ ํŒŒ์ผ์— ๋‹ค ์ž‘์„ฑํ•œ ๋ฒ„์ „์ด๋‹ค.

๊ฐœ์ธ์ ์œผ๋กœ ๋„์ปค๋ฅผ ํ†ตํ•œ ํ”„๋ก ํŠธ์—”๋“œ ๋ฐฐํฌ์— ๋Œ€ํ•ด ๊ฐœ์ธ์ ์œผ๋กœ ๋Š๋ผ๋Š” ์•„์‰ฌ์šด ์ ์ด ์ข€ ์žˆ์–ด์„œ nginx๋ฅผ ํ†ตํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ๋ฅผ ๊ตฌํ˜„ํ•˜์˜€๊ณ , ์ด์— ๋Œ€ํ•ด์„œ ๋‹ค์Œ๊ธ€์— ๊ธฐ์ˆ ํ•ด๋‘”๋‹ค.

์ด ๊ธฐ๋ก์€ ๋‚˜์ค‘์— ๋„์ปค๋ฅผ ํ†ตํ•ด ๋ฐฐํฌํ•ด์•ผ ํ•˜๋Š” ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์ผ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด์„œ ๋ฌธ์„œํ™”ํ•˜๋Š” ๋‚ด์šฉ์ด๋‹ค.


1. ๐Ÿš ECR

1. AWS credential

   steps:
     - name: AWS credential
       uses: aws-actions/configure-aws-credentials@v4
       with:
         aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} # IAM access key
         aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} # IAM secret key
         aws-region: ${{ secrets.AWS_REGION }}

์šฐ์„  AWS์— ์ ‘๊ทผํ•˜์—ฌ ์ž‘์—…์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” credential์„ ์–ป์–ด์•ผ ํ•œ๋‹ค.
region์€ ์–ด๋ ค์šธ ๊ฒŒ ์—†์„ํ…๋ฐ, access key๋ž‘ secret access key๋Š” ์–ด๋””์„œ ์–ป๋Š”์ง€ ์ฒ˜์Œํ•˜๋Š” ์‚ฌ๋žŒ์€ ์ƒ์†Œํ•  ๊ฒƒ์ด๋‹ค.
์ด credential์„ ์–ป๊ธฐ ์œ„ํ•œ access,key์™€ secret key๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์žฅ์†Œ์—์„œ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค. ( ์ด๋ฏธ ๋ฐฑ์—”๋“œ ๋ถ„๋“ค์—๊ฒŒ IAM ๊ณ„์ •์„ ๋ถ€์—ฌ๋ฐ›์•˜๋‹ค๋Š” ์ „์ œ ํ•˜์—์„œ ์ž‘์„ฑํ•œ๋‹ค)

    1. IAM ์— ์ ‘์†
    1. ์‚ฌ์šฉ์ž ํด๋ฆญ => ๋‚ด ๊ณ„์ •์œผ๋กœ ๋“ค์–ด๊ฐ€๊ธฐ

    1. ๋ณด์•ˆ์ž๊ฒฉ์ฆ๋ช…์˜ ์•ก์„ธ์Šค ํ‚ค ๋งŒ๋“ค๊ธฐ
    1. ์ปดํ“จํŒ… ์„œ๋น„์Šค์šฉ key ์ƒ์„ฑ
    1. ์ƒ์„ฑ๋œ ์•ก์„ธ์Šคํ‚ค(access-key), ๋น„๋ฐ€ ์•ก์„ธ์Šค ํ‚ค action์˜ secret์œผ๋กœ ๋“ฑ๋ก


2. ECR login and push image to ECR

      # 1. ECR
      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v2 # result : registry (ECR repo uri)
        
      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        env:
          ECR_REPO_URI: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPO_NAME: ${{ secrets.ECR_REPO_NAME }}
          IMAGE_TAG: ${{ github.sha }}
        run: |
          IMAGE_NAME='${{ env.ECR_REPO_URI }}/${{ env.ECR_REPO_NAME }}:${{ env.IMAGE_TAG }}'
          docker build -t ${IMAGE_NAME} .
          docker push ${IMAGE_NAME}
          docker system prune --volumes -a -f
          echo "image=${IMAGE_NAME}" >> $GITHUB_OUTPUT

ECR์ด๋ผ๋Š” ๊ฒƒ์„ ๋‚˜๋„ ์ด๋ฒˆ์— ์ฒ˜์Œ ๋“ค์–ด๋ดค๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ์–ด๋ ค์šด ๊ฐœ๋…์€ ์•„๋‹ˆ๊ณ  ๊ทธ๋ƒฅ ๋นŒ๋“œ๋œ ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•ด์„œ ECS์˜ ์›๋ฃŒ(?) ๋กœ ์“ฐ์ด๊ธฐ ์œ„ํ•œ S3๊ฐ™์€ ์ €์žฅ์†Œ๋ผ๊ณ  ์—ฌ๊ธฐ๋ฉด ๊ฐ€์žฅ ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์› ๋‹ค.

์šฐ์„  ๊ฒ€์ƒ‰์ฐฝ์— ecr์„ ์ž…๋ ฅํ•˜์—ฌ ์•„๋ž˜์— ๋ณด์ด๋Š” ํ”„๋ผ์ด๋น— ECR ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋ฅผ ํด๋ฆญํ•œ๋‹ค.

์ดํ›„, ์˜†์˜ ํƒญ์—์„œ "Repositories"๋ฅผ ํด๋ฆญํ•œ ๋’ค, ๋ ˆํฌ์ง€ํ† ๋ฆฌ ์ƒ์„ฑ์„ ํด๋ฆญํ•ด์„œ ์ƒ์„ฑํ•˜๋ฉด ๋œ๋‹ค. ์ƒ์„ฑํƒญ์— ์žˆ๋Š” UI ์ž…๋ ฅ๋‚ด์šฉ์€ ๋ชน์‹œ ๊ฐ„๋‹จํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๋žตํ•œ๋‹ค.

์ƒ์„ฑ ํ›„ ๋งŒ๋“ค์–ด์ง€๋Š” ์œ„ ๋‘ ํƒญ ์ค‘์— ๋‘๋ฒˆ์งธ๊ฐ€ ๋ฐ”๋กœ git action secret์˜ ECR_REPO_NAME์œผ๋กœ ๋“ค์–ด๊ฐ€์•ผ ํ•˜๋Š” ๊ฐ’์ด ๋œ๋‹ค. ( ECR_REPO_URI ๋Š” git action step์—์„œ ECR๋กœ ๋กœ๊ทธ์ธํ•˜๋Š” ์ˆœ๊ฐ„ ์ž๋™์œผ๋กœ ๋ฐ›์•„์™€์ง )

ECR_REPO_URI๋Š” ์ถ”ํ›„ ECS์˜ ์ž‘์—… ์ •์˜๋ฅผ ์ƒ์„ฑํ•  ๋•Œ ์‚ฌ์šฉ๋˜์•ผ ํ•˜๋ฏ€๋กœ ๋ฏธ๋ฆฌ ๋ณต์‚ฌํ•ด๋‘์ž.

      - name: Build, tag, and push image to Amazon ECR
        id: build-image
        env:
          ECR_REPO_URI: ${{ steps.login-ecr.outputs.registry }} <-- ์š”๊ธฐ
          ECR_REPO_NAME: ${{ secrets.ECR_REPO_NAME }} <-- ์š”๊ธฐ
          IMAGE_TAG: ${{ github.sha }} # automatically generated
        run: |
          IMAGE_NAME='${{ env.ECR_REPO_URI }}/${{ env.ECR_REPO_NAME }}:${{ env.IMAGE_TAG }}'
          docker build -t ${IMAGE_NAME} .
          docker push ${IMAGE_NAME}
          docker system prune --volumes -a -f
          echo "image=${IMAGE_NAME}" >> $GITHUB_OUTPUT

์ดํ›„ run์— ํ•ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„์€ ๋‹จ์ˆœํ•œ docker ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ›„ ์ด๋ฅผ pushํ•˜๋Š” ๊ณผ์ •์ด ๋“ค์–ด๊ฐ€์žˆ๋‹ค.

IMAGE_NAME์˜ ์•ž์ž๋ฆฌ์— REPO_URI๊ฐ€ ์žˆ์œผ๋ฏ€๋กœ, docker build๋ฅผ ํ†ตํ•ด ๋งŒ๋“ค์–ด์ง€๋Š” ์ด๋ฏธ์ง€๋Š” ์ด URI๋กœ push๋˜๊ฒŒ ๋œ๋‹ค.

์ดํ›„, ๋‚ด MAC OS์—๋Š” ๋นŒ๋“œํ•˜๋ฉด์„œ ๋„์ปค ์˜ค๋ฒ„๋ ˆ์ด๊ฐ€ ์ƒ์„ฑ๋˜๊ฒŒ ๋œ๋‹ค. ์ด ์˜ค๋ฒ„๋ ˆ์ด๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋ ˆ์ด์–ด ๊ฐœ๋…์ฒ˜๋Ÿผ ๋งŒ๋“ค์–ด ์Œ“์•„๊ฐ€๋Š” ๋„์ปค์˜ ํŠน์„ฑ์ƒ, ๋ถˆํ•„์š”ํ•œ ๋ ˆ์ด์–ด๋ฅผ ์žฌ์ƒ์‚ฐํ•˜์ง€ ์•Š๋„๋ก ์บ์‹ฑํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ์ด๊ฒƒ์ด ์šฉ๋Ÿ‰์ด ์ƒ๋‹นํ•œ ํŽธ์ด๋ผ ๋นŒ๋“œ๋ฅผ ํ•  ๋•Œ๋งˆ๋‹ค ๊ณ„์† ์ƒ๊ธฐ๊ธฐ ๋•Œ๋ฌธ์— ์ง€์›Œ์ค˜์•ผ ํ•œ๋‹ค.

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

๊ทธ ๋ช…๋ น์–ด๊ฐ€ run ํŒŒํŠธ์—์„œ ๋ฐ‘์—์„œ ๋‘๋ฒˆ์งธ์ค„์ธ docker system prune --volumes -a -f ์— ํ•ด๋‹นํ•œ๋‹ค.
๋ณผ๋ฅจ ๋ฐ, ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ ๋„คํŠธ์›Œํฌ ๋“ฑ์„ ๋ฐ€์–ด๋ฒ„๋ฆฐ๋‹ค.

์ฐธ๊ณ ๋กœ, run์˜ ๋งˆ์ง€๋ง‰์ค„์ธ echo ... >> $GITHUB_OUTPUT ๋ฌธ๋ฒ•์€ git action์—์„œ ์ œ๊ณตํ•˜๋Š” ๋ฌธ๋ฒ•์œผ๋กœ, ์ €๋ ‡๊ฒŒ ํ•œ ์Šคํƒญ์—์„œ export ๋˜๋Š” ๊ฐ’์€ ๋‹ค๋ฅธ step์—์„œ ${{ steps.์Šคํƒญ ์•„์ด๋””.outputs.image }} ์ด๋Ÿฐ์‹์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค.

IMAGE_TAG: ${{ github.sha }} ์ด๋ฏธ์ง€ ํƒœ๊ทธ๋Š” ๋ฌด์กฐ๊ฑด github์ด ์ œ๊ณตํ•ด์ฃผ๋Š” ํ•ด์‹ฑ๋œ ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ธฐ์กด์˜ ์ด๋ฏธ์ง€์™€ ๋‹ค๋ฅด๋‹ค๋Š” ๊ฒƒ์„ ์„ค์ •ํ•ด์ค˜์•ผ ํ•œ๋‹ค. ๊ทธ๋ ‡์ง€ ์•Š์„ ๊ฒฝ์šฐ ๋ฐฐํฌ๋ฅผ ํ–ˆ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ์ƒˆ๋กœ์šด ECR์˜ ์ด๋ฏธ์ง€๊ฐ€ ECS์—์„œ ๋ฐฐํฌ๋˜์ง€ ์•Š๋Š” ์ƒํ™ฉ์„ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ์ด๋Ÿด ๊ฒฝ์šฐ ์ง์ ‘ ECS์— ๋“ค์–ด๊ฐ€์„œ ๋ฒ„์ „์„ ๋ฐ”๊ฟ”์ค˜์•ผ ํ•˜๋Š” ๋ฒˆ๊ฑฐ๋กœ์›€์ด ์ƒ๊ธด๋‹ค.


3. ๐Ÿš ECS

3. ECS deployment

๋ฐฉ๊ธˆ ์ „ ECR์ด AWS์˜ ์ด๋ฏธ์ง€ ํ—ˆ๋ธŒ์™€ ๊ฐ™์€ ์—ญํ• ์„ ํ•œ๋‹ค๋ฉด, ECS๋Š” ์ด ์ด๋ฏธ์ง€๋ฅผ ์ด์šฉํ•ด์„œ ์ •ํ•ด์ง„ ๋ฐฐํฌ์ „๋žต (๋กค๋ง or ๋ธ”๋ฃจ๊ทธ๋ฆฐ) ์— ๋”ฐ๋ผ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์›Œ์ฃผ๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

์ด ECS๊ฐ€ ์กฐ๊ธˆ ๊ฑด๋“ค๊ฒŒ ๋งŽ์•˜์—ˆ๋‹ค. (๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ, ํƒ€๊ฒŸ๊ทธ๋ฃน ๋“ฑ๋“ฑ)

์šฐ์„ , ๋งŒ์•ฝ ํŒ€ ๋‚ด์— ์ด๋ฏธ ์‚ฌ์šฉ์ค‘์ธ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๊ณ , ์—†๋‹ค๋ฉด ๋จผ์ € ์šฐ์„ ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ค˜์•ผ ํ•œ๋‹ค.

๊ทธ ์ด์œ ๋Š” ๋‚˜์ค‘์— ํ™•์ธํ•ด๋ณด๋ฉด ์•Œ๊ฒ ์ง€๋งŒ ECS ์ž์ฒด๋งŒ์œผ๋กœ๋Š” EC2์ฒ˜๋Ÿผ ํผ๋ธ”๋ฆญ DNS ๊ฐ™์€๊ฒŒ ์—†์œผ๋ฏ€๋กœ ์šฐ๋ฆฌ์˜ ๋„์ปค ์ด๋ฏธ์ง€๊ฐ€ ๋ฐฐํฌ๋œ ECS์— ์ ‘๊ทผํ•˜๋ ค๋ฉด ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ์™€ ์—ฎ์–ด ์ ‘๊ทผํ•˜๋Š” ๋ฐฉ์‹์„ ์ทจํ•ด์•ผ ํ•œ๋‹ค. (๊ทธ๋ฆฌ๊ณ  ์‚ฌ์‹ค EC2์— ๋ฐฐํฌํ•  ๋•Œ์—๋„ ๋‹น์—ฐํ•˜๊ฒ ์ง€๋งŒ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ๋Š” ํ•„์š”ํ•˜๋‹ค. ํฌํŠธํฌ์›Œ๋”ฉ์„ ์œ„ํ•ด์„œ๋ผ๋„, ๋„คํŠธ์›Œํฌ ์š”์ฒญ ๋ถ„์‚ฐ ๋ฐ https ์ ์šฉ์„ ์œ„ํ•ด์„œ๋ผ๋„ ...)


AWS๊ฐ€ ์ต์ˆ™ํ•œ ์‚ฌ๋žŒ๋“ค์—๊ฒŒ๋Š” ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ์˜ ์ž‘๋™์›๋ฆฌ๋ฅผ ๊ตณ์ด ์ƒ๊ฐ ์•ˆํ•ด๋„ ๋˜๊ฒ ์ง€๋งŒ, ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ํ•„์š”ํ•œ ์ด์œ ์— ๋Œ€ํ•ด์„œ nginx๋ฅผ ๋งŒ์ง€์ž‘ํ•˜๋‹ค๊ฐ€ ๊นจ๋‹ซ๋Š” ์ˆœ๊ฐ„์ด ์žˆ์—ˆ์–ด์„œ ์ •๋ฆฌํ•  ๊ฒธ ๋‚จ๊ฒจ๋ณธ๋‹ค.

Nginx๋ž€, ํ•œ๋งˆ๋””๋กœ ๋งํ•ด์„œ ์›น ์„œ๋ฒ„์ด๋‹ค.

์ด ์›น ์„œ๋ฒ„๋Š” ์ธ์Šคํ„ด์Šค ๋‚ด์—์„œ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋ฒ„(WAS) ๋“ค์—๊ฒŒ ์˜ค๋Š” ์š”์ฒญ์„ ๋Œ€์‹  ์ˆ˜์‹ ํ•˜์—ฌ ์ด๋ฅผ ๋ชฉํ‘œํ•˜๋Š” ์„œ๋ฒ„์—๊ฒŒ ์ „๋‹ฌํ•˜๊ณ , ์—ฌ๊ธฐ์„œ ์˜ค๋Š” ์‘๋‹ต์„ ๋‹ค์‹œ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•ด์ฃผ๋Š” ์—ญํ• ์„ ์ฃผ ๋ชฉ์ ์œผ๋กœ ํ•œ๋‹ค.

(์ถ”ํ›„ nginx๋ฅผ ํ†ตํ•œ ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ์— ๋Œ€ํ•ด์„œ ์ž‘์„ฑํ•  ์˜ˆ์ •์ด๋ผ ์—ฌ๊ธฐ์„œ๋Š” ์ด์ •๋„๋งŒ ์†Œ๊ฐœํ•˜๊ฒ ๋‹ค)

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

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

๋งŒ์•ฝ ๊ธฐ๋ณธ http ๊ธฐ๋ณธ ํฌํŠธ์ธ 80๋ฒˆ์œผ๋กœ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๊ตฌ๋™๋˜๊ณ  ์žˆ์„ ๊ฒฝ์šฐ๋Š” ์ƒ๊ด€์—†์ง€๋งŒ, 1023๋ฒˆ ๋ฏธ๋งŒ์˜ ์˜ˆ์•ฝ ํฌํŠธ์ธ "Well-known-port" ๋“ค์ด ์•„๋‹Œ ๊ทธ ์™ธ์˜ ํฌํŠธ์— ์—ด๋ ค์žˆ๋Š” ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ผ ๊ฒฝ์šฐ, http ์š”์ฒญ์ด ๋“ค์–ด์˜ฌ ๋•Œ ์ด ์š”์ฒญ์„ ํ•ด๋‹น ํฌํŠธ๋กœ ํฌ์›Œ๋”ฉ์„ ํ•ด์ค˜์•ผํ•˜๋Š” ์ƒํ™ฉ์ด ๋ฒŒ์–ด์ง„๋‹ค.

์ด๋Ÿฐ ์—ญํ• ์„ nginx ๋‚ด๋ถ€ ์„ค์ •์—์„œ ํ•  ์ˆ˜ ์žˆ๋“ฏ์ด, load balancer๋„ ๋™์ผํ•œ ์—ญํ• ์„ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๊ทธ ํฌํŠธ ํฌ์›Œ๋”ฉ์— ๋Œ€ํ•œ ์ •์˜๋“ค์ด ๋ฐ”๋กœ Target group(๋Œ€์ƒ ๊ทธ๋ฃน)์ด๋‹ค.

๋Œ€๋žต ์ด์ •๋„์˜ ๊ฐœ๋…์„ ์žก๊ณ  ๋‹ค์‹œ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ์˜ ์„ค์ •์œผ๋กœ ๋Œ์•„๊ฐ€๋ณด๋ฉด,

์ผ๋‹จ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ์ž์ฒด์˜ ์ด๋ฆ„์„ ์ •์˜ํ•˜๊ณ , ์ด ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ๊ฐ€ ํƒ€๊ฒŸํŒ…ํ•  VPC์™€ ์„œ๋ธŒ๋„ท์„ ๋งคํ•‘ํ•ด์ค€๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๋ฐฉํ™”๋ฒฝ ์—ญํ• ์„ ํ•ด์ค„ ๋ณด์•ˆ๊ทธ๋ฃน์„ ์„ค์ •ํ•ด์ค€๋‹ค. EC2๋ฅผ ์“ฐ๋‹ค๋ณด๋ฉด ์ž์ฃผ ๋ณด๊ฒŒ๋˜๋Š”, ์ธ๋ฐ”์šด๋“œ์™€ ์•„์›ƒ๋ฐ”์šด๋“œ์— ๋Œ€ํ•œ ์ •์˜๋“ค์ด ๋˜์–ด์žˆ๋Š” ๊ฐ์ฒด์ด๋‹ค. (์ฆ‰, ์–ด๋Š ํฌํŠธ๋กœ ๋“ค์–ด์˜ค๋Š” ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ด์ค„๊ฑฐ๊ณ , ์–ด๋Š ํฌํŠธ๋กœ ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค„๊ฒƒ์ธ์ง€์— ๋Œ€ํ•œ ์ •์˜ ๋ชจ์Œ์ง‘ )

๊ทธ ๋‹ค์Œ์—๋Š” ๋ฆฌ์Šค๋„ˆ์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ํ•ด์ค˜์•ผํ•œ๋‹ค.
์•„๊นŒ ์œ„์—์„œ ๋ณธ ์ด๋ฏธ์ง€๋Œ€๋กœ, ๋ฐฉํ™”๋ฒฝ์„ ํ†ต๊ณผํ•œ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ์ด์ œ ์ง์ ‘์ ์œผ๋กœ ๊ฐ๊ฐ์˜ ํฌํŠธ์— ๋”ฐ๋ฅธ ํฌ์›Œ๋”ฉ์— ๋Œ€ํ•œ ์ •์˜๋ฅผ ํ•ด์ค„ ์ฐจ๋ก€์ด๋‹ค(๋Œ€์ƒ๊ทธ๋ฃน). ๋Œ€์ƒ๊ทธ๋ฃน ์ƒ์„ฑ์„ ๋ˆŒ๋Ÿฌ์„œ ๋“ค์–ด๊ฐ„๋‹ค.

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

๋”ฐ๋ผ์„œ ECS๊ฐ€ ์•Œ์•„์„œ ๋ฐฐ์ •ํ•ด ์ค„ ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์—์ฒ˜๋Ÿผ ๊ธฐ๋ณธ ์„ค์ •๋œ Ipv4๋ถ€๋ถ„์€ ์ œ๊ฑฐํ•˜๊ณ  ๋งŒ๋“ค์–ด์ฃผ๊ธฐ๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

๋‹ค ๋˜์—ˆ์œผ๋ฉด ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋กœ ๋‹ค์‹œ ๋Œ์•„์™€์„œ ๋ฆฌ์Šคํ„ฐ ๋ถ€๋ถ„์— ๋Œ€์ƒ๊ทธ๋ฃน์— ์ƒˆ๋กœ๊ณ ์นจ์„ ๋ˆ„๋ฅธ ํ›„, ์•„๊นŒ ๋งŒ๋“ค์–ด๋‘์—ˆ๋˜ ๋Œ€์ƒ๊ทธ๋ฃน๊ณผ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์—ฐ๊ฒฐ์‹œ์ผœ์ฃผ๋ฉด ๋œ๋‹ค.

์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ECS๋กœ ๋„˜์–ด๊ฐ€๊ฒŒ ๋œ๋‹ค.

๋จผ์ € ECS ๋‚ด์—์„œ ์‚ฌ์šฉ๋  ์ž‘์—… ์ •์˜(task-definition)์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค

์ž‘์—… ์ •์˜๋ž€, ECS๊ฐ€ ํŠน์ • ECR์— ์˜ฌ๋ผ๊ฐ€์žˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ, ์–ผ๋งˆ๋งŒํผ์˜ ์ž์›์„ ๋ถ„๋ฐฐํ• ๊ฒƒ์ด๊ณ  ์–ด๋–ค OS๋ฅผ ์“ฐ๊ณ , ์ปจํ…Œ์ด๋„ˆ ์ƒ์„ฑํ•˜๋ฉด ์ปจํ…Œ์ด๋„ˆ ํฌํŠธ๋Š” ๋ช‡์ด๊ณ  ... ๋“ฑ๋“ฑ์˜ ์ŠคํŽ™ ์ •์˜์„œ์™€ ๊ฐ™์€ ๊ฒƒ์„ JSON ํ˜•ํƒœ๋กœ ์ƒ์„ฑํ•˜๋Š” ๊ฒƒ์„ ๋œปํ•œ๋‹ค.

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

๊ฐ ์š”์†Œ์— ๋Œ€ํ•ด์„œ ์ƒ์„ธํ•œ ์„ค๋ช…์€ AWS ๊ณต์‹ ๋ฌธ์„œ ๋ฅผ ์ฐธ์กฐํ•˜๋„๋ก ํ•˜๊ณ , ์—ฌ๊ธฐ์„œ๋Š” ์ˆœ์ˆ˜ํ•˜๊ฒŒ ์‚ฌ์šฉ์„ ์œ„ํ•œ ๋ถ€๋ถ„๋งŒ ์งš๊ณ  ๋„˜์–ด๊ฐ€๋ ค๊ณ  ํ•œ๋‹ค.

ECS๋ฅผ ๊ฒ€์ƒ‰ํ•ด์„œ ์ƒˆ ํ…Œ์Šคํฌ ์ •์˜ ์ƒ์„ฑ์„ ๋ˆ„๋ฅธ๋‹ค.


๋งจ ์ฒ˜์Œ์— ๋งŒ๋‚˜๊ฒŒ ๋˜๋Š” ๊ฒƒ์€ ํƒœ์Šคํฌ ์ •์˜ ํŒจ๋ฐ€๋ฆฌ ์ด๋ฆ„์ด๋‹ค.
ํƒœ์Šคํฌ ์ •์˜๋Š” ํ•˜๋‚˜์˜ ํŒจ๋ฐ€๋ฆฌ ์ •์˜ ์ด๋ฆ„์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ณ„์†ํ•ด์„œ ์ƒˆ๋กœ์šด ๋ฒ„์ „์˜ ํƒœ์Šคํฌ๋“ค์ด ์Œ“์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ ‡๊ฒŒ ํŒจ๋ฐ€๋ฆฌ ์ด๋ฆ„์œผ๋กœ ๊ฐ์‹ธ์ฃผ๋Š” ๊ฒƒ์ด๋ผ ์ดํ•ดํ•˜์˜€๋‹ค.

๋‹ค๋ฅธ ๋‚ด์šฉ๋“ค๋„ ์ค‘์š”ํ•˜๊ธด ํ•œ๋ฐ, ๊ทธ๊ฒƒ๋“ค์€ ๊ทธ๋ƒฅ ๊ธฐ๋ณธ์œผ๋กœ ๋‘๋”๋ผ๋„ ์ œ์ผ ์ค‘์š”ํ•œ๊ฑด ์šฐ๋ฆฌ์˜ docker image๊ฐ€ ์ปจํ…Œ์ด๋„ˆํ™”ํ•  ๋•Œ ํ•„์š”ํ•œ ์ •๋ณด๋“ค์„ ์ž‘์„ฑํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.
์•„๋ž˜์˜ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋ถ€๋ถ„์€ ์ง์ ‘ ์ €๋ ‡๊ฒŒ ์ž…๋ ฅํ•ด๋„ ๋˜๊ณ , S3์— ํŒŒ์ผํ˜•ํƒœ๋กœ ์ €์žฅํ–ˆ๋‹ค๊ฐ€ ์ถ”๊ฐ€ํ•˜์—ฌ๋„ ๋œ๋‹ค.

์ด ์ž‘์ ‘ ์ •์˜์„œ์— ๋”ฐ๋ผ์„œ ECS๊ฐ€ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒ์„ฑํ•ด์ค„๊ฒƒ์ด๋‹ค.

๋กœ์ปฌ์—์„œ ์ง์ ‘ docker์„ ์ด์šฉํ•ด์„œ ์ปจํ…Œ์ด๋„ˆ ๋„์šธ ๋•Œ๋ฅผ ์ƒ๊ฐํ•ด๋ณด๋ฉด ์ดํ•ด์— ๋„์›€์ด ๋  ๊ฒƒ์ด๋‹ค.

docker run -it -d -p 20160:20160 -e PORT=20160 testimage

์—ฌํŠผ ๊ทธ๋ ‡๊ฒŒ ํƒœ์Šคํฌ ์ •์˜๋ฅผ ์ƒ์„ฑํ•˜๊ฒŒ ๋˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ผ ๊ฒƒ์ธ๋ฐ

์œ„์— ๋ณด์ด๋Š” ํƒœ์Šคํฌ ์ •์˜ ์ด๋ฆ„์ด git action secret์˜ ECS_TASK_DEFINITION ๋ถ€๋ถ„์— ๋“ค์–ด๊ฐˆ ๊ฐ’์ด ๋œ๋‹ค.

      - name: Generate task-definition.json from latest active ECS task definition
        run: |
          aws ecs describe-task-definition \
            --task-definition ${{ secrets.ECS_TASK_DEFINITION }} \ <-- ์—ฌ๊ธฐ
            --query taskDefinition \
            > task-definition.json

Run ํŒŒํŠธ๋Š” ๊ฐ„๋‹จํžˆ ์„ค๋ช…ํ•˜๋ฉด aws cli๋ฅผ ์ด์šฉํ•˜์—ฌ task ์ •์˜์— ๋Œ€ํ•œ json์„ ์ถ”์ถœํ•˜๋Š” ๋ฌธ๋ฒ•์ด๋‹ค. (์ƒ์„ฑ ํ›„ task-definition.json์ด๋ผ๋Š” ์ด๋ฆ„์˜ ํŒŒ์ผ์— ์ €์žฅ์‹œํ‚ค๊ฒŒ ํ•˜์˜€๋‹ค. ์ด ํŒŒ์ผ์€ ์ž๋™์œผ๋กœ ๋‹ค์Œ ์Šคํƒญ์—์„œ ๋™์ผ ์ด๋ฆ„์œผ๋กœ ์ฐธ์กฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค )

์ž์„ธํ•œ ์˜ต์…˜ ์„ค๋ช…์€ task-definition cli ๊ณต์‹๋ฌธ์„œ์„ ์ฐธ์กฐํ•˜๋„๋ก ํ•œ๋‹ค.

๊ทธ๋Ÿฌ๋ฉด ์ด ๋‹ค์Œ ์Šคํƒญ์œผ๋กœ ๋„˜์–ด๊ฐ€๋ณด๋„๋ก ํ•˜์ž.

      - name: Render Amazon ECS task definition
        id: render-task-definition
        uses: aws-actions/amazon-ecs-render-task-definition@v1
        with:
          # this step exports the task-definition as an output automatically (used for next step)
          task-definition: task-definition.json
          container-name: ${{ secrets.ECS_TASK_CONTAINER_NAME }}
          image: ${{ steps.build-image.outputs.image }}

ํ•ด๋‹น ์Šคํƒญ์€ ๋ฐ›์•„์˜จ task-definition json์„ ์‹ค์ œ ECS์— ๋Œ์•„๊ฐ€๊ธฐ ์œ„ํ•œ definition์œผ๋กœ ๋žœ๋”๋งํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. (์ž์„ธํ•œ ๋‚ด๋ถ€ ๊ตฌ์กฐ๋Š” ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค)

aws-actions์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” aws-actions/amazon-ecs-render-task-definition@v1 ์„ ํ™œ์šฉํ•˜๋ฉด ๋˜๋ฉฐ, ์—ฌ๊ธฐ์„œ ์šฐ๋ฆฌ๊ฐ€ git action secret์œผ๋กœ ์ •์˜ํ•ด์ค˜์•ผ ํ•˜๋Š” ๋ถ€๋ถ„์€ ์•„๊นŒ task-definition์„ ์ƒ์„ฑํ•  ๋•Œ ์ปจํ…Œ์ด๋„ˆ ์ด๋ฆ„์œผ๋กœ ์ •ํ•ด๋†“์•˜๋˜ ๊ฒƒ์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค.

๊ทธ๋Ÿผ ์ด์ œ ํ…Œ์ŠคํŠธ ์ •์˜๋Š” ๋‹ค ํ•˜์˜€์œผ๋‹ˆ, ์ด ํƒœ์Šคํฌ๋ฅผ ๊ธฐ๋ฐ˜ํ•˜์—ฌ ์‹ค์ œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ๋„์›Œ์ค„ ํ™˜๊ฒฝ์ธ ECS ํด๋Ÿฌ์Šคํ„ฐ ์ •์˜๋ฅผ ํ•˜๋Ÿฌ ๊ฐ€์•ผํ•œ๋‹ค. (EC2๋กœ ๋Œ€์ฒดํ•ด์„œ ์ƒ๊ฐํ•˜๋ฉด ์ดํ•ดํ•˜๊ธฐ ํŽธํ•˜๋‹ค.)

ํด๋Ÿฌ์Šคํ„ฐ ๊ทธ ์ž์ฒด๋Š” ์„œ๋น„์Šค๋“ค์„ ๋ฌถ์–ด์ฃผ๋Š” ์ง‘ํ•ฉ์˜ ์ด๋ฆ„๋งŒ ํ•ด๋‹นํ•˜๋Š” ๋Š๋‚Œ์ด๋ผ ์‚ฌ์‹ค ์ด๋ฆ„ ์ •์˜๋งŒ ํ•˜๋ฉด ๋œ๋‹ค.

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

์ค‘๊ฐ„์— ๋ณด์ด๋Š” ํŒจ๋ฐ€๋ฆฌ๊ฐ€ ์•„๊นŒ ์šฐ๋ฆฌ๊ฐ€ ์ •์˜ํ–ˆ๋˜ ํƒœ์Šคํฌ ์ •์˜์˜ ํŒจ๋ฐ€๋ฆฌ ์ด๋ฆ„์ด๋‹ค.
ํ˜„์žฌ ๋ฒ„์ „์€ 14๋กœ ๋˜์–ด์žˆ๋Š”๋ฐ, ์ € ๋ฒ„์ „์€ ๊ณ„์† ๋ฐ”๋€”๊ฒƒ์ด๋‹ค.(๋ฐฐํฌ๋ฅผ ํ•  ๋•Œ๋งˆ๋‹ค)

์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ด๋ฆ„์„ ์ •์˜ํ•ด์ฃผ๊ณ , ๋ฐฐํฌ ์˜ต์…˜์„ ๊ฐ€์•ผํ•˜๋Š”๋ฐ,

์‚ฌ์‹ค ๋ธ”๋ฃจ/๊ทธ๋ฆฐ ๋ฐฐํฌ์ž”๋žต์„ ์„ ํƒํ•˜๋ ค๋ฉด AWS code deploy๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•ด์•ผํ•œ๋‹ค.
๊ทธ ๋ถ€๋ถ„๊นŒ์ง€ ๋„ฃ๊ธฐ๋Š” ๋„ˆ๋ฌด ์‹œ๊ฐ„์ด ๊ฑธ๋ ค์„œ ์ผ๋‹จ ๋กค๋ง์—…๋ฐ์ดํŠธ๋กœ ์ง„ํ–‰ํ•˜๋ ค๊ณ  ํ•œ๋‹ค.

์ฐธ๊ณ ๋กœ, ๋กค๋ง ์—…๋ฐ์ดํŠธ์™€ ๋ธ”๋ฃจ/๊ทธ๋ฆฐ ์—…๋ฐ์ดํŠธ๋Š” ๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๊ธฐ๋ฒ•๋“ค์ด๋ฉฐ, ์ฐจ์ด์— ๋Œ€ํ•ด์„œ๋Š” ๊ฐ„๋‹จํžˆ ์„ค๋ช…ํ•˜์ž๋ฉด

  1. ๋กค๋ง ์—…๋ฐ์ดํŠธ : ํ˜„์žฌ ๋„์›Œ์ ธ ์žˆ๋Š” ์„œ๋น„์Šค๋ฅผ ์œ ์ง€ํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ์—์„œ, ์ ์ง„์ ์œผ๋กœ ์„œ๋น„์Šค๋“ค์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์—…๋ฐ์ดํŠธํ•ด๋‚˜๊ฐ€๋ฉด์„œ ๊ต์ฒดํ•˜๋Š” ๋ฐฉ์‹. ํ•„์—ฐ์ ์œผ๋กœ ๋‘๊ฐ€์ง€ ๋ฒ„์ „์ด ๋™์‹œ์— ํ˜ธ์ŠคํŒ…๋˜๋Š” ์ˆœ๊ฐ„์ด ์กด์žฌํ•จ.

  2. ๋ธ”๋ฃจ/๊ทธ๋ฆฐ ์—…๋ฐ์ดํŠธ : ํ˜„์žฌ ์„œ๋น„์Šค๋ฅผ ์œ ์ง€ํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ์—์„œ, ๋‹ค๋ฅธ ๋ฒ„์ „์˜ ์„œ๋น„์Šค๋“ค์„ ํ†ต์งธ๋กœ ์ƒ์„ฑํ•œ ํ›„, ๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ์„ ์ƒˆ๋กœ์šด ๋ฒ„์ „์œผ๋กœ ์น˜ํ™˜ํ•œ ๋’ค ๊ธฐ์กด ์„œ๋น„์Šค๋ฅผ ์ฃฝ์ด๋Š” ๋ฐฉ๋ฒ•. ๋ฐฐํฌํ•  ๋•Œ ๋‘ ์„œ๋น„์Šค๋ฅผ ๋‹ค ๋„์šธ ์ž์›์ด ํ•„์š”ํ•จ(์ฆ‰ ๋‘๋ฐฐ)

์—ฌํŠผ, ์ดํ›„ ์•„๊นŒ ๋งŒ๋“ค์–ด๋‘์—ˆ๋˜ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ์„ค์ •๋„ ๋ถˆ๋Ÿฌ์˜จ ํ›„, ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑ ์™„๋ฃŒํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

์ดํ›„, ๋‹ค์Œ git action step์˜ secret์— ํ•ด๋‹นํ•˜๋Š” ๊ฐ’์„ ๋“ฑ๋กํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

      - name: Deploy Amazon ECS task definition
        uses: aws-actions/amazon-ecs-deploy-task-definition@v1
        with:
          task-definition: ${{ steps.render-task-definition.outputs.task-definition }}
          service: ${{ secrets.ECS_SERVICE }} <--- ์ด๊ฑฐ
          cluster: ${{ secrets.ECS_CLUSTER }} <--- ์ด๊ฑฐ
          wait-for-service-stability: true

์ด๋ ‡๊ฒŒ ํ•ด๋‘๋ฉด, ์ด์ œ ๋‹ค ์™„๋ฃŒ๋˜์—ˆ๋‹ค.

์ด์ œ git action์€ ์กฐ๊ฑด์— ๋งž์ถฐ์„œ ์‹คํ–‰๋ ๊ฒƒ์ด๋‹ค. ๋‚˜๋Š” develop์˜ pull request๊ฐ€ close๋˜๋Š” ์ˆœ๊ฐ„์— ์‹คํ–‰๋˜๊ฒŒ ํ•ด๋†“์•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„๋ž˜์ฒ˜๋Ÿผ CD action์ด ์ง„ํ–‰๋˜๋ฉฐ

on:
  pull_request:
    branches:
      - develop
    types: [closed]

task defininition์—๋„ ์ œ๋Œ€๋กœ ์ƒˆ๋กœ์šด ๋ฒ„์ „์ด ์˜ฌ๋ผ๊ฐ€๊ฒŒ ๋˜๋ฉด์„œ CD ๊ณผ์ •์œผ๋กœ ์ƒ์„ฑ๋œ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๊ฐ€ ๋“ฑ๋ก๋˜๊ฒŒ ๋˜๊ณ ,

ECS ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์˜ ์„œ๋น„์Šค์—๋Š” ํ•ด๋‹น ์ตœ์‹ ์˜ ์ด๋ฏธ์ง€๊ฐ€ ๊ตฌ๋™๋˜๊ฒŒ ๋œ๋‹ค.

ํ•ด๋‹น ๊ตฌ๋™๋œ ์ปจํ…Œ์ด๋„ˆ์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋ฅผ ํ†ตํ•ด ๋“ค์–ด๊ฐ€์•ผ ํ•œ๋‹ค.
์šฐ๋ฆฌ์˜ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ๋Š” ํด๋Ÿฌ์Šคํ„ฐ ์„œ๋น„์Šค์— ๋“ค์–ด๊ฐ€์„œ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ๋ถ€๋ถ„์„ ๋ˆ„๋ฅธ ํ›„, DNS ์ฃผ์†Œ๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.



๐Ÿš ๋งบ์Œ๊ธ€

๊ธด ์—ฌ์ •์ด์—ˆ๋‹ค... ์‚ฌ์‹ค ์ด ๊ณผ์ • ํ•˜๋‚˜ํ•˜๋‚˜๊ฐ€ ์ˆœํƒ„ํ•œ ๊ณผ์ •์ด ์•„๋‹ˆ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— ํ•ด์•ผํ•  ๊ฒƒ์ด ์ •๋ง ๋งŽ์•˜๋Š”๋ฐ,
๊ทธ๋ž˜๋„ ๊ทธ ๊ณผ์ •์„ ๊ฒช์œผ๋ฉด์„œ ๋ฐฐ์›Œ๊ฐ„ ๊ฒƒ์ด ์ •๋ง ๋งŽ์•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ธฐ๋ก์œผ๋กœ ๋‚จ๊ธฐ๋ฉด์„œ๋„ ์•„์ง๋„ ๋งŽ์ด ์ •์ง„ํ•ด์•ผ ํ•จ์„ ๋Š๋‚€๋‹ค.

์ด๋ ‡๊ฒŒ ์ •๋ฆฌํ•ด๋’€์œผ๋‹ˆ ๋‚˜์ค‘์— (๋‚ด๊ฐ€) ๋‹ค์‹œ ๊ตฌํ˜„ํ•˜๋ผ๊ณ  ํ•  ๋•Œ ๋„์›€์ด ๋งŽ์ด ๋˜๊ฒ ์ง€ ํžˆํžˆ.

profile
์ž๋ผ๋‚˜๋ผ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ƒˆ์‹น!

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