Assembling a pipeline

A Pipeline represents a CI/CD flow and is defined by the Tasks to be executed. It specifies how the Tasks interact with each other and their order of execution using the inputs , outputs, and the run-After parameters. It is designed to be generic and reusable in multiple applications and environments.

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 OpenShift:

Pipeline

Procedure

  1. Copy the contents of the following sample Pipeline YAML file and save it:

    apiVersion: tekton.dev/v1alpha1
    kind: Pipeline
    metadata:
      name: build-and-deploy
    spec:
      resources:
        - name: api-repo
          type: git
        - name: api-image
          type: image
        - name: ui-repo
          type: git
        - name: ui-image
          type: image
    
      tasks:
        - name: build-api
          taskRef:
            name: buildah
            kind: ClusterTask
          resources:
            inputs:
              - name: source
                resource: api-repo
            outputs:
              - name: image
                resource: api-image
          params:
            - name: TLSVERIFY
              value: "false"
    
        - name: apply-api-manifests
          taskRef:
            name: apply-manifests
          resources:
            inputs:
              - name: source
                resource: api-repo
          runAfter:
            - build-api
    
        - name: update-api-image
          taskRef:
            name: update-deployment
          resources:
            inputs:
              - name: image
                resource: api-image
          params:
            - name: deployment
              value: "api"
          runAfter:
            - apply-api-manifests
    
        - name: build-ui
          taskRef:
            name: s2i-python-3
            kind: ClusterTask
          resources:
            inputs:
              - name: source
                resource: ui-repo
            outputs:
              - name: image
                resource: ui-image
          params:
            - name: TLSVERIFY
              value: "false"
    
        - name: apply-ui-manifests
          taskRef:
            name: apply-manifests
          resources:
            inputs:
              - name: source
                resource: ui-repo
          runAfter:
            - build-ui
            - update-api-image
    
        - name: update-ui-image
          taskRef:
            name: update-deployment
          resources:
            inputs:
              - name: image
                resource: ui-image
          params:
            - name: deployment
              value: "ui"
          runAfter:
            - apply-ui-manifests

    This Pipeline performs the following tasks:

    • Clones the source code of the frontend application from the api-repo Git repository and the backend application from the ui-reporesource Git repository.

    • Builds the container image for the frontend using the s2i-python-3 task that generates a Dockerfile for the application using Source-to-Image (S2I).

    • Builds the container image for the backend using the buildah task that uses Buildah to build the image.

    • The application image is pushed to an image registry.

    • The new application image is deployed on OpenShift using the apply-manifests and update-deployment tasks.

      Pipeline s in Tekton are designed to be generic and re-usable across environments and stages through the applications lifecycle. They abstract away the specifics of the Git source repository and image registries to be used during Pipeline execution.

      The execution order of the tasks is determined by the dependencies defined between the tasks using the inputs and outputs parameters, and the explicit orders that are defined using runAfter.

  2. Create the Pipeline:

    $ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/pipeline/pipeline.yaml
  3. Verify that the Pipeline has been added to the application as follows:

    $ tkn pipeline ls
    NAME               AGE            LAST RUN   STARTED   DURATION   STATUS
    build-and-deploy   1 minute ago   ---        ---       ---        ---

Additional resources