외부 배포 도구의 배포 추적

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

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

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

배포 추적 설정 방법

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

  • 배포가 시작되면, running 상태의 배포를 생성합니다.
  • 배포가 성공하면, 배포 상태를 success업데이트합니다.
  • 배포가 실패하면, 배포 상태를 failed업데이트합니다.
note
GitLab API 인증을 위해 프로젝트 액세스 토큰을 생성할 수 있습니다.

예시: ArgoCD의 배포 추적

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

  1. 새로운 웹훅을 생성하세요. 아래 매니페스트 파일을 저장하고 kubectl apply -n argocd -f <manifest-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 는 즉시 API 요청을 트리거하고, 문제가 있을 경우 GitLab API 서버로부터 오류 메시지를 렌더링합니다.