Skip to content

Deploy Application With Custom Build Tool/Frameworkβš“οΈŽ

This Use Case describes the procedure of adding custom Tekton libraries that include pipelines with tasks. In addition to it, the process of modifying custom pipelines and tasks is enlightened as well.

Goalsβš“οΈŽ

  • Add custom Tekton pipeline library;
  • Modify existing pipelines and tasks in a custom Tekton library.

Preconditionsβš“οΈŽ

  • EDP instance with Gerrit and Tekton inside is configured;
  • Developer has access to the EDP instances using the Single-Sign-On approach;
  • Developer has the Administrator role to perform merge in Gerrit.

Scenarioβš“οΈŽ

Note

This case is based on our predefined repository and application. Your case may be different.

To create and then modify a custom Tekton library, please follow the steps below:

Add Custom Application to EDPβš“οΈŽ

  1. Open EDP Portal URL. Use the Sign-In option:

    Logging Page
    Logging screen

  2. In the top right corner, enter the Cluster settings and ensure that both Default namespace and Allowed namespace are set:

    Settings
    Cluster settings

  3. Create the new Codebase with the Application type using the Clone strategy. To do this, click the EDP tab:

    Cluster Overview
    Cluster overview

  4. Select the Components section under the EDP tab and push the create + button:

    Components Overview
    Components tab

  5. Select the Application codebase type because is meant to be delivered as a container and deployed inside the Kubernetes cluster. Choose the Clone strategy and this example repository:

    Codebase Info
    Step codebase info

  6. In the Application Info tab, define the following values and click the Proceed button:

    • Application name: tekton-hello-world
    • Default branch: master
    • Application code language: Other
    • Language version/framework: go
    • Build tool: shell

    Application Info
    Application info

    Note

    These application details are required to match the Pipeline name gerrit-shell-go-app-build-default.

    The PipelineRun name is formed with the help of TriggerTemplates in pipelines-library so the Pipeline name should correspond to the following structure:

      pipelineRef:
        name: gerrit-$(tt.params.buildtool)-$(tt.params.framework)-$(tt.params.cbtype)-build-$(tt.params.versioning-type)
    
    The PipelineRun is created as soon as Gerrit (or, if configured, GitHub, GitLab) sends a payload during Merge Request events.
  7. In the Advances Settings tab, define the below values and click the Apply button:

    • CI tool: Tekton
    • Codebase versioning type: default
    • Leave Specify the pattern to validate a commit message empty.

    Advanced Settings
    Advanced settings

  8. Check the application status. It should be green:

    Components overview page
    Application status

    Now that the application is created successfully, proceed to adding the Tekton library.

Add Tekton Libraryβš“οΈŽ

  1. Select the Components section under the EDP tab and push the create + button:

    Components Overview
    Components tab

  2. Create a new Codebase with the Library type using the Create strategy:

    Codebase Info
    Step codebase info

    Note

    The EDP Create strategy will automatically pull the code for the Tekton Helm application from here.

  3. In the Application Info tab, define the following values and click the Proceed button:

    • Application name: custom-tekton-chart
    • Default branch: master
    • Application code language: Helm
    • Language version/framework: Pipeline
    • Build tool: Helm

    Codebase Info
    Step codebase info

  4. In the Advances Settings tab, define the below values and click the Apply button:

    • CI tool: Tekton
    • Codebase versioning type: default
    • Leave Specify the pattern to validate a commit message empty.

    Advanced Settings
    Advanced settings

  5. Check the codebase status:

    Components overview page
    Codebase status

Modify Tekton Pipelineβš“οΈŽ

Note

Our recommendation is to avoid modifying the default Tekton resources. Instead, we suggest creating and modifying your own custom Tekton library.

Now that the Tekton Helm library is created, it is time to clone, modify and then apply it to the Kubernetes cluster.

  1. Generate SSH key to work with Gerrit repositories:

    ssh-keygen -t ed25519 -C "your_email@example.com"
    
  2. Log into Gerrit UI.

  3. Go to Gerrit Settings -> SSH keys, paste your generated public SSH key to the New SSH key field and click ADD NEW SSH KEY:

    Gerrit settings
    Gerrit settings
    Gerrit settings
    Gerrit settings

  4. Browse Gerrit Repositories and select custom-tekton-chart project:

    Browse Gerrit repositories
    Browse Gerrit repositories

  5. Clone the repository with SSH using Clone with commit-msg hook command:

    Gerrit clone
    Gerrit clone

    Note

    In case of the strict firewall configurations, please use the HTTP protocol to pull and configure the HTTP Credentials in Gerrit.

  6. Examine the repository structure. It should look this way by default:

    custom-tekton-chart
      β”œβ”€β”€ Chart.yaml
      β”œβ”€β”€ chart_schema.yaml
      β”œβ”€β”€ ct.yaml
      β”œβ”€β”€ lintconf.yaml
      β”œβ”€β”€ templates
      β”‚Β Β  β”œβ”€β”€ pipelines
      β”‚Β Β  β”‚Β Β  └── hello-world
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-build-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-build-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-build-lib-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-build-lib-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-review-lib.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gerrit-review.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-build-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-build-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-build-lib-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-build-lib-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-review-lib.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ github-review.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitlab-build-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitlab-build-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitlab-build-lib-default.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitlab-build-lib-edp.yaml
      β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gitlab-review-lib.yaml
      β”‚Β Β  β”‚Β Β      └── gitlab-review.yaml
      β”‚Β Β  └── tasks
      β”‚Β Β      └── task-hello-world.yaml
      └── values.yaml
    

    Note

    Change the values in the values.yaml file.

    The gitProvider parameter is the git hosting provider, Gerrit in this example. The similar approach be made with GitHub, or GitLab.

    The dnsWildCard parameter is the cluster DNS address.

    The gerritSSHPort parameter is the SSH port of the Gerrit service on Kubernetes. Check the Gerrit port in your edp installation global section.

    Note

    Our custom Helm chart includes edp-tekton-common-library dependencies in the Chart.yaml file. This library allows to use our predefined code snippets.

    Here is an example of the filled in values.yaml file:

    nameOverride: ""
    fullnameOverride: ""
    
    global:
      gitProvider: gerrit
      dnsWildCard: "example.domain.com"
      gerritSSHPort: "30009"
    
  7. Modify and add tasks or pipelines.

    As an example, let's assume that we need to add the helm-lint pipeline task to the review pipeline. To implement this, insert the code below to the gerrit-review.yaml file underneath the hello task:

        - name: hello
          taskRef:
            name: hello
          runAfter:
          - init-values
          params:
          - name: BASE_IMAGE
            value: "$(params.shell-image-version)"
          - name: username
            value: "$(params.username)"
          workspaces:
            - name: source
              workspace: shared-workspace
    
        - name: helm-lint
          taskRef:
            kind: Task
            name: helm-lint
          runAfter:
            - hello
          params:
            - name: EXTRA_COMMANDS
              value: |
                ct lint --validate-maintainers=false --charts deploy-templates/
          workspaces:
            - name: source
              workspace: shared-workspace
    

    Note

    The helm-lint task references to the default pipeline-library Helm chart which is applied to the cluster during EDP installation.

    The runAfter parameter shows that this Pipeline task will be run after the hello pipeline task.

  8. Build Helm dependencies in the custom chart:

    helm dependency update .
    
  9. Ensure that the chart is valid and all the indentations are fine:

    helm lint .
    

    To validate if the values are substituted in the templates correctly, render the templated YAML files with the values using the following command. It generates and displays all the manifest files with the substituted values:

    helm template .
    
  10. Install the custom chart with the command below. You can also use the --dry-run flag to simulate the chart installation and catch possible errors:

    helm upgrade --install edp-tekton-custom . -n edp --dry-run
    
    helm upgrade --install edp-tekton-custom . -n edp
    
  11. Check the created pipelines and tasks in the cluster:

    kubectl get tasks -n edp
    kubectl get pipelines -n edp
    
  12. Commit and push the modified Tekton Helm chart to Gerrit:

    git add .
    git commit -m "Add Helm chart testing for go-shell application"
    git push origin HEAD:refs/for/master
    
  13. Check the Gerrit code review for the custom Helm chart pipelines repository in Tekton:

    Gerrit code review status
    Gerrit code review status

  14. Go to Changes -> Open, click CODE-REVIEW and submit the merge request:

    Gerrit merge
    Gerrit merge
    Gerrit merge
    Gerrit merge

  15. Check the build Pipeline status for the custom Pipelines Helm chart repository in Tekton:

    Tekton status
    Tekton status

Create Application Merge Requestβš“οΈŽ

Since we applied the Tekton library to the Kubernetes cluster in the previous step, let's test the review and build pipelines for our tekton-hello-world application.

Perform the below steps to merge new code (Merge Request) that passes the Code Review flow. For the steps below, we use Gerrit UI but the same actions can be performed using the command line and Git tool:

  1. Log into Gerrit UI, select tekton-hello-world project, and create a change request.

  2. Browse Gerrit Repositories and select tekton-hello-world project:

    Browse Gerrit repositories
    Browse Gerrit repositories

  3. Clone the tekton-hello-world repository to make the necessary changes or click the Create Change button in the Commands section of the project to make changes via Gerrit GUI:

    Create Change request
    Create Change request

  4. In the Create Change dialog, provide the branch master, write some text in the Description (commit message) and click the Create button:

    Create Change
    Create Change

  5. Click the Edit button of the merge request and add deployment-templates/values.yaml to modify it and change the ingress.enabled flag from false to true:

    Update values.yaml file
    Update values.yaml file
    Update values.yaml file
    Update values.yaml file

  6. Check the Review Pipeline status. The helm-lint pipeline task should be displayed there:

    Review Change
    Review Change

  7. Review the deployment-templates/values.yaml file and push the SAVE & PUBLISH button. As soon as you get Verified +1 from CI bot, the change is ready for review. Click the Mark as Active and Code-review buttons:

    Review Change
    Review Change

  8. Click the Submit button. Then, your code is merged to the main branch, triggering the Build Pipeline.

    Review Change
    Review Change

    Note

    If the build is added and configured, push steps in the pipeline, it will produce a new version of artifact, which will be available for the deployment in EDP Portal.

  9. Check the pipelines in the Tekton dashboard:

    Tekton custom pipelines
    Tekton custom pipelines
    Tekton custom pipelines
    Tekton custom pipelines

What happens under the hood:
1) Gerrit sends a payload during Merge Request event to the Tekton EventListener;
2) EventListener catches it with the help of Interceptor;
3) TriggerTemplate creates a PipelineRun.

The detailed scheme is shown below:

graph LR;
    A[Gerrit events] --> |Payload| B(Tekton EventListener) --> C(Tekton Interceptor CEL filter) --> D(TriggerTemplate)--> E(PipelineRun)

This chart will be using the core of common-library and pipelines-library and custom resources on the top of them.