외부 배포 도구의 배포 추적
Tier: Free, Premium, Ultimate
Offering: GitLab.com, Self-managed, GitLab Dedicated
- GitLab 12.5에서 소개됨.
GitLab은 내장 배포 솔루션을 제공하지만, Heroku 또는 ArgoCD와 같은 외부 배포 도구를 사용하는 것을 선호할 수 있습니다. GitLab은 이러한 외부 도구로부터 배포 이벤트를 수신하고 GitLab 내에서 배포를 추적할 수 있습니다. 예를 들어, 추적 설정을 통해 다음과 같은 기능을 활용할 수 있습니다:
- Merge Request이 배포되고 어떤 환경으로 이동했는지 확인.
- 환경 또는 배포 날짜별로 Merge Request 필터링.
- DevOps Research and Assessment (DORA) metrics.
- 환경 및 배포 보기.
- 배포별로 새롭게 포함된 Merge Request 추적.
배포 추적 설정 방법
외부 배포 도구는 배포 상태가 변경될 때 추가적인 API 요청을 실행하는 웹훅을 일반적으로 제공합니다. 도구를 구성하여 GitLab 배포 API로 요청을 보낼 수 있습니다. 다음은 이벤트 및 API 요청 흐름에 대한 개요입니다:
- 배포가 시작되면,
running
상태로 배포 생성. - 배포가 성공하면, 배포 상태를
success
로 업데이트. - 배포에 실패하면, 배포 상태를
failed
로 업데이트.
GitLab API를 인증하기 위해 프로젝트 액세스 토큰을 생성할 수 있습니다.
예시: ArgoCD의 배포 추적
ArgoCD 웹훅을 활용하여 GitLab 배포 API로 배포 이벤트를 보낼 수 있습니다.
다음은 ArgoCD가 새로운 리비전을 성공적으로 배포할 때 GitLab에서 success
배포 레코드를 생성하는 예시 설정입니다:
-
새 웹훅을 생성합니다. 다음 매니페스트 파일을 저장하고
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
-
애플리케이션 내에 새로운 구독을 생성합니다:
kubectl patch app <your-app-name> -n argocd -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-deployed.gitlab":""}}}' --type merge
배포가 예상대로 생성되지 않으면
argocd-notifications
도구로 문제를 해결할 수 있습니다.
예를 들어, argocd-notifications template notify gitlab-deployment-status <your-app-name> --recipient gitlab:argocd-notifications
를 실행하면 GitLab API 서버로부터 즉시 API 요청이 발생하고 오류 메시지가 렌더링됩니다.