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

Modifying Creating CI/CD Pipelines based on revised tutorial #31331

Merged
merged 1 commit into from
Apr 20, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions cicd/pipelines/creating-applications-with-cicd-pipelines.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ toc::[]

With {pipelines-title}, you can create a customized CI/CD solution to build, test, and deploy your application.

To create a full-fledged, self-serving CI/CD pipeline for an application, you must perform the following tasks:
To create a full-fledged, self-serving CI/CD pipeline for an application, perform the following tasks:

* Create custom tasks, or install existing reusable tasks.
* Create and define the delivery pipeline for your application.
* Provide a storage volume or filesystem that is attached to a workspace for the pipeline execution using one of the following approaches:
* Provide a storage volume or filesystem that is attached to a workspace for the pipeline execution, using one of the following approaches:
** Specify a volume claim template that creates a persistent volume claim
** Specify a persistent volume claim
* Create a `PipelineRun` object to instantiate and invoke the pipeline.
* Add triggers to capture events in the source repository.

This section uses the `pipelines-tutorial` example to demonstrate the preceding tasks. The example uses a simple application which consists of:

* A front-end interface, `vote-ui`, with the source code in the link:https://github.com/openshift-pipelines/vote-ui/tree/pipelines-1.3[`ui-repo`] Git repository.
* A back-end interface, `vote-api`, with the source code in the link:https://github.com/openshift-pipelines/vote-api/tree/pipelines-1.3[`api-repo`] Git repository.
* The `apply-manifests` and `update-deployment` tasks in the link:https://github.com/openshift/pipelines-tutorial/tree/pipelines-1.3[`pipelines-tutorial`] Git repository.
* A front-end interface, `pipelines-vote-ui`, with the source code in the link:https://github.com/openshift/pipelines-vote-ui/tree/{pipelines-ver}[`pipelines-vote-ui`] Git repository.
* A back-end interface, `pipelines-vote-api`, with the source code in the link:https://github.com/openshift/pipelines-vote-api/tree/{pipelines-ver}[`pipelines-vote-api`] Git repository.
* The `apply-manifests` and `update-deployment` tasks in the link:https://github.com/openshift/pipelines-tutorial/tree/{pipelines-ver}[`pipelines-tutorial`] Git repository.

== Prerequisites

* You have access to an {product-title} cluster.
* You have installed xref:../../cicd/pipelines/installing-pipelines.adoc#installing-pipelines[OpenShift Pipelines] using the {pipelines-title} Operator listed in the OpenShift OperatorHub. Once installed, it is applicable to the entire cluster.
* You have installed xref:../../cli_reference/tkn_cli/installing-tkn.adoc#installing-tkn[OpenShift Pipelines CLI].
* You have forked the front-end link:https://github.com/openshift-pipelines/vote-ui/tree/pipelines-1.3[`ui-repo`] and back-end link:https://github.com/openshift-pipelines/vote-api/tree/pipelines-1.3[`api-repo`] Git repositories using your GitHub ID, and have Administrator access to these repositories.
* Optional: You have cloned the link:https://github.com/openshift/pipelines-tutorial/tree/pipelines-1.3[`pipelines-tutorial`] Git repository.
* You have forked the front-end link:https://github.com/openshift/pipelines-vote-ui/tree/{pipelines-ver}[`pipelines-vote-ui`] and back-end link:https://github.com/openshift/pipelines-vote-api/tree/{pipelines-ver}[`pipelines-vote-api`] Git repositories using your GitHub ID, and have Administrator access to these repositories.
* Optional: You have cloned the link:https://github.com/openshift/pipelines-tutorial/tree/{pipelines-ver}[`pipelines-tutorial`] Git repository.


include::modules/op-creating-project-and-checking-pipeline-service-account.adoc[leveloffset=+1]
Expand Down
10 changes: 5 additions & 5 deletions modules/op-adding-triggers.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc

[id="adding-triggers_{context}"]
= Adding Triggers to a Pipeline
= Adding triggers to a pipeline

Triggers enable pipelines to respond to external GitHub events, such as push events and pull requests. After you assemble and start a Pipeline for the application, add the `TriggerBinding`, `TriggerTemplate`, `Trigger`, and `EventListener` resources to capture the GitHub events.
Triggers enable pipelines to respond to external GitHub events, such as push events and pull requests. After you assemble and start a pipeline for the application, add the `TriggerBinding`, `TriggerTemplate`, `Trigger`, and `EventListener` resources to capture the GitHub events.

sounix000 marked this conversation as resolved.
Show resolved Hide resolved
[discrete]
.Procedure
Expand Down Expand Up @@ -63,7 +63,7 @@ spec:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: build-deploy-$(tt.params.git-repo-name)-$(uid)
generateName: build-deploy-$(tt.params.git-repo-name)-
sounix000 marked this conversation as resolved.
Show resolved Hide resolved
spec:
serviceAccountName: pipeline
pipelineRef:
Expand Down Expand Up @@ -117,7 +117,7 @@ spec:
bindings:
- ref: vote-app
template:
ref: vote-app
ref: vote-app
----

. Create the `Trigger` resource:
Expand All @@ -131,7 +131,7 @@ Alternatively, you can create the `Trigger` resource directly from the `pipeline
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://github.com/openshift/pipelines-tutorial/blob/{pipelines-ver}/03_triggers/03_trigger.yaml
$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/03_triggers/03_trigger.yaml
----

. Copy the contents of the following sample `EventListener` YAML file and save it:
Expand Down
15 changes: 4 additions & 11 deletions modules/op-assembling-a-pipeline.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc

[id="assembling-a-pipeline_{context}"]
= Assembling a Pipeline
= Assembling a pipeline

A pipeline represents a CI/CD flow and is defined by the tasks to be executed. It is designed to be generic and reusable in multiple applications and environments.

A pipeline specifies how the tasks interact with each other and their order of execution, using the `from` and `runAfter` parameters. It uses the `workspaces` field to specify one or more volumes that each task in the pipeline requires during execution.
A pipeline specifies how the tasks interact with each other and their order of execution using the `from` and `runAfter` parameters. It uses the `workspaces` field to specify one or more volumes that each task in the pipeline requires during execution.

In this section, you will create a pipeline that takes the source code of the application from GitHub and then builds and deploys it on {product-title}.
In this section, you will create a pipeline that takes the source code of the application from GitHub, and then builds and deploys it on {product-title}.

//The image below displays the various components of `pipelines-tutorial` Pipeline, and how these components interact with each other.

//image::op-assemble-a-pipeline.png[]


The pipeline performs the following tasks for the back-end application `vote-api` and front-end application `vote-ui`:
The pipeline performs the following tasks for the back-end application `pipelines-vote-api` and front-end application `pipelines-vote-ui`:

* Clones the source code of the application from the Git repository by referring to the `git-url` and `git-revision` parameters.
* Builds the container image using the `buildah` cluster task.
Expand Down Expand Up @@ -73,8 +68,6 @@ spec:
name: buildah
kind: ClusterTask
params:
- name: TLSVERIFY
value: "false"
- name: IMAGE
value: $(params.IMAGE)
workspaces:
Expand Down
6 changes: 3 additions & 3 deletions modules/op-creating-pipeline-tasks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc

[id="creating-pipeline-tasks_{context}"]
= Creating Pipeline Tasks
= Creating pipeline tasks

[discrete]
.Procedure
Expand Down Expand Up @@ -32,7 +32,7 @@ apply-manifests 1 minute ago
update-deployment 48 seconds ago
----

. Use the `tkn clustertasks list` command to list the Operator-installed additional cluster tasks, for example, `buildah` and `s2i-python-3`:
. Use the `tkn clustertasks list` command to list the Operator-installed additional cluster tasks such as `buildah` and `s2i-python`:
+
[NOTE]
====
Expand All @@ -51,6 +51,6 @@ The output lists the Operator-installed `ClusterTask` resources:
NAME DESCRIPTION AGE
buildah 1 day ago
git-clone 1 day ago
s2i-php 1 day ago
s2i-python 1 day ago
tkn 1 day ago
----
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// *openshift_pipelines/creating-cicd-solutions-using-openshift-pipelines.adoc

[id="creating-project-and-checking-pipeline-service-account_{context}"]
= Creating a project and checking your Pipeline ServiceAccount
= Creating a project and checking your pipeline service account

[discrete]
.Procedure
Expand All @@ -24,9 +24,9 @@ $ oc new-project pipelines-tutorial
====
If you create a project with a different name, be sure to update the resource URLs used in the example with your project name.
====
. View the `pipeline` ServiceAccount:
. View the `pipeline` service account:
+
{pipelines-title} Operator adds and configures a ServiceAccount named `pipeline` that has sufficient permissions to build and push an image. This ServiceAccount is used by PipelineRun.
{pipelines-title} Operator adds and configures a service account named `pipeline` that has sufficient permissions to build and push an image. This service account is used by the `PipelineRun` object.
+
----
$ oc get serviceaccount pipeline
Expand Down
18 changes: 9 additions & 9 deletions modules/op-creating-webhooks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc

[id="creating-webhooks_{context}"]
= Creating Webhooks
= Creating webhooks

_Webhooks_ are HTTP POST messages that are received by the EventListeners whenever a configured event occurs in your repository. The event payload is then mapped to TriggerBindings, and processed by TriggerTemplates. The TriggerTemplates eventually start one or more PipelineRuns, leading to the creation and deployment of Kubernetes resources.
_Webhooks_ are HTTP POST messages that are received by the event listeners whenever a configured event occurs in your repository. The event payload is then mapped to trigger bindings, and processed by trigger templates. The trigger templates eventually start one or more pipeline runs, leading to the creation and deployment of Kubernetes resources.

In this section, you will configure a Webhook URL on your forked Git repositories `vote-ui` and `vote-api`. This URL points to the publicly accessible EventListener service route.
In this section, you will configure a webhook URL on your forked Git repositories `pipelines-vote-ui` and `pipelines-vote-api`. This URL points to the publicly accessible `EventListener` service route.

[NOTE]
====
Adding Webhooks requires administrative privileges to the repository. If you do not have administrative access to your repository, contact your system administrator for adding Webhooks.
Adding webhooks requires administrative privileges to the repository. If you do not have administrative access to your repository, contact your system administrator for adding webhooks.
====

[discrete]
.Procedure

. Get the Webhook URL:
. Get the webhook URL:
+
* For a secure HTTPS connection:
+
Expand All @@ -33,17 +33,17 @@ $ echo "URL: $(oc get route el-vote-app --template='http://{{.spec.host}}')"
+
Note the URL obtained in the output.

. Configure Webhooks manually on the front-end repository:
. Configure webhooks manually on the front-end repository:

.. Open the front-end Git repository `vote-ui` in your browser.
.. Open the front-end Git repository `pipelines-vote-ui` in your browser.
.. Click *Settings* -> *Webhooks* -> *Add Webhook*
.. On the *Webhooks/Add Webhook* page:
+
... Enter the Webhook URL from step 1 in *Payload URL* field
... Enter the webhook URL from step 1 in *Payload URL* field
... Select *application/json* for the *Content type*
... Specify the secret in the *Secret* field
... Ensure that the *Just the push event* is selected
... Select *Active*
... Click *Add Webhook*

. Repeat step 2 for the back-end repository `vote-api`.
. Repeat step 2 for the back-end repository `pipelines-vote-api`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
= Mirroring images to run pipelines in a restricted environment


To run OpenShift Pipelines in a disconnected cluster or a cluster provisioned in a restricted environment, you must ensure that either the Samples Operator is configured for a restricted network, or a cluster administrator has created a cluster with a mirrored registry.
To run OpenShift Pipelines in a disconnected cluster or a cluster provisioned in a restricted environment, ensure that either the Samples Operator is configured for a restricted network, or a cluster administrator has created a cluster with a mirrored registry.

The following procedure uses the `pipelines-tutorial` example to create a pipeline for an application in a restricted environment using a cluster with a mirrored registry. To ensure that the `pipelines-tutorial` example works in a restricted environment, you must mirror the respective builder images from the mirror registry for the front-end interface, `vote-ui`; back-end interface, `vote-api`; and the `cli`.
The following procedure uses the `pipelines-tutorial` example to create a pipeline for an application in a restricted environment using a cluster with a mirrored registry. To ensure that the `pipelines-tutorial` example works in a restricted environment, you must mirror the respective builder images from the mirror registry for the front-end interface, `pipelines-vote-ui`; back-end interface, `pipelines-vote-api`; and the `cli`.

.Procedure

. Mirror the builder image from the mirror registry for the front-end interface, `vote-ui`.
. Mirror the builder image from the mirror registry for the front-end interface, `pipelines-vote-ui`.
.. Verify that the required images tag is not imported:
+
[source,terminal]
Expand Down Expand Up @@ -77,7 +77,7 @@ latest
[...]
----

. Mirror the builder image from the mirror registry for the back-end interface, `vote-api`.
. Mirror the builder image from the mirror registry for the back-end interface, `pipelines-vote-api`.
.. Verify that the required images tag is not imported:
+
[source,terminal]
Expand Down
22 changes: 11 additions & 11 deletions modules/op-running-a-pipeline.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// // *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc

[id="running-a-pipeline_{context}"]
= Running a Pipeline
= Running a pipeline

A `PipelineRun` resource starts a pipeline and ties it to the Git and image resources that should be used for the specific invocation. It automatically creates and starts the `TaskRun` resources for each task in the pipeline.

Expand All @@ -16,9 +16,9 @@ A `PipelineRun` resource starts a pipeline and ties it to the Git and image reso
----
$ tkn pipeline start build-and-deploy \
-w name=shared-workspace,volumeClaimTemplateFile=https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/01_pipeline/03_persistent_volume_claim.yaml \
-p deployment-name=vote-api \
-p git-url=https://github.com/openshift-pipelines/vote-api.git \
-p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/vote-api
-p deployment-name=pipelines-vote-api \
-p git-url=https://github.com/openshift/pipelines-vote-api.git \
-p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/pipelines-vote-api
----
+
The previous command uses a volume claim template, which creates a persistent volume claim for the pipeline execution.
Expand All @@ -32,15 +32,15 @@ $ tkn pipelinerun logs <pipelinerun_id> -f
+
The <pipelinerun_id> in the above command is the ID for the `PipelineRun` that was returned in the output of the previous command.

. Start the Pipeline for the front-end application:
. Start the pipeline for the front-end application:
+
[source,yaml,subs="attributes+"]
----
$ tkn pipeline start build-and-deploy \
-w name=shared-workspace,volumeClaimTemplateFile=https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/01_pipeline/03_persistent_volume_claim.yaml \
-p deployment-name=vote-ui \
-p git-url=https://github.com/openshift-pipelines/vote-ui.git \
-p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/vote-ui
-p deployment-name=pipelines-vote-ui \
-p git-url=https://github.com/openshift/pipelines-vote-ui.git \
-p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/pipelines-vote-ui
----

. To track the progress of the pipeline run, enter the following command:
Expand All @@ -52,14 +52,14 @@ $ tkn pipelinerun logs <pipelinerun_id> -f
+
The <pipelinerun_id> in the above command is the ID for the `PipelineRun` that was returned in the output of the previous command.

. After a few minutes, use `tkn pipelinerun list` command to verify that the Pipeline ran successfully by listing all the PipelineRuns:
. After a few minutes, use `tkn pipelinerun list` command to verify that the pipeline ran successfully by listing all the pipeline runs:
+
[source,yaml]
----
$ tkn pipelinerun list
----
+
The output lists the PipelineRuns:
The output lists the pipeline runs:
+
[source,yaml]
----
sounix000 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -73,7 +73,7 @@ The output lists the PipelineRuns:
+
[source,yaml]
----
$ oc get route vote-ui --template='http://{{.spec.host}}'
$ oc get route pipelines-vote-ui --template='http://{{.spec.host}}'
----
Note the output of the previous command. You can access the application using this route.

Expand Down
8 changes: 4 additions & 4 deletions modules/op-triggering-a-pipelinerun.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
[id="triggering-a-pipeline_{context}"]
= Triggering a pipeline run

Whenever a `push` event occurs in the Git repository, the configured Webhook sends an event payload to the publicly exposed `EventListener` service route. The `EventListener` service of the application processes the payload, and passes it to the relevant `TriggerBinding` and `TriggerTemplate` resource pairs. The `TriggerBinding` resource extracts the parameters and the `TriggerTemplate` resource uses these parameters and specifies the way the resources must be created. This may rebuild and redeploy the application.
Whenever a `push` event occurs in the Git repository, the configured webhook sends an event payload to the publicly exposed `EventListener` service route. The `EventListener` service of the application processes the payload, and passes it to the relevant `TriggerBinding` and `TriggerTemplate` resource pairs. The `TriggerBinding` resource extracts the parameters, and the `TriggerTemplate` resource uses these parameters and specifies the way the resources must be created. This may rebuild and redeploy the application.

In this section, you push an empty commit to the front-end `vote-ui` repository, which then triggers the pipeline run.
In this section, you push an empty commit to the front-end `pipelines-vote-ui` repository, which then triggers the pipeline run.

[discrete]
.Procedure

. From the terminal, clone your forked Git repository `vote-ui`:
. From the terminal, clone your forked Git repository `pipelines-vote-ui`:
+
[source,terminal,subs="attributes+"]
----
$ git clone git@github.com:<your GitHub ID>/vote-ui.git -b {pipelines-ver}
$ git clone git@github.com:<your GitHub ID>/pipelines-vote-ui.git -b {pipelines-ver}
----
. Push an empty commit:
+
Expand Down