Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AWS CodeCommit examples for push request and also README to configure AWS CodeCommit #1619

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions examples/v1beta1/awscodecommit/push/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
## AWS CodeCommit push EventListener

Creates an EventListener that listens for AWS CodeCommit push request.

### Pre-requisites

1. Enable [debug logs for Triggers eventlistener](https://github.com/tektoncd/triggers/blob/main/docs/troubleshooting.md#configuring-debug-logging-for-eventlisteners) (This will be helpful for getting subscription URL which you do in later section)
2. Should have access to AWS
1. Should have URL accessible publicly to configure in webhook

### Steps to try:

1. To create the AWS CodeCommit push eventlistener and all related resources, run:

```bash
kubectl apply -f .
```

1. To get the eventlistener URL, run:

```bash
kubectl get el
```

### Steps for AWS CodeCommit configuration

1. Login to aws console
2. Search for CodeCommit aws service
3. On left side of the panel select **Source** -> **Repositories** -> **Create repository**
![img.png](images/img.png)
4. Once after successful creation of repository follow below steps to add Triggers
5. a) Create SNS (Simple Notification Service)

ai) Search for sns service
![img.png](images/sns.png)

aii) Click on Create topic

![img.png](images/createtopic.png)

aiii) Click on **Create subscription**

1.
![img.png](images/createsubscription.png)
2.
![img.png](images/createsubscriptionsuccess.png)
3. Once **Create subscription** is success click on **Request confirmation**
![img.png](images/requestconfirmation.png)
a. Then go to eventlistener pod

i. oc logs -f <pod-name>

ii. Search for SubscribeURL and copy value

"SubscribeURL\" : \"https://sns.us-east-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-2:361754793035:demo-acc-tekton&Token=2336412f37fb687f5d51e6e2425c464de257e9a5924e2fd4cf343ac0f1dcdb40cc7dad021f86dcf2af98fbabf59b6314b975e5d5bfc673924522ab99cb9b45b824a2795d81328e045db0148571c0ba451648f60157690c2c377eb41f58a7d663c15a36654beda27c295f9f90cc8a0f46096aea96a40f9c4ca0b1ec1092e32116\"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking: is this an active subscription? we may want to change it to something fake

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It no more works

So is that okay if i keep it as it is ?


4. Click on **Confirm subscription**

![img.png](images/confirmsubscription.png)
5. Make sure Status as **Confirmed**

![img.png](images/confirmed.png)

aiv) Now go back to CodeCommit page

**!!!!!Done with SNS configuration go back to codecommit flow!!!!!**

b) **Source** -> **Repositories** and select demo-acc-tekton
![img.png](images/selectrepo.png)

c) Go to **Settings -> Triggers** then click on **Create trigger**
![img.png](images/createtrigger.png)

d) While creating trigger give trigger name, set the events to All repository events, Service to use AWS SNS, and finally, choose the previously configured SNS topic
![img.png](images/createtriggersuccess.png)
e) Once the **Create trigger** is successful go back to Repository and send Push Request.

**!!!!!Done with CodeCommit configuration!!!!!**

f) You should see a new TaskRun that got created:

```bash
kubectl get taskruns | grep aws-codecommit-push-listener-run-
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
name: aws-codecommit-push
spec:
triggers:
- name: aws-codecommit-push
bindings:
- ref: aws-codecommit-push-binding
template:
ref: aws-codecommit-push-template
resources:
kubernetesResource:
spec:
template:
spec:
serviceAccountName: tekton-triggers-example-sa
containers:
- resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"

---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
name: aws-codecommit-push-binding
spec:
params:
- name: aws-codecommit-awsregion
value: $(body.Records[0].awsRegion)
- name: aws-codecommit-commit
value: $(body.Records[0].codecommit.references[0].commit)
- name: aws-codecommit-branch
value: $(body.Records[0].codecommit.references[0].ref)
- name: aws-codecommit-useridentity
value: $(body.Records[0].userIdentityARN)
---
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
name: aws-codecommit-push-template
spec:
params:
- name: aws-codecommit-awsregion
- name: aws-codecommit-commit
- name: aws-codecommit-branch
- name: aws-codecommit-useridentity
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: aws-codecommit-push-listener-run-
spec:
taskSpec:
steps:
- image: ubuntu
script: |
#! /bin/bash
echo "aws region is : $(tt.params.aws-codecommit-awsregion). commit is $(tt.params.aws-codecommit-commit).
branch name is : $(tt.params.aws-codecommit-branch). pusher name is $(tt.params.aws-codecommit-useridentity)."
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/v1beta1/awscodecommit/push/rbac.yaml