amandawinkles / WAS-Tekton

Example of using WebSphere and Tekton

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tekton Pipeline for deploy WebSphere Application Server Apps

This is a sample pipeline that can be used for deploying an application to a tWAS container and deploying it to OCP. The pipeline will do the following:

  1. Update the name of the project to lowercase and remove spaces.
  2. Download code from a Git repository
  3. Compile the code using Maven
  4. Use the Dockerfile to build a new tWAS image and store it in the OCP ImageStreams repository
  5. Create a Deployment, Autoscaler, Service and Route.

The first 3 items are done with Tasks from the Tekton Hub.

The OpenShift and Tekton CLIs are needed to run commands and setup the pipeline.

  1. Login to your OCP cluster
  2. Install the Tekton Pipeline
oc apply -f tekton/tekton-pipelines-install.yaml
  1. Install the necessary Tekton Tasks from the Tekton Hub
tkn hub install task git-clone -n <project>
tkn hub install task maven -n <project>
tkn hub install task kaniko -n <project>
  1. Add task to format the app name (make lowercase, remove spaces)
oc apply -f tekton/was-pipeline-task-appname.yaml 
  1. Add the custom Task
oc apply -f tekton/was-pipeline-task.yaml 
  1. Add the PersistentVolumeClaim used to share between tasks.
oc apply -f tekton/was-pipeline-pvc.yaml
  1. Install the Pipeline
oc apply -f tekton/was-pipeline.yaml

To run the pipeline, a sample Pipeline Run is included

oc apply -f tekton/was-pipeline-run.yaml

Setting up a trigger

In a true CI/CD pipeleine developers would not be submitting a Pipeline Run with the necessary data to kick off a pipeline, they would use an EventListener that would take some inputs and start the Pipeline Run.

  1. Setup the necessary ServiceAccount and cluster secuity to receive events and act upon them
oc apply -f was-triggers-security.yaml
  1. Add the Trigger Template, which is an outline of how to handle the Trigger and what to run, which is similar to the Pipeline Run
oc apply -f was-triggers-template.yaml
  1. Add the necessary bindings for this specific application. This contains information to be passed to the Trigger Template
oc apply -f was-triggers-bindings.yaml
  1. Add the EventListener, which will startup a Pod and service to listen to Events for the trigger. The Pod name will be prefixed with an el with the name of the EventListen. In this sample it is called el-was-triggers-eventlistener. The Service is given the same name as the Pod.
oc apply -f was-triggers-eventlistener.yaml
  1. Create a Route so that the Trigger can be called from outside the cluster.
oc apply -f was-triggers-route.yaml

To test the Trigger, the Route endpoint can be called with the necessary JSON parameters.

ROUTE_HOST=$(oc get route el-was-triggers-listener --template='http://{{.spec.host}}')
URL=https://github.com/bpaskin/WAS-Tekton.git
curl -v -H 'X-GitHub-Event: pull_request' -H 'Content-Type: application/json' -d '{ "repository": {"clone_url": "'"${URL}"'"}, "pull_request": {"head": {"sha": "master1", "repo": {"name":"WAS-TekTon"}}} }' ${ROUTE_HOST}

If the request is accepted successfully the HTTP response should be either a 201 Created or 202 Accepted.

Using a Webhook to trigger a build

The Pipeline can be started when a GitHub Pull is done. This will send a message to the Event Listener endpoint with some data. The repository name, SHA of the pull request and URL of the repository will be used in the pipeline.

  1. Go to the GitHub repository page in the web browser.
  2. Click the Settings tab.
  3. In the navigation pane, click Hooks.
  4. Click Add Webhook.
  5. In the Payload URL field, paste the webhook URL (output from the oc get route el-was-triggers-listener --template='http://{{.spec.host}}' command
  6. In the Content type field, select JSON.
  7. Leave the Secret field empty
  8. Below Which events would you like to trigger this webhook?, select Let me select individual events. In the options displayed, ensure that the Pull event is selected only.
  9. Ensure that the Active check box is selected. This option keeps the webhook enabled and sends notifications whenever an event is triggered.
  10. Click Add webhook to complete the configuration of the webhook in GitHub Enterprise.

About

Example of using WebSphere and Tekton


Languages

Language:Java 33.1%Language:JavaScript 25.7%Language:HTML 25.6%Language:CSS 14.1%Language:Python 0.8%Language:Dockerfile 0.6%