.github/workflows
디렉토리에 *.yml
파일을 생성하면 됩니다.*.yml
파일은 여러개를 생성할 수 있고, 각각의 파일은 하나의 workflow를 의미합니다.name: test on push CI
on:
push:
branches:
- main
jobs:
test:
runs-on: ubuntu-22.04 # ubuntu 22.04 버전에서 실행
steps:
- name: Checkout # 레포지토리를 체크아웃
uses: actions/checkout@v4.0.0
- name: Setup node
uses: actions/setup-node@v3.8.1
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
name
: workflow의 이름on
: workflow가 실행되는 조건push
: 푸시가 발생했을 때branches
: 푸시가 발생한 브랜치jobs
: workflow가 실행되는 jobruns-on
: job이 실행되는 환경steps
: job이 실행되는 과정name
: step의 이름uses
: step에서 사용하는 actionwith
: action에 전달하는 인자run
: step에서 실행하는 명령어name: Test and Deploy
on:
pull_request:
branches:
- stage
- main
types:
- closed
permissions:
id-token: write
contents: read
pull-requests: write
env:
...
jobs:
test:
name: test nestjs
runs-on: ubuntu-22.04
steps:
...
build_and_deploy:
if: github.event.pull_request.merged == true # PR이 merge되었을 때만 실행
name: build docker image and ecs deploy
runs-on: ubuntu-22.04
needs: test # test job이 성공적으로 끝나야 실행
steps:
- name: checkout # 레포지토리를 체크아웃
...
- name: configure AWS Credentials # AWS 인증정보 획득
...
- name: Login to Amazon ECR # ECR에 로그인
...
- name: Build and push NestJS
...
- name: Fill in the new image ID in the Amazon ECS task definition # 새로운 이미지 ID를 ECS task definition에 채워넣음
...
- name: Deploy Amazon ECS task definition # ECS task definition을 배포
...
pull_request
: PR이 생성되거나 업데이트 되었을 때branches
: PR이 생성되거나 업데이트 된 브랜치types
: PR이 생성되거나 업데이트 된 타입opened
: PR이 열렸을 때closed
: PR이 닫혔을 때merged
: PR이 merge되었을 때permissions
: workflow에서 사용하는 권한id-token
: 워크플로우가 id-token을 사용할 수 있도록 허용, OIDC를 사용하는 경우에 필요contents
: 워크플로우가 레포지토리의 내용을 읽을 수 있도록 허용pull-requests
: 워크플로우가 PR에 코멘트 등 쓰기 권한을 가질 수 있도록 허용다음 글에서 본격적으로 workflow를 구성해보고, 두 가지 인증수단을 각각 활용해서 배포를 해 보도록 하겠습니다.