Skip to content

Templates

One of the most frustrating parts of deployments is having steps or actions that have to be re-written or heavily modified for every single application or CI/CD pipeline. Templates solves this challenge. It helps create an internal registry of common (language-agnostic) actions that can be used across any deployment pipeline instantly.

These template could include scripts to run a Terraform plan + apply, sync an Argo CD application, or wait for a Git PR to be approved.

Templates can be stacked together like Lego blocks to build full pipelines - more on this in the pipelines page

Using the UI to Create a Template Manifest

GreenOps uses Argo Workflows templates as building blocks for pipelines. Using the UI builder in the Manifests > Create Template Manifest section, you can easily build a template.

Template Types

If it runs on your machine, it runs in a template. Users can register a Docker container, script, or Kubernetes resource as a template.

Screenshot

Script

As an example, here is a script template that creates an Amazon EKS cluster using ekctl. For scripts, users can enter a container image with: * The required tools * Container command (some common suggestions are provided in the UI, but any value can be entered) * Source which contains the script

Screenshot

Container

There are often ready-made Docker containers that simply need custom arguments to be able to execute properly, not a full script. Here is an example of a container template that uses the Kaniko image to build a custom Docker image.

For containers, users enter an executable container image, and should specify whatever custom container arguments or input variables they want.

Screenshot

Variables & Sensitive Values

Users can also add custom variables using Inputs. You can reference the input variable in a template script or container argument. The value itself can be defined in the pipeline manifest generation section. Sensitive values like access tokens are injected using Environment Variables. Environment Variables link to Kubernetes secrets, and mount them during runtime. This is great for security conscious organizations as all sensitive data will be in your clusters at all times, and won't be accessed by GreenOps. You can see an example below:

You can read more about creating secrets with sensitive values here. Keep in mind that all secrets should be in the argo namespace.

Screenshot

Outputs

Templates represent isolated execution of an action, but what happens when you want to pass a variable to a future step? For example, say a step in a workflow builds a new Docker image, and you would like to pass the image name to a future step for testing. This is where outputs come in.

Users can export strings, JSON blobs, or values to a file in the step's local environment. They can then specify where to find the file, and what name it should be exported with. The output parameter will be read from the file and passed to future steps (passing variables between steps is defined in the pipeline manifest section).

In the example below, we see the script template exporting a JSON blob to a file, and then defining the location of the file to use in an output.

Screenshot

Registering a Block Template

Templates can be registered directly from the manifest builder page.

Templates are connected to upstream Git repositories - or more specifically - a file stored in a Git repository. The template itself is stored as an Argo WorkflowTemplate. GreenOps will automatically push and fetch manifests in repos so you don't have to copy/paste files everywhere.

To create a template, follow the steps:

  1. In the templates manifest page, press the "Create" tab on the upper right corner. Fill out the fields.

    Screenshot

    Here is a quick explanation of each of the parameters:

    • Name: Name of the template.
    • Description: Description of the template.
    • Repo URL: Select one of the linked repositories.
    • File Path: This is the path root for the file that should hold the template information. For example: example/templateA.yaml.
    • Select Cluster: This section specifies which cluster the template should be synced to. In most cases, it is wherever the control GreenOps plane is located.

    Press the save button once everything is filled out. The creation process for templates may take take up to 15 seconds to complete. You should see templates appear in the the Templates tab like this:

    Screenshot

How Can Templates be Used?

It is clear how to create a template, but how does it actually help in making pipeline creation simpler? When creating pipelines through the GreenOps UI, the registered templates will automatically be picked up and will appear as drop down items for pipeline steps. Users can then pick the desired template to use for a step and enter the custom parameters. This helps with action reusability and simple customizability.

Screenshot In the example above, there are two templates that have been registered: argocd-step and github-pr. Picking either template would automatically update the parameters section (per the template specification).