GitLab CI CD
#
Find similar titles
-
최초 작성자
hjcho@insilicogen.com
- 최근 업데이트
Table of Contents
GitLab CI/CD #
GitLab CI/CD는 연속 통합, 연속 배포를 위한 개발 도구이다. 애플리케이션 개발 단계부터 배포 때까지의 모든 단계를 자동화를 통해서 좀 더 효율적이고 빠르게 사용자에게 빈번히 배포할 수 있는 것을 말한다.
CI (Continuous Integration) "지속적인 통합"이라는 의미이다. 애플리케이션의 버그 수정이나 새로운 코드 변경이 주기적으로 빌드 및 테스트 되면서 공유되는 저장소에 통합(merge)되는 것을 의미한다.
CD (Continuous Delivery/Deployment) "지속적인 제공", "지속적인 배포"라는 의미이다. CI에서 Build 되고 Test 된 후에, 배포 단계에서 relrase 할 준비 단계를 거치고 문제가 없는지 수정할만한 것들이 없는지 검증한 후에, 사용자들에게 서비스를 제공해도 되겠다고 정해져서 배포를 수동적으로 진행하는 것이 "Continuous Delivery, 지속적인 제공"이고, 위와 같이 배포할 준비가 되자마자 자동화를 통하여 배포를 진행하는 것이 "Continuous Deployment, 지속적인 배포"이다.
Pipeline #
파이프라인은 GitLab에서 CI/CD의 기본 구성 요소이다. 파이프라인을 구성하는 세 가지 주요 방법이 있는데, 사용자의 프로젝트에 적합한 방법을 선택해서 사용하면 된다.
- Basic: 모든 구성이 한 곳에서 쉽게 찾을 수 있는 간단한 프로젝트에 적합하다.
- Directed Acyclic Graph: 효율적인 실행이 필요하고 크고 복잡한 프로젝트에 적합하다.
- Child/Parent Pipelines: 독립적으로 정의된 구성 요소가 많은 프로젝트에 적합하다.
Basic Pipeline #
GitLab에서 가장 간단한 파이프라인이다. 빌드 단계에서 모든 작업을 동시에 실행하고, 모든 작업이 완료되면 테스트 단계에서 모든 작업을 같은 방식으로 실행한다.
예시, Basic Pipeline 구성 /.gitlab-ci.yml
stages:
- build
- test
- deploy
image: alpine
build_a:
stage: build
script:
- echo "This job builds something."
build_b:
stage: build
script:
- echo "This job builds something else."
test_a:
stage: test
script:
- echo "This job tests something. It will only run when all jobs in the"
- echo "build stage are complete."
test_b:
stage: test
script:
- echo "This job tests something else. It will only run when all jobs in the"
- echo "build stage are complete too. It will start at about the same time as test_a."
deploy_a:
stage: deploy
script:
- echo "This job deploys something. It will only run when all jobs in the"
- echo "test stage complete."
deploy_b:
stage: deploy
script:
- echo "This job deploys something else. It will only run when all jobs in the"
- echo "test stage complete. It will start at about the same time as deploy_a."
Directed Acyclic Graph Pipelines #
효율성이 중요하며 모든 작업을 최대한 빨리 실행하려면 DAG(Directed Asyclic Graph)를 사용할 수 있다.
needs
키워드를 사용하여 작업 간의 종속 관계를 정의한다.
작업 간의 관계를 알면 모든 작업을 가능한 한 빨리 실행할 수 있으며, 가능한 경우 후속 단계로 건너뛸 수도 있다.
아래 예제에서 build_a와 test_a가 build_b와 test_b보다 훨씬 빠르면 build_b가 아직 실행 중이더라도 GitLab은 deploy_a를 시작한다.
예시, DAG Pipeline 구성 /.gitlab-ci.yml
stages:
- build
- test
- deploy
image: alpine
build_a:
stage: build
script:
- echo "This job builds something quickly."
build_b:
stage: build
script:
- echo "This job builds something else slowly."
test_a:
stage: test
needs: [build_a]
script:
- echo "This test job will start as soon as build_a finishes."
- echo "It will not wait for build_b, or other jobs in the build stage, to finish."
test_b:
stage: test
needs: [build_b]
script:
- echo "This test job will start as soon as build_b finishes."
- echo "It will not wait for other jobs in the build stage to finish."
deploy_a:
stage: deploy
needs: [test_a]
script:
- echo "Since build_a and test_a run quickly, this deploy job can run much earlier."
- echo "It does not need to wait for build_b or test_b."
deploy_b:
stage: deploy
needs: [test_b]
script:
- echo "Since build_b and test_b run slowly, this deploy job will run much later."
```
Child / Parent Pipelines #
위의 두 가지의 독립적인 구성 방법과 trigger
키워드와 함께 사용하여 Child/Parent Pipelines 을 이상적으로 구현할 수 있다.
구성을 여러 파일로 분리하여 매우 단순하게 유지할 수 있다.
rules
키워드: 하위 파이프라인이 해당 영역에 변경 사항이 있을 때만 트리거되도록 함.
include
키워드: 외부의 yaml 파일을 포함시킴으로써 CI/CD 구성을 여러 파일로 나누어 긴 구성 파일의 가독성을 높임.
하위 파이프라인 내부의 DAG 파이프라인으로, 두 가지 모두의 이점을 달성한다.
예시, 다이어그램과 일치하는 상위 파이프라인에 대한 구성: /.gitlab-ci.yml
stages:
- triggers
trigger_a:
stage: triggers
trigger:
include: a/.gitlab-ci.yml
rules:
- changes:
- a/*
trigger_b:
stage: triggers
trigger:
include: b/.gitlab-ci.yml
rules:
- changes:
- b/*
예시, child 'a' 파이프라인 구성, DAGneeds
키워드 사용. 구성 위치: /a/.gitlab-ci.
stages:
- build
- test
- deploy
image: alpine
build_a:
stage: build
script:
- echo "This job builds something."
test_a:
stage: test
needs: [build_a]
script:
- echo "This job tests something."
deploy_a:
stage: deploy
needs: [test_a]
script:
- echo "This job deploys something."
예시, child 'b' 파이프라인 구성, DAGneeds
키워드 사용. 구성 위치: /b/.gitlab-ci.
stages:
- build
- test
- deploy
image: alpine
build_b:
stage: build
script:
- echo "This job builds something else."
test_b:
stage: test
needs: [build_b]
script:
- echo "This job tests something else."
deploy_b:
stage: deploy
needs: [test_b]
script:
- echo "This job deploys something else."
공통 설정 단계나 마지막 통합 배포가 있는 경우, 하위 파이프라인을 트리거하기 전이나 후에 작업을 실행하도록 설정할 수도 있다.
참고 - [https://docs.gitlab.com/ee/ci/pipelines/pipeline_architectures.html#basic-pipelines](https://docs.gitlab.com/ee/ci/pipelines/pipeline_architectures.html#basic-pipelines)