Status | Authors | Coach | DRIs | Owning Stage | Created |
---|---|---|---|---|---|
proposed | devops verify | - |
GitLab Steps의 .gitlab-ci.yml
사용
이 문서는 GitLab Steps가 .gitlab-ci.yml
에 통합되는 방법에 대해 설명합니다.
GitLab Steps는 세 단계의 실행 주기를 사용하여 통합되며 before_script:
, script:
, after_script:
를 대체할 것입니다.
-
setup:
: 환경을 프로비저닝하는 실행 단계로, 리포지터리 복제, 아티팩트 복원 또는 모든 의존성 설치를 포함합니다. 이 단계는 암시적으로 클론, 아티팩트 복원 및 캐시 다운로드를 대체할 것입니다. -
run:
: 테스트, 빌드 또는 해당 작업에 필요한 기본 명령을 실행하는 실행 단계입니다. -
teardown:
: 환경을 정리하거나 아티팩트를 업로드하거나 캐시를 저장하는 실행 단계로, 이 단계는 암시적으로 아티팩트 및 캐시 업로드를 대체할 것입니다.
세 단계의 실행을 달성하려면 사전 GitLab 통합이 필요하지 않은 최소한의 초기 지원을 제공하게됩니다.
Phase 1: 초기 지원
최초로 Step Runner는 GitLab에 대한 사전 의존성이 필요하지 않고 외부적으로 사용될 것입니다:
-
step-runner
는 컨테이너 이미지의 일부로 제공될 것입니다. -
step-runner
는 명시적으로script:
섹션에서 실행될 것입니다. -
$STEPS
환경 변수는type: steps
로 실행될 것입니다.
hello-world:
image: registry.gitlab.com/gitlab-org/step-runner
variables:
STEPS: |
- step: gitlab.com/josephburnett/component-hello-steppy@master
inputs:
greeting: "hello world"
script:
- /step-runner ci
Phase 2: .gitlab-ci.yml
에 run:
추가
Phase 2에서는 run:
을 GitLab Steps를 사용하는 첫 번째 방식으로 추가할 것입니다:
-
run:
은type: steps
구문을 사용할 것입니다. -
run:
은before_script
,script
및after_script
의 사용을 대체할 것입니다. - Git 클론, 아티팩트 및 캐시 지원을 계속 지원하기 위한 기존 기능이 모두 유지될 것입니다.
- 작업이 취소되거나 작업이 취소된 경우에만 무조건 실행되는
after_script
를 어떻게 지원할지는 아직 정의되지 않았습니다. -
run:
은before_script:
,script:
,after_script:
과 함께 사용할 수 없습니다. - GitLab Rails는
run:
을 구문 검증과 함께 정적으로 검증하고 Step Runner가 제공하는 JSON 스키마로만 파싱할 것입니다.
hello-world:
image: registry.gitlab.com/gitlab-org/step-runner
run:
- step: gitlab.com/josephburnett/component-hello-steppy@master
inputs:
greeting: "hello world"
다음의 예제는 구문 검증에 실패합니다:
hello-world:
image: registry.gitlab.com/gitlab-org/step-runner
run:
- step: gitlab.com/josephburnett/component-hello-steppy@master
inputs:
greeting: "hello world"
script: echo "모호하고 유효하지 않은 예제입니다"
before_script:
, script:
, after_script:
에서의 전환
GitLab Rails는 *script:
구문을 자동으로 관련 run:
사양으로 변환할 것입니다:
- 오늘날
before_script:
및script:
은 실행을 위해 하나의 스크립트로 합쳐집니다. -
after_script:
섹션은 항상 별도의 컨텍스트에서 실행되며 실행해야 할 별도의 단계를 나타냅니다. - 상태 또는 타임아웃에 관계없이 항상 실행되고 별도의 타임아웃을 사용하는
after_script
의 기존 동작 방식을 유지하는 방법은 아직 정의되지 않았습니다. -
script:
을 단계 기반 실행으로 변환할 때 모든 환경 변수를 정의하는 암시적인 동작을 유지할 것입니다.
예를 들어, 이 CI/CD 구성:
hello-world:
before_script:
- echo "Run before_script"
script:
- echo "Run script"
after_script:
- echo "Run after_script"
다음과 같이 동등한 사양으로 변환될 수 있습니다:
hello-world:
run:
- step: gitlab.com/gitlab-org/components/steps/legacy/script@v1.0
inputs:
script:
- echo "Run before_script"
- echo "Run script"
- step: gitlab.com/gitlab-org/components/steps/legacy/script@v1.0
inputs:
script:
- echo "Run after_script"
when: always
Phase 3: .gitlab-ci.yml
에 setup:
및 teardown:
추가
setup:
및 teardown:
의 추가는 GitLab Runner가 암시적으로 제공하는 기능을 대체할 것입니다: Git 클론, 아티팩트 및 캐시 처리.
-
setup:
의 사용은 GitLab Runner가 리포지터리를 암시적으로 복제하는 것을 중단시킬 것입니다. - 지정된 경우
artifacts:
및cache:
는 이전 구문과의 하위 호환성을 제공하기 위해setup:
및teardown:
에 변환 및 추가될 것입니다. - 지정된 경우
release:
는 하위 호환성을 제공하기 위해teardown:
에 변환 및 추가될 것입니다. -
setup:
및teardown:
는default:
에서 사용될 수 있어 클론하는 경우와 아티팩트를 처리하는 등 일반적인 워크플로우를 지원하게 간단해질 것입니다. -
extends:
와 함께 단계의 조합성을 추가로 향상시킵니다. -
hooks:pre_get_sources_script
은script:
와 유사하게 구현되며setup:
앞에 추가될 것입니다.
예를 들어, 이 CI/CD 구성:
rspec:
script:
- echo "This job uses a cache."
artifacts:
paths: [binaries/, .config]
cache:
key: binaries-cache
paths: [binaries/*.apk, .config]
다음과 같이 Step Runner에서 실행되는 동등한 사양으로 변환될 수 있습니다:
rspec:
setup:
- step: gitlab.com/gitlab-org/components/git/clone@v1.0
- step: gitlab.com/gitlab-org/components/artifacts/download@v1.0
- step: gitlab.com/gitlab-org/components/cache/restore@v1.0
inputs:
key: binaries-cache
run:
- step: gitlab.com/gitlab-org/components/steps/legacy/script@v1.0
inputs:
script:
- echo "This job uses a cache."
teardown:
- step: gitlab.com/gitlab-org/components/artifacts/upload@v1.0
inputs:
paths: [binaries/, .config]
- step: gitlab.com/gitlab-org/components/cache/restore@v1.0
inputs:
key: binaries-cache
paths: [binaries/*.apk, .config]
default:
을 사용하여 공통 작업 상속
setup:
및 teardown:
은 시간이 지남에 따라 매우 상세해질 수 있습니다. 이를 간소화하는 한 가지 방법은 default:
를 사용하여 공통 setup:
및 teardown:
작업을 상속하는 것입니다.
이전 예제는 다음과 같이 간소화될 수 있습니다:
default:
setup:
- step: gitlab.com/gitlab-org/components/git/clone@v1.0
- step: gitlab.com/gitlab-org/components/artifacts/download@v1.0
- step: gitlab.com/gitlab-org/components/cache/restore@v1.0
inputs:
key: binaries-cache
teardown:
- step: gitlab.com/gitlab-org/components/artifacts/upload@v1.0
inputs:
paths: [binaries/, .config]
- step: gitlab.com/gitlab-org/components/cache/restore@v1.0
inputs:
key: binaries-cache
paths: [binaries/*.apk, .config]
rspec:
run:
- step: gitlab.com/gitlab-org/components/steps/legacy/script@v1.0
inputs:
script:
- echo "실행 중입니다."
linter:
run:
- step: gitlab.com/gitlab-org/components/steps/legacy/script@v1.0
inputs:
script:
- echo "린팅 실행 중입니다."
병렬 작업 및 setup:
앞으로 setup:
이 소개되면 작업을 병렬로 실행하는 효율적인 방법이 도입될 것입니다:
-
setup:
은 환경을 프로비저닝하는 데 필요한 모든 단계를 정의할 것입니다. -
parallel: N
을 사용하면setup:
의 결과는 스냅샷으로 정의되고 해당 스냅샷이 모든 병렬 작업의 기본으로 분산될 것입니다. -
run:
및teardown:
은 복제된 작업과 해당 서비스 위에서 실행될 것입니다. - Runner는 모든 병렬 작업을 제어하고 지능적으로 분배하여 작업의 고정된 부분(깃 클론, 아티팩트, 의존성 설치)의 리소스 요구 사항을 크게 줄일 것입니다.
rspec-parallel:
image: ruby:3.2
services: [postgres, redis]
parallel: 10
setup:
- step: gitlab.com/gitlab-org/components/git/clone@v1.0
- step: gitlab.com/gitlab-org/components/artifacts/download@v1.0
inputs:
jobs: [setup-all]
- script: bundle install --without production
run:
- script: bundle exec knapsack
잠재적인 GitLab Runner 플로우:
- Runner는
setup:
및parallel:
이 구성된rspec-parallel
작업을 수신합니다. - Runner는
setup
까지의 블록 볼륨을 사용하여 Kubernetes 클러스터 상에서 작업을 실행합니다. - 그런 다음 Runner는 Kubernetes에서 10개의 병렬 작업을 실행하고, 2번에서의 블록 볼륨을 겹쳐
run:
및teardown:
을 계속 실행합니다.