외부 배포 도구의 배포 추적

Tier: Free, Premium, Ultimate Offering: GitLab.com, Self-managed, GitLab Dedicated

GitLab은 내장 배포 솔루션을 제공하지만, Heroku 또는 ArgoCD와 같은 외부 배포 도구를 사용하는 것을 선호할 수 있습니다. GitLab은 이러한 외부 도구로부터 배포 이벤트를 수신하고 GitLab 내에서 배포를 추적할 수 있습니다. 예를 들어, 추적 설정을 통해 다음과 같은 기능을 활용할 수 있습니다:

note
일부 기능은 GitLab이 외부 배포를 승인하고 활용할 수 없기 때문에 사용할 수 없습니다. 이에는 보호된 환경, 배포 승인, 배포 안전성환경 롤백이 포함됩니다.

배포 추적 설정 방법

외부 배포 도구는 배포 상태가 변경될 때 추가적인 API 요청을 실행하는 웹훅을 일반적으로 제공합니다. 도구를 구성하여 GitLab 배포 API로 요청을 보낼 수 있습니다. 다음은 이벤트 및 API 요청 흐름에 대한 개요입니다:

note
GitLab API를 인증하기 위해 프로젝트 액세스 토큰을 생성할 수 있습니다.

예시: ArgoCD의 배포 추적

ArgoCD 웹훅을 활용하여 GitLab 배포 API로 배포 이벤트를 보낼 수 있습니다. 다음은 ArgoCD가 새로운 리비전을 성공적으로 배포할 때 GitLab에서 success 배포 레코드를 생성하는 예시 설정입니다:

  1. 새 웹훅을 생성합니다. 다음 매니페스트 파일을 저장하고 kubectl apply -n argocd -f <manifiest-file-path>를 통해 적용할 수 있습니다:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: argocd-notifications-cm
    data:
      trigger.on-deployed: |
        - description: Application is synced and healthy. Triggered once per commit.
          oncePer: app.status.sync.revision
          send:
          - gitlab-deployment-status
          when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
      template.gitlab-deployment-status: |
        webhook:
          gitlab:
            method: POST
            path: /projects/<your-project-id>/deployments
            body: |
              {
                "status": "success",
                "environment": "production",
                "sha": "{{.app.status.operationState.operation.sync.revision}}",
                "ref": "main",
                "tag": "false"
              }
      service.webhook.gitlab: |
        url: https://gitlab.com/api/v4
        headers:
        - name: PRIVATE-TOKEN
          value: <your-access-token>
        - name: Content-type
          value: application/json
    
  2. 애플리케이션 내에 새로운 구독을 생성합니다:

    kubectl patch app <your-app-name> -n argocd -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-deployed.gitlab":""}}}' --type merge
    
note
배포가 예상대로 생성되지 않으면 argocd-notifications 도구로 문제를 해결할 수 있습니다. 예를 들어, argocd-notifications template notify gitlab-deployment-status <your-app-name> --recipient gitlab:argocd-notifications를 실행하면 GitLab API 서버로부터 즉시 API 요청이 발생하고 오류 메시지가 렌더링됩니다.