How to execute CF CLI commands in a Concourse task
search cancel

How to execute CF CLI commands in a Concourse task

book

Article ID: 434700

calendar_today

Updated On:

Products

VMware Tanzu Platform - Cloud Foundry

Issue/Introduction

Operator or developer requires executing Clound Foundry CLI commands from within a Concourse task & pipeline.

Guidelines for using CF CLI executable in Concourse & Platform Automation.

Resolution

There are multiple options for executing CF CLI commands in a Concourse task - 

  • cf-cli-resource - This is a community supported resource that simplifies command execution and settings of authentication/org/space parameters. This resource is not supported by Broadcom and may be outdated.

  • cloudfoundry/cli - This is the official open-source docker image for the Cloud Foundry CLI. Dockerhub contains the latest open-source version of CLI and continues to get updates.

    Below is an example pipeline utilizing CLI docker image -

    jobs:
    - name: deploy-app
      plan:
      - get: app-code
        trigger: true
      - task: push-to-cf
        config:
          platform: linux
          image_resource:
            type: registry-image
            source:
              repository: cloudfoundry/cli
              tag: latest
          inputs:
            - name: app-code
          run:
            path: /bin/sh
            args:
              - -c
              - |
                cf api ((cf-api-url)) --skip-cert-check
                cf auth ((cf-username)) ((cf-password))
                cf target -o ((cf-org)) -s ((cf-space))
                cd app-code
                cf push APP-NAME

 

  • Build your own docker image - Create a custom image to use as a resource (as in pipeline example above) containing all the utilities that you need.

    Example dockerfile that pulls in CF CLI & OM:
    FROM ubuntu:jammy 

    RUN apt-get update -y
    RUN apt-get install jq curl wget openssh-client zip git -y

    # om cli

    RUN curl -L -O https://github.com/pivotal-cf/om/releases/download/7.12.0/om-linux-amd64-7.12.0 -k
    RUN mv om-linux-amd64-7.12.0 /usr/local/bin/om
    RUN chmod +x /usr/local/bin/om

    # cf cli

    RUN wget -O cf.tgz "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=8.7.10&source=github-rel" --no-check-certificate
    RUN tar -xzvf cf.tgz
    RUN mv cf8 /usr/local/bin/cf
    RUN chmod +x /usr/local/bin/cf