Using OpenShift Pipelines

Automated builds and deployments – known as CI/CD – of container-based applications can reduce mistakes, improve productivity, and promote more thorough testing. This sandbox activity introduces OpenShift Pipelines for automated builds and deployment.

OpenShift Pipelines is added to a Red Hat OpenShift cluster by the OpenShift Pipelines operator. This operator is already installed in the Developer Sandbox. So all we need to do is create objects and run our pipelines.

Learn more about the Developer Sandbox

In the previous lesson, you started a workspace and and populated it with tasks. Now you're ready to run your pipeline and observe the results.  

In order to get full benefit from taking this lesson, you need:

  • A web browser.

In this lesson, you will:

  • Create the workspace.
  • Create its necessary tasks.

Run your pipeline

It's time to execute your pipeline. Here are the steps.

  1. Execute the following command to run the pipeline:

    ​tkn pipeline start qotd-build-and-deploy -w name=shared-workspace,claimName=source-pvc -p git-url=https://github.com/redhat-developer-demos/qotd.git -p IMAGE=image-registry.openshift-image-registry.svc:5000/<<yourworkspacename>>/qotd:latest

    Info alert: You will need to replace <<yourworkspacename>> with the name of your OpenShift Sandbox project name that you noted in the Preparing for Run the pipeline section of this activity.

  2. Here’s an example of the command that I used:

    tkn pipeline start qotd-build-and-deploy -w name=shared-workspace,claimName=source-pvc -p git-url=https://github.com/redhat-developer-demos/qotd.git -p IMAGE=image-registry.openshift-image-registry.svc:5000/rhn-engineering-dschenck-dev/qotd:latest

    Two other GitHub repos can be used in the command. You can substitute them if you wish to work with C# or Nodejs.

  3. The pipeline run will be visible in the OpenShift dashboard (Figure 4). 

    Figure 4: OpenShift Pipeline running in OpenShift dashboard.
    Figure 4: OpenShift Pipeline running in OpenShift dashboard.
  4. When you started the run at the command line, it immediately returned with a command that you can use to observe your pipeline run from the command line. The command will be very similar to the following results. In order to track the PipelineRun progress, run:

    tkn pipelinerun logs qotd-build-and-deploy-run-7wl4v -f -n rhn-engineering-dschenck-dev
  5. Paste your command into your command line and press Enter to observe the pipeline run from your command line.

You should see a fair amount of activity, while in the background, in the OpenShift dashboard, the progress is displayed at a less granular level.

View the results

  1. Run the following command to get the URL of the service:

    oc get route qotd
  2. Using the URL from the previous command, use the cURL command to get a random quote. Substituting your URL as needed, run the following command to see the results:
    1. PowerShell

      (curl <<route_URL>>/quotes/random).Content
    2. Bash

      curl <<route_URL>>/quotes/random
  3. Here are examples:

    $ oc get routes qotd
    
    NAME   HOST/PORT                                                                     PATH   SERVICES   PORT        TERMINATION   WILDCARD
    
    qotd   qotd-rhn-engineering-dschenck-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com          qotd       10000-tcp                 None

     

    $ (curl http://qotd-rhn-engineering-dschenck-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/quotes/random).Content
    ​{"id":1,"quotation":"Yeah, well, that's just like, your opinion ... man.","author":"The Dude"}

Bonus

  1. Use a cURL endless loop to view your results.
    1. PowerShell

      While($true) { $(curl http://qotd-rhn-engineering-dschenck-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/quotes/random).Content;sleep 1 }
    2. Bash

      while $true; do curl http://qotd-rhn-engineering-dschenck-dev.apps.sandbox-m2.ll9k.p1.openshiftapps.com/quotes/random; sleep 1; done;

Developer notes

  • The qotd application is written in Go.

Move it, remove it, improve it

Move

If you have another cluster, such as  a Red Hat OpenShift Service on AWS instance,  you can install the OpenShift Pipelines operator and run this activity there. If you do this, consider creating a project for this activity.

Remove

You can remove all or part of this activity by using one of the following commands:

  • To remove only the qotd app: oc delete all -l learn-pipelines=qotd
  • To remove only the pipeline: oc delete all -l learn-pipelines=pipeline
  • To remove only the task: oc delete all -l learn-pipelines-task
  • To remove only the workspace: oc delete all -l learn-pipelines=workspace
  • To remove all of the objects associated with this activity: oc delete all -l sandbox=learn-pipelines

Improve

The following are ideas to improve this activity:

  • Write your qotd app in a different language.
  • After building the app using your source code, create an endless loop using cURL at the command line to get random quotes. Next, change the source code and re-run the pipeline to see the new version implemented. This is a rolling update.
  • Add a health check to the deployment.
  • Read the quotes from the text file that is stored in a PVC.

Congratulations. Now you know the basics of OpenShift Pipelines. Ready to learn more? Try this Getting Started with OpenShift Pipelines lesson.

Previous resource
Create necessary tasks within a new workspace