Skip to content

controlplane-com/circle-ci-pipeline-example-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Control Plane - CircleCI Pipeline Example Using the CLI

This example demonstrates building and deploying an app to Control Plane using the CLI (cpln) as part of a CI/CD pipeline at CircleCI.

The example is a Node.js app that displays the environment variables and start-up arguments.

This example is provided as a starting point and your own unique delivery and/or deployment requirements will dictate the steps needed in your situation.

Control Plane Authentication Set Up

The Control Plane CLI require a Service Account with the proper permissions to perform actions against the Control Plane API.

  1. Follow the Control Plane documentation to create a Service Account and create a key. Take a note of the key. It will be used in the next section.
  2. Add the Service Account to the superusers group. Once the pipeline executes as expected, a policy can be created with a limited set of permissions and the Service Account can be removed from the superusers group.

Example Set Up

When triggered, the pipeline will execute the jobs/workflows defined in the .circleci/config.yml file. The example will containerize and push the application to the org's private image repository and create/update a GVC and workload hosted at Control Plane. Any commits to the repository will trigger the pipeline.

Perform the following steps to set up the example:

  1. Fork or copy the example into your own workspace at one of the supported CircleCI repositories.

  2. Connect CircleCI to your workspace and set up the example as a project in CircleCI.

  3. The following variables are required and must be added as environment variables at CircleCI:

    Browse to the environment variables page by:

    • Clicking Projects (left menu bar), then
    • Click the three dots (...) to the right of the current project and click Project Settings,
    • Click Environment Variables (left menu bar).

    Add the following variables:

    • CPLN_ORG: Control Plane org.
    • CPLN_GVC_NAME: The name of the GVC.
    • CPLN_WORKLOAD_NAME: The name of the workload.
    • CPLN_TOKEN Service Account Key from the previous section (masked).
    • CPLN_IMAGE_NAME: The name of the image that will be deployed. The pipeline will append the short SHA of the commit as the tag when pushing the image to the org's private image repository.
  4. Review the .circleci/config.yml file:

    • This file contains the jobs and workflows that CircleCI will execute when the pipeline is triggered.
    • The build-and-deploy job will install the Control Plane CLI, containerize and deploy the sample application.
    • There are two workflows defined in the example to demonstrate pushing to a stage and production environment. Each workflow calls the build-and-deploy job with the environment parameter set to the value that will be appended to the GVC name based on the branch that triggered the pipeline. The deploy-to-prod workflow is manually triggered.
    • The sed command is used to substitute the ORG_NAME, GVC_NAME, WORKLOAD_NAME and IMAGE_NAME_TAG tokens inside the YAML files in the /cpln directory on lines 38-41.
  5. The Control Plane YAML files are located in the /cpln directory. No changes are required to execute the example.

    • The cpln-gvc.yaml file defines the GVC to be created/updated.
    • The cpln-workload.yaml file defines the workload to be created/updated.
  6. Run the pipeline by:

    • Committing a change to one of the branches, or
    • Clicking Projects in the left menu, then
    • Click click the current project name and select a branch from the pulldown,
    • Click the Run Pipeline button. A modal will be displayed, click Run Pipeline.

Running the App

After the pipeline has successfully deployed the application, it can be tested by following these steps:

  1. Browse to the Control Plane Console.
  2. Select the GVC that was set in the CPLN_GVC_NAME(-ENVIRONMENT) variable.
  3. Select the workload that was set in the CPLN_WORKLOAD_NAME variable.
  4. Click the Open button. The app will open in a new tab. The container's environment variables and start up arguments will be displayed.

Notes

  • The cpln apply command creates and updates the resources defined within the YAML files. If the name of a resource is changed, cpln apply will create a new resource. Any orphaned resources will need to be manually deleted.

  • The Control Plane CLI commands use the CPLN_ORG and CPLN_TOKEN environment variables when needed. There is no need to add the --org or --token flags.

  • The GVC definition must exists in its own YAML file. The cpln apply command executing the file that contains the GVC definition must be executed before any child definition YAML files (workloads, identities, etc.) are executed.

Helper Links

CircleCI

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published