[AWS] VPC 구성 및 ECS 배포 해보기(+기본개념) [6. Github action workflow 직접 작성 해 보기]

Heechan Kang·2023년 12월 6일
0

AWS ECS 배포하기

목록 보기
6/7
post-thumbnail

AWS VPC 구성부터 ECS 배포까지

Github action Marketplace에서 직접 workflow를 만들어보기

  • "set up a workflow yourself"
  • Repo에 깃헙액션을 사용해 보신 적이 없다면 위와 같은 방법으로 첫 Workflow를 작성 할 수 있습니다.

  • "New workflow"
  • 기존에 작성한 워크플로우가 있으신 분들은 위 버튼으로 새 워크플로우를 등록하실 수 있습니다.

  • 그러면 위와 같은 에디터에서 직접 yml파일을 수정하실 수 있습니다.
  • vscode가 아닌 위 에디터를 사용하는 이유는, 최신의 actions를 marketplace에서 골라서 바로 사용 할 수 있기 때문입니다.

  • 우측 마켓플레이스에서 위와 같이 최신의 액션에 대한 문서와 사용법을 바로 확인 할 수 있습니다.
  • 이제 마켓플레이스에서 필요한 물건을 하나씩 골라 담아주면 됩니다.

푸시하면 자동으로 코드를 테스트하는 Github Action

  • 필요한 작업 목록

    작업 종류작업명Marketplace
    Repo에서 코드 가져오기code checkoutO
    머신에 nodejs 세팅하기setup nodeO
    반복적인 모듈 인스톨을 위한 캐싱cache node modulesO
    의존성 설치npm installX
    린트npm run lintX
    유닛 테스트npm run testX
    e2e 테스트npm run test:e2eX
    슬랙으로 알림 보내주기(선택)Notify SlackO
  • test_on_push.yml

    name: test_on_push
    
    on:
      push:
        branches:
          - develop
    
    jobs:
      test:
        name: test nestjs
        runs-on: ubuntu-22.04
    
        steps:
          - name: Checkout
            uses: actions/checkout@v4.1.1
    
          - name: Setup node
            uses: actions/setup-node@v4.0.0
            with:
              node-version: '20'
              cache: 'npm'
    
          - name: Cache node modules
            uses: actions/cache@v3.3.2
            with:
              path: ~/.npm
              key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
              restore-keys: |
                ${{ runner.os }}-node-
    
          - name: Install dependencies
            run: npm install
    
          - name: Run lint
            run: npm run lint
    
          - name: Run tests
            run: npm run test
    
          - name: Run e2e tests
            run: npm run test:e2e
    
          - name: Notify Slack on Failure
            if: failure()
            uses: 8398a7/action-slack@v3.15.1
            with:
              status: ${{ job.status }}
              fields: repo,message,commit,author,action,eventName,ref,workflow
              author_name: ${{ github.actor }}
              channel: ${{ vars.SLACK_CHANNEL }}
              username: ${{ vars.SLACK_USERNAME }}
              text: 'Tests failed! :x:'
            env:
              SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_URL }}
    
          - name: Notify Slack on Success
            if: success()
            uses: 8398a7/action-slack@v3.15.1
            with:
              status: ${{ job.status }}
              fields: repo,message,commit,author,action,eventName,ref,workflow
              author_name: ${{ github.actor }}
              channel: ${{ vars.SLACK_CHANNEL }}
              username: ${{ vars.SLACK_USERNAME }}
              text: 'Tests passed! :white_check_mark:'
            env:
              SLACK_WEBHOOK_URL: ${{ vars.SLACK_WEBHOOK_URL }}
  • 크게 신경 쓸 부분은 없고, 슬랙을 사용하시는 경우 몇가지 변수를 Repo에 등록해주셔야 합니다.

    • vscode를 사용하는 경우: github actions 익스텐션에서 직접 등록

    • github에서 직접 등록하는 경우

      • Repository -> Settings -> Security -> Secrets and variables 에서 필요한 변수를 등록 해 줄 수 있습니다.

      ❗참고
      Secrets: 등록 후 변수 확인 불가
      Variables: 등록 후 변수 확인 가능

profile
안녕하세요!

0개의 댓글