OpenShift Pipelines (Tekton) - Triggers with a cup of Gitea - Branch Webhook Demo
Prerequisite
Triggers with a cup of Gitea - Cluster Setup
Set Up The Namespace Provisioner
-
Create a Namespace
oc new-project namespace-provisioner
-
Create a service account with self-provisioner privileges
oc create sa provisioner -n namespace-provisioner oc adm policy add-cluster-role-to-user self-provisioner -z provisioner -n namespace-provisioner
-
Create a ConfigMap for the CA bundle that includes our Gitea server
cat << EOF | oc apply -n namespace-provisioner -f - apiVersion: v1 kind: ConfigMap metadata: name: trusted-ca labels: config.openshift.io/inject-trusted-cabundle: 'true' EOF
-
Create the Tekton Task and Trigger objects
oc apply -f ~/tekton-tutorial/gitea-demo/namespace-provisioner/ -n namespace-provisioner
-
Expose the Trigger via a Secured Route
SVC_NAME=$(oc get el ns-prov-trigger-listener -o=jsonpath='{.status.configuration.generatedName}') oc create route edge ${SVC_NAME} --service=${SVC_NAME}
Create the Gitea Webhook
-
Retrieve the endpoint URL of the Trigger Event Listener
echo "https://$(oc get route ${SVC_NAME} -o=jsonpath='{.spec.host}')"
-
Log into Gitea with the ‘developer’ user account:
-
Select the
Organization
tab on the right, and select thedemo
organization: -
Click on
Settings
to the right aboveNew Migration
: -
Select
Webhooks
from the menu on the left, and clickAdd webhook
: -
Use the URL from step 1 to fill in the webhook as shown:
-
Click the
Add Webhook
button: -
Your webhook is ready to fire.
Create A Git repository
Let’s use the Quarkus CLI to create a Java application and add it to our Gitea repository:
-
Create a basic Quarkus REST service:
We’re using the Quarkus CLI for this step. Check it out here: https://quarkus.io/guides/cli-tooling
mkdir ~/branch-test cd ~/branch-test quarkus create app --maven --java=11 --no-wrapper --package-name=fun.is.quarkus.demo fun.is.quarkus:hook-test:0.1
-
Initialize a git repository for the demo app code:
cd ~/branch-test/hook-test git init -b main git add . git commit -m "initial commit"
-
Add the Gitea server as a remote origin:
git remote add origin https://gitea-gitea.apps-crc.testing/demo/hook-test
-
Push the demo code to our Gitea instance:
GIT_SSL_NO_VERIFY=true git push --set-upstream origin main
Note: We’re using
GIT_SSL_NO_VERIFY
here because we have not set up trust between our Gitea server and workstation.When prompted, enter the credentials that you created for your gitea user:
developer
Take a Look at the Results
The webhook should have fired on the creation of the main
branch.
-
Log into the OpenShift console as
kubeadmin
crc console --credentials crc console
-
Take a look at the
TaksRuns
in thenamespace-provisioner
namespace: -
Log into the OpenShift CLI as the
developer
user:oc login -u developer -p developer https://api.crc.testing:6443
-
Take a look at the available namespaces:
oc get projects
NAME DISPLAY NAME STATUS hook-test-main Active
-
Create a new branch, and verify that another namespace appears:
cd ~/branch-test/hook-test git checkout -b my-feature GIT_SSL_NO_VERIFY=true git push --set-upstream origin my-feature
oc get projects
NAME DISPLAY NAME STATUS hook-test-main Active hook-test-my-feature Active
JSON Payload of a Create Hook
{
"sha": "9354b1ebd85dba28268d7a7fa2ba6722ef629542",
"ref": "my-feature",
"ref_type": "branch",
"repository": {
"id": 2,
"owner": {
"id": 4,
"login": "demo",
"full_name": "",
"email": "",
"avatar_url": "https://gitea-gitea.apps-crc.testing/avatars/fe01ce2a7fbac8fafaed7c982a04e229",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2022-05-14T16:13:22Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "private",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "demo"
},
"name": "hook-test",
"full_name": "demo/hook-test",
"description": "",
"empty": false,
"private": true,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 215,
"html_url": "https://gitea-gitea.apps-crc.testing/demo/hook-test",
"ssh_url": "gitea@gitea-gitea.apps-crc.testing:demo/hook-test.git",
"clone_url": "https://gitea-gitea.apps-crc.testing/demo/hook-test.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 3,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "main",
"archived": false,
"created_at": "2022-05-15T13:07:04Z",
"updated_at": "2022-05-15T13:17:47Z",
"permissions": {
"admin": false,
"push": false,
"pull": false
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"has_projects": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": true,
"allow_squash_merge": true,
"default_merge_style": "merge",
"avatar_url": "",
"internal": false,
"mirror_interval": "",
"mirror_updated": "0001-01-01T00:00:00Z",
"repo_transfer": null
},
"sender": {
"id": 2,
"login": "developer",
"full_name": "",
"email": "developer@gitea.crc.testing",
"avatar_url": "https://secure.gravatar.com/avatar/b2f888cb41ee3b9f75d5844732d68765?d=identicon",
"language": "",
"is_admin": false,
"last_login": "0001-01-01T00:00:00Z",
"created": "2022-05-14T15:48:18Z",
"restricted": false,
"active": false,
"prohibit_login": false,
"location": "",
"website": "",
"description": "",
"visibility": "public",
"followers_count": 0,
"following_count": 0,
"starred_repos_count": 0,
"username": "developer"
}
}