In today's fast-paced software development landscape, pipelines have become essential for organizations to streamline their development processes. Tekton, an open source framework for building pipelines, offers a flexible and scalable solution. This article will explore how to create an efficient and automated workflow by integrating Tekton (Red Hat OpenShift Pipelines) with AWS CodeCommit, a fully managed source control service by Amazon Web Services (AWS).
Integrating Trigger with AWS CodeCommit brings together the benefits of a flexible pipeline framework and a managed source control service. This integration enables organizations to create an efficient and automated workflow, encompassing code changes, building, testing, and deploying applications. To enable the AWS CodeCommit webhook to trigger a Tekton pipeline in Red Hat OpenShift, you must configure several resources, including Tekton TriggerTemplate, EventListener, and TriggerBinding objects.
Refer to the OpenShift Pipelines documentation for more information. This article describes the steps to connect AWS CodeCommit with the OpenShift Pipelines and use it as source code management (SCM) for CI\CD.
Prerequisites
- OpenShift cluster and AWS account to use AWS CodeCommit and SNS service.
- To setup, follow OpenShift Pipelines (OSP) for OpenShift and Tekton Pipelines and Tekton Triggers for Kubernetes.
- Make sure all workloads are up and running.
Steps to connect AWS CodeCommit
1. Enable debug logs for Triggers eventlistener to obtain the subscription URL, which we will explain in a later section of this article. Debug logging will help us to see the event listener detailed logging information.
2. Create samples for TriggerTemplate, TriggerBinding, and EventListener and expose event listener service, which will help to configure in AWS CodeCommit trigger.
You can review samples on GitHub.
oc create -f https://gist.githubusercontent.com/savitaashture/097c366753ea58017e8a24be83892ad4/raw/a441f65afe73113dd554122c8e86818af030b7da/gistfile1.txt
3. Sign in to your AWS account and navigate to your chosen region.
4. Look for the CodeCommit AWS service in the search bar to locate and access the repository hosting and version control solution swiftly.
5. Navigate to the left side of the panel and choose Source -> Repositories -> Create Repository to initiate the repository creation process (Figure 1).
Adding triggers
After successfully creating the repository, proceed with the following steps to add triggers:
1. Create a Simple Notification Service (SNS) as shown in Figure 2.
2. Search for SNS service.
3. Click on Create topic (Figure 3).
4. Click on Create Subscription (Figure 4).
5. Ensure that you enable raw message delivery by checking the appropriate box (Figure 5).
6. Once you have successfully created a subscription, click on Request confirmation (Figure 6).
7. Then go to the event listener pod:
oc logs -f <pod-name>
8. Search for SubscribeURL and copy value.
Example:
"SubscribeURL\" : \"https://sns.us-east-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-2:361754793035:demo-acc-tekton&Token=2336412f37fb687f5d51e6e2425c464de257e9a5924e2fd4cf343ac0f1dcdb40cc7dad021f86dcf2af98fbabf59b6314b975e5d5bfc673924522ab99cb9b45b824a2795d81328e045db0148571c0ba451648f60157690c2c377eb41f58a7d663c15a36654beda27c295f9f90cc8a0f46096aea96a40f9c4ca0b1ec1092e32116\"
9. Click on Confirm subscription (Figure 7).
10. Make sure the status is confirmed (Figure 8).
11. Now go back to CodeCommit page.
12. Go to Source -> Repositories and select demo-acc-tekton (Figure 9).
13. Go to Settings -> Triggers, then click on Create trigger (Figure 10).
14. While creating the trigger, give the trigger name. Set the events to: All repository events Service to use AWS SNS. Choose the previously configured SNS topic (Figure 11).
15. Once the Create trigger is successful, go back to the AWS CodeCommit repository and send a push request. You should see a new Taskrun created.
kubectl get taskruns | grep aws-codecommit-push-listener-run-
Important note
Users can get the request body data coming from AWS Code Commit from the EventListener pod as we have enabled debug log initially. So all request body will be displayed as payload.
Sample payload for push request:
{"level":"debug","ts":"2023-07-29T18:49:13.904Z","logger":"eventlistener","caller":"sink/sink.go:177", "msg":"handling event with path /, payload: {\"Records\":[{\"awsRegion\":\"us-e
ast-2\",\"codecommit\":{\"references\":[{\"commit\":\"b660b4bbf35e6d18478063a01dbcaa0f94edef6e\",\"ref\":\"refs/heads/main\"}]},\"customData\":null,\"eventId\":\"9d769236-ad9b-48ea-
84e0-bd1b93378560\",\"eventName\":\"ReferenceChanges\",\"eventPartNumber\":1,\"eventSource\":\"aws:codecommit\",\"eventSourceARN\":\"arn:aws:codecommit:us-east-2:361754793035: demo-a
cc-tekton\",\"eventTime\":\"2023-07-29T18:49:13.816+0000\",\"eventTotalParts\":1,\"eventTriggerConfigId\":\"34d16103-b8a5-48cd-b16a-cbd287a724c8\",\"eventTriggerName\":\"demo-acc-te
kton\",\"eventVersion\":\"1.0\",\"userIdentityARN\":\"arn:aws:iam: :361754793035:user/njajodia@redhat.com-v7nxk-admin\"}]} and header: map [Accept-Encoding: [gzip,deflate] Content-Leng
Summary
In this article, we explored integrating Tekton (OpenShift Pipelines) with AWS CodeCommit. Integrating Tekton with AWS CodeCommit brings together the benefits of a flexible pipeline framework and a managed source control service. This integration enables organizations to create an efficient and automated workflow, encompassing code changes, building, testing, and deploying applications. We demonstrated how to enable the AWS CodeCommit to trigger a Tekton pipeline in OpenShift and configured several resources, including TriggerTemplate, EventListener, and TriggerBinding objects along with SNS topic in AWS.