3.2. GitHub Webhook에서 Pipeline을 코드로 사용
GitHub 앱을 생성할 수 없는 경우 리포지토리에서 GitHub Webhook와 함께 Pipeline을 코드로 사용합니다. 그러나 GitHub Webhook에서 Pipeline을 코드로 사용하면 GitHub Check Runs API에 액세스할 수 없습니다. 작업 상태는 가져오기 요청에 대한 주석으로 추가되며 Checks 탭에서는 사용할 수 없습니다.
GitHub Webhook의 코드로서의 파이프라인은 /retest
및 /ok-to-test
와 같은 GitOps 주석을 지원하지 않습니다. 연속 통합(CI)을 다시 시작하려면 리포지토리에 대한 새 커밋을 생성합니다. 예를 들어 변경 없이 새 커밋을 생성하려면 다음 명령을 사용할 수 있습니다.
git --amend -a --no-edit && git push --force-with-lease <origin> <branchname>
$ git --amend -a --no-edit && git push --force-with-lease <origin> <branchname>
사전 요구 사항
- Pipeline as Code가 클러스터에 설치되어 있는지 확인합니다.
권한 부여를 위해 GitHub에서 개인 액세스 토큰을 생성합니다.
안전하고 세분화된 토큰을 생성하려면 해당 범위를 특정 리포지토리로 제한하고 다음 권한을 부여합니다.
표 3.1. 세분화된 토큰에 대한 권한 이름 액세스 관리
읽기 전용
메타데이터
읽기 전용
내용
읽기 전용
커밋 상태
읽기 및 쓰기
가져오기 요청
읽기 및 쓰기
Webhook
읽기 및 쓰기
클래식 토큰을 사용하려면 범위를 공용 리포지토리 및 개인 리포지토리에 대해
public_
로 설정합니다. 또한 짧은 토큰 만료 기간을 제공하고 대체 위치에서 토큰을 기록해 둡니다.repo
참고tkn pac
CLI를 사용하여 Webhook를 구성하려면admin:repo_hook
범위를 추가합니다.
프로세스
Webhook를 구성하고
Repository
CR(사용자 정의 리소스)을 생성합니다.tkn pac
CLI 툴을 사용하여 Webhook를 구성하고리포지토리
CR을 자동으로 생성하려면 다음 명령을 사용합니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow tkn pac create repo
$ tkn pac create repo
대화형 출력 샘플
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ? Enter the Git repository url (default: https://github.com/owner/repo): ? Please enter the namespace where the pipeline should run (default: repo-pipelines): ! Namespace repo-pipelines is not found ? Would you like me to create the namespace repo-pipelines? Yes ✓ Repository owner-repo has been created in repo-pipelines namespace ✓ Setting up GitHub Webhook for Repository https://github.com/owner/repo 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ? Please enter the secret to configure the webhook for payload validation (default: sJNwdmTifHTs): sJNwdmTifHTs ℹ ️You now need to create a GitHub personal access token, please checkout the docs at https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token for the required scopes ? Please enter the GitHub access token: **************************************** ✓ Webhook has been created on repository owner/repo 🔑 Webhook Secret owner-repo has been created in the repo-pipelines namespace. 🔑 Repository CR owner-repo has been updated with webhook secret in the repo-pipelines namespace ℹ Directory .tekton has been created. ✓ We have detected your repository using the programming language Go. ✓ A basic template has been created in /home/Go/src/github.com/owner/repo/.tekton/pipelinerun.yaml, feel free to customize it.
? Enter the Git repository url (default: https://github.com/owner/repo): ? Please enter the namespace where the pipeline should run (default: repo-pipelines): ! Namespace repo-pipelines is not found ? Would you like me to create the namespace repo-pipelines? Yes ✓ Repository owner-repo has been created in repo-pipelines namespace ✓ Setting up GitHub Webhook for Repository https://github.com/owner/repo 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ? Please enter the secret to configure the webhook for payload validation (default: sJNwdmTifHTs): sJNwdmTifHTs ℹ ️You now need to create a GitHub personal access token, please checkout the docs at https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token for the required scopes ? Please enter the GitHub access token: **************************************** ✓ Webhook has been created on repository owner/repo 🔑 Webhook Secret owner-repo has been created in the repo-pipelines namespace. 🔑 Repository CR owner-repo has been updated with webhook secret in the repo-pipelines namespace ℹ Directory .tekton has been created. ✓ We have detected your repository using the programming language Go. ✓ A basic template has been created in /home/Go/src/github.com/owner/repo/.tekton/pipelinerun.yaml, feel free to customize it.
Webhook를 구성하고
리포지토리
CR을 수동으로 생성하려면 다음 단계를 수행합니다.OpenShift 클러스터에서 Pipeline의 공용 URL을 코드 컨트롤러로 추출합니다.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')
$ echo https://$(oc get route -n openshift-pipelines pipelines-as-code-controller -o jsonpath='{.spec.host}')
GitHub 리포지토리 또는 조직에서 다음 단계를 수행합니다.
- 설정 -> Webhook 로 이동하여 Webhook 추가 를 클릭합니다.
- Payload URL 을 코드 컨트롤러 공용 URL로 Pipeline으로 설정합니다.
- 콘텐츠 유형을 application/json 으로 선택합니다.
웹 후크 시크릿을 추가하고 대체 위치에서 기록해 둡니다. 로컬 시스템에
openssl
을 설치하면 임의의 보안을 생성합니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow openssl rand -hex 20
$ openssl rand -hex 20
- 개별 이벤트 선택을 클릭하고 Commit comments,Issue comments,Pull request, Pushes 이벤트를 선택합니다.
- Webhook 추가를 클릭합니다.
OpenShift 클러스터에서 개인 액세스 토큰 및 Webhook 시크릿을 사용하여
Secret
오브젝트를 생성합니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc -n target-namespace create secret generic github-webhook-config \ --from-literal provider.token="<GITHUB_PERSONAL_ACCESS_TOKEN>" \ --from-literal webhook.secret="<WEBHOOK_SECRET>"
$ oc -n target-namespace create secret generic github-webhook-config \ --from-literal provider.token="<GITHUB_PERSONAL_ACCESS_TOKEN>" \ --from-literal webhook.secret="<WEBHOOK_SECRET>"
리포지토리
CR을 생성합니다.예:
리포지토리
CRCopy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: url: "https://github.com/owner/repo" git_provider: secret: name: "github-webhook-config" key: "provider.token" # Set this if you have a different key in your secret webhook_secret: name: "github-webhook-config" key: "webhook.secret" # Set this if you have a different key for your secret
apiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: url: "https://github.com/owner/repo" git_provider: secret: name: "github-webhook-config" key: "provider.token" # Set this if you have a different key in your secret webhook_secret: name: "github-webhook-config" key: "webhook.secret" # Set this if you have a different key for your secret
참고코드로서의 파이프라인은 OpenShift
Secret
오브젝트 및Repository
CR이 동일한 네임스페이스에 있다고 가정합니다.
선택 사항: 기존
리포지토리
CR의 경우 여러 GitHub Webhook 보안을 추가하거나 삭제된 보안을 대신 제공합니다.tkn pac
CLI 툴을 사용하여 Webhook를 추가합니다.예:
tkn pac
CLI를 사용한 추가 WebhookCopy to Clipboard Copied! Toggle word wrap Toggle overflow tkn pac webhook add -n repo-pipelines
$ tkn pac webhook add -n repo-pipelines
대화형 출력 샘플
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ✓ Setting up GitHub Webhook for Repository https://github.com/owner/repo 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ? Please enter the secret to configure the webhook for payload validation (default: AeHdHTJVfAeH): AeHdHTJVfAeH ✓ Webhook has been created on repository owner/repo 🔑 Secret owner-repo has been updated with webhook secert in the repo-pipelines namespace.
✓ Setting up GitHub Webhook for Repository https://github.com/owner/repo 👀 I have detected a controller url: https://pipelines-as-code-controller-openshift-pipelines.apps.example.com ? Do you want me to use it? Yes ? Please enter the secret to configure the webhook for payload validation (default: AeHdHTJVfAeH): AeHdHTJVfAeH ✓ Webhook has been created on repository owner/repo 🔑 Secret owner-repo has been updated with webhook secert in the repo-pipelines namespace.
-
기존 OpenShift
Secret
오브젝트에서webhook.secret
키를 업데이트합니다.
선택 사항: 기존
리포지토리
CR의 경우 개인 액세스 토큰을 업데이트합니다.tkn pac
CLI 툴을 사용하여 개인 액세스 토큰을 업데이트합니다.예:
tkn pac
CLI를 사용하여 개인 액세스 토큰 업데이트Copy to Clipboard Copied! Toggle word wrap Toggle overflow tkn pac webhook update-token -n repo-pipelines
$ tkn pac webhook update-token -n repo-pipelines
대화형 출력 샘플
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ? Please enter your personal access token: **************************************** 🔑 Secret owner-repo has been updated with new personal access token in the repo-pipelines namespace.
? Please enter your personal access token: **************************************** 🔑 Secret owner-repo has been updated with new personal access token in the repo-pipelines namespace.
또는
Repository
CR을 수정하여 개인 액세스 토큰을 업데이트합니다.Repository
CR에서 시크릿 이름을 찾습니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: # ... git_provider: secret: name: "github-webhook-config" # ...
apiVersion: "pipelinesascode.tekton.dev/v1alpha1" kind: Repository metadata: name: my-repo namespace: target-namespace spec: # ... git_provider: secret: name: "github-webhook-config" # ...
oc patch
명령을 사용하여$target_namespace
네임스페이스에서$NEW_TOKEN
값을 업데이트합니다.Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc -n $target_namespace patch secret github-webhook-config -p "{\"data\": {\"provider.token\": \"$(echo -n $NEW_TOKEN|base64 -w0)\"}}"
$ oc -n $target_namespace patch secret github-webhook-config -p "{\"data\": {\"provider.token\": \"$(echo -n $NEW_TOKEN|base64 -w0)\"}}"