Skip to content

Commit

Permalink
[KOGITO-7278][KSW-Guides] Building Workflow Images with Tekton Pipelines
Browse files Browse the repository at this point in the history
Signed-off-by: desmax74 <[email protected]>
  • Loading branch information
desmax74 committed Apr 28, 2023
1 parent fe4ede4 commit 91ffcbb
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
10 changes: 10 additions & 0 deletions serverlessworkflow/modules/ROOT/pages/cloud/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ xref:cloud/operator/build-and-deploy-workflows.adoc[]
Learn how to build and deploy workflow services with {operator_name}
--


[.card]
--
[.card-title]
xref:cloud/operator/build-workflow-images-with-tekton.adoc[]
[.card-description]
Learn how to build workflow services using Tekton
--


[.card]
--
[.card-title]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
= Building Workflows Images with Tekton
:compat-mode!:
// Metadata:
:description: Building Workflow Images with Tekton
:keywords: kogito, workflow, serverless, operator, kubernetes, minikube, openshift, containers, tekton, pipelines

This document describes how to build a Workflow Application on a Kubernetes cluster using the Tekton pipeline.


.Prerequisites
You have a git repo containing your workflow and the dockerfile to build the workflow as a docker/podman image.

[NOTE]
====
If you are using Openshift you can install the Red Hat Pipeline Operator, if you are using Minikube you can follow this link:https://github.com/tektoncd/pipeline/blob/main/docs/developers/local-setup.md#using-minikube[tekton guide for Minikube]
If using Kind you can follow this link:https://github.com/tektoncd/plumbing/tree/main/hack[Tekton guide for Kind] on plain kubernetes cluster you can follow this link:https://tekton.dev/docs/pipelines/install/[Tekton guide for kubernetes]
====


== Create The pipeline
In the namespace `kogito-serverless-operator-system` where is deployed the Kogito Serverless Operator in the pipelines menu open the item Pipeline and go inthe create, copy the following yaml.
It contains a pipeline to clone your image workflow repo, build the image anbd push to the local image registry.


----
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: custom-workflow-image-pipeline
namespace: kogito-serverless-operator-system
spec:
params:
- description: name of the deployment to be patched
name: deployment-name
type: string
- description: url of the git repo for the code of deployment
name: git-url
type: string
- default: pipelines-1.9
description: revision to be used from repo of the code for deployment
name: git-revision
type: string
- description: image to be built from the code
name: IMAGE
type: string
tasks:
- name: fetch-repository
params:
- name: url
value: $(params.git-url)
- name: subdirectory
value: ''
- name: deleteExisting
value: 'true'
- name: revision
value: $(params.git-revision)
taskRef:
kind: ClusterTask
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
- name: build-image
params:
- name: IMAGE
value: $(params.IMAGE)
- name: TLSVERIFY
value: 'false'
runAfter:
- fetch-repository
taskRef:
kind: ClusterTask
name: buildah
workspaces:
- name: source
workspace: shared-workspace
workspaces:
- name: shared-workspace
----

== Create The PipelineRun to execute the pipeline

The next step is to create a pipeline run with the details of your git repo and the name of the image desidered

in the Pipeline menu, in the item PipelineRun copy the following yaml replacing the placeholder with your values
i.e. `image registry available at image-registry.openshift-image-registry.svc:5000/`

----
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: custom-workflow-image-pipeline-run
namespace: kogito-serverless-operator-system
spec:
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
params:
- name: deployment-name
value: <your-image-name>
- name: git-url
value: https://<your repo>.git
- name: git-revision
value: "main"
- name: IMAGE
value: "image-registry.openshift-image-registry.svc:5000/kogito-serverless-operator-system/<your-image-name>:latest"
pipelineRef:
name: custom-workflow-image-pipeline
----
You can check the execution of the pipeline in the UI,
at the end your image will be available at:
image-registry.openshift-image-registry.svc:5000/kogito-serverless-operator-system/<your-image-name>:latest


== Create The PipelineRun with Tkn cli

If you have installed the Tekton cli you can run the pipeline with the following command:
----
tkn pipeline start kogito-serverless-operator-pipeline \
-w name=shared-workspace,volumeClaimTemplateFile=https://raw.githubusercontent.com/kiegroup/kogito-serverless-operator/main/tekton/volume/persistent_volume.yaml \
-p deployment-name=<your-image-name> \
-p git-url=https://<your repo>.git \
-p git-revision=main \
-p IMAGE='image-registry.openshift-image-registry.svc:5000/kogito-serverless-operator-system/<your-image-name>:latest' \
--use-param-defaults
----

This command returns an id to check the execution with the cli in this way
----
tkn pipelinerun logs custom-workflow-image-pipeline-run-<id> -f -n <your-namespace>
----

At the end your image will be cluster's internal registry, like this example:
----
image-registry.openshift-image-registry.svc:5000/kogito-serverless-operator-system/<your-image-name>:latest
----

0 comments on commit 91ffcbb

Please sign in to comment.