CICD 환경을 구축하는 방법은 정말 다양하다.
그래서 처음 시도해볼때, 더 어려웠다. 눈물같던 80커밋 절대 잊지 못해
내가 본 방법은 크게 3가지였다.
1) Workflow
2) Event
3) Job
4) Step
5) Action
6) Runner
name: CI
on: // 어떤 조건에 Workflow를 Trigger 시킬지 작성
push:
branches: [ master ] // 단일 Event를 사용할 수도 있고, array로 작성가능
pull_request:
branches: [ master ]
jobs: // 여러 Job이 있을 경우, Default로 병렬 실행
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run a one-line script
run: echo Hello, world!
- name: Run a multi-line script
run: |
echo Add other actions to build,
echo test, and deploy your project.
name: CI
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Install packages
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm run test
on:
push:
branches:
- main
name: Deploy to Amazon ECS
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: <ecr-repository>
IMAGE_TAG: latest
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition taskdef --query taskDefinition > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: <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.task-def.outputs.task-definition }}
service: <service-name>
cluster: <cluster-name>
wait-for-service-stability: true
이번 프로젝트에서 위 방식으로 CICD를 붙일 예정이기 때문에, 캡처에서 올려야지.
🌷컨테이너 관리에 대해 공부해야겠다. 궁금해져버렸어.🌷