Deploy Application With Custom Build Tool/Framework
This use case outlines the steps for adding custom Tekton libraries that contain pipelines with tasks. It also covers the process of modifying custom pipelines and tasks.
Goalsβ
- Add custom Tekton pipeline library;
- Modify existing pipelines and tasks in a custom Tekton library.
Preconditionsβ
- KubeRocketCI instance with Gerrit and Tekton inside is configured;
- Developer has access to the KubeRocketCI instances using the Single-Sign-On approach;
- Developer has the
Administrator
role to perform merge in Gerrit.
Scenarioβ
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 KubeRocketCIβ
-
Open the UI Portal. Use the Sign-In option:
-
In the top right corner, enter the
Cluster settings
and ensure that bothDefault namespace
andAllowed namespace
are set: -
Create the new
Codebase
with theApplication
type using theClone
strategy. To do this, click the EDP tab: -
Select the
Components
section under the EDP tab and push the create+
button: -
Select the
Application
codebase type because is meant to be delivered as a container and deployed inside the Kubernetes cluster. Choose theClone
strategy and this example repository: -
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
noteThese 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.
- Application name:
-
In the
Advances Settings
tab, define the below values and click theApply
button:- CI tool:
Tekton
- Codebase versioning type:
default
- Leave
Specify the pattern to validate a commit message
empty.
- CI tool:
-
Check the application status. It should be green:
Now that the application is successfully created, proceed to adding the Tekton library to the KubeRocketCI platform.
Add Tekton Libraryβ
-
Select the
Components
section under the EDP tab and push the create+
button: -
Create a new Codebase with the
Library
type using theCreate
strategy:noteThe KubeRocketCI
Create
strategy will automatically pull the code for the Tekton Helm application from the template. -
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
- Application name:
-
In the
Advances Settings
tab, define the below values and click theApply
button:- CI tool:
Tekton
- Codebase versioning type:
default
- Leave
Specify the pattern to validate a commit message
empty.
- CI tool:
-
Check the codebase status:
Modify Tekton Pipelineβ
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.
-
Generate SSH key to work with Gerrit repositories:
ssh-keygen -t ed25519 -C "your_email@example.com"
-
Log into Gerrit UI.
-
Go to Gerrit
Settings
->SSH keys
, paste your generated public SSH key to theNew SSH key
field and clickADD NEW SSH KEY
: -
Browse Gerrit Repositories and select
custom-tekton-chart
project: -
Clone the repository with
SSH
usingClone with commit-msg hook
command:noteIn case of the strict firewall configurations, please use the
HTTP
protocol to pull and configure theHTTP Credentials
in Gerrit. -
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.yamlnoteChange 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.
noteOur 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" -
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-workspacenoteThe
helm-lint
task references to the defaultpipeline-library
Helm chart which is applied to the cluster during EDP installation.The
runAfter
parameter shows that this Pipeline task will be run after thehello
pipeline task. -
Build Helm dependencies in the custom chart:
helm dependency update .
-
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 .
-
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
-
Check the created pipelines and tasks in the cluster:
kubectl get tasks -n edp
kubectl get pipelines -n edp -
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 -
Check the Gerrit code review for the custom Helm chart pipelines repository in Tekton:
-
Go to
Changes
->Open
, clickCODE-REVIEW
and submit the merge request: -
Check the build Pipeline status for the custom Pipelines Helm chart repository in Tekton:
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:
-
Log into Gerrit UI, select
tekton-hello-world
project, and create a change request. -
Browse Gerrit Repositories and select
tekton-hello-world
project: -
Clone the
tekton-hello-world
repository to make the necessary changes or click theCreate Change
button in theCommands
section of the project to make changes via Gerrit GUI: -
In the
Create Change
dialog, provide the branchmaster
, write some text in theDescription
(commit message) and click theCreate
button: -
Click the
Edit
button of the merge request and adddeployment-templates/values.yaml
to modify it and change theingress.enabled flag
fromfalse
totrue
: -
Check the Review Pipeline status. The
helm-lint
pipeline task should be displayed there: -
Review the
deployment-templates/values.yaml
file and push theSAVE & PUBLISH
button. As soon as you getVerified +1
from CI bot, the change is ready for review. Click theMark as Active
andCode-review
buttons: -
Click the
Submit
button. Then, your code is merged to the main branch, triggering the Build Pipeline.noteIf 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.
-
Check the pipelines in the Tekton dashboard:
Under the hood, the following process takes place:
- Gerrit sends a payload to the Tekton EventListener when a Merge Request event occurs.
- The EventListener captures the payload with the assistance of an Interceptor.
- The TriggerTemplate is responsible for creating a PipelineRun.
The detailed scheme is shown below:
This chart will be using the core of common-library
and pipelines-library
and custom resources on the top of them.