Using Press Build Parameters

Let’s say you are creating a workflow block, and want to keep a couple of parameters configurable - values that can be changed by business users at deployment time, to allow the workflow configuration to more accurately reflect their specific usecase, without you as the developer needing to produce multiple nearly-identical iterations of your spec. Press build parameters are meant for this specific usecase. Here’s how you can use them.

Using Build Parameters in Workflows

Creating the Block Spec

When creating the block spec, you will need to make the required parts of the config customizable. Here’s an example spec that contains a parameterized config, and the corresponding parameter objects that describe the metadata of each parameter. We will parameterize the instanceTypeId,storage and watcher["user"] fields, to allow for a slightly different processing power and storage for the test step, and a different target for workflow success/fail events. These would be common things that different users might want to vary, obviously much more could be done here. We have also added options for the instance type parameter.

# block_spec.yaml.j2

body:
    version: 1
    kind: workflow
    metadata:
        name: workflow-block
        title: Workflow Block
        summary: Workflow Block
        description: Creating a new workflow block spec
        descriptionContentType: text/markdown
        imageUrl: https://my-block-pics.com/image-0.jpg
        tags:
            - name: CLI
    release:
        version: 1.0.0
        notes: This is the original release
    config:
        steps:
            test:
                command: echo 1
                resources:
                    instanceTypeId: "@param:instance_type"
                    storage: "@param:storage"
                type: standard
                image:
                    context: "."
                    dockerfile: Dockerfile
                    version: 0.0.1
                    buildArguments:
                        API_KEY: {{ api_key }}
        triggers:
            - cron: "0 0 * * *"
        watchers: "@param:watchers"
parameters:
    build:
        - defaultValue: 21
          description: Computational power to allow for the test step
          name: instance_type
          options:
              - title: regular
                value: 21
              - title: large
                value: 23
          required: false
          title: Instance Type
          type: number
        - defaultValue: 10GB
          description: The storage for the test step
          name: storage
          required: false
          title: Storage
          type: string
        - description: Specify workflow watchers. Events along with one of User, Webhook, Email is to be provided in a single watcher object.
          name: watchers
          title: Watchers
          required: false
          type: object_array
          defaultValue:
                -   user: "user1@peak.ai"
                    events:
                        success: true
                        fail: true
                -   webhook:
                        name: info
                        url: https://abc.com/post
                        payload: |
                            {
                                "system": "external_system",
                                "action": "update",
                                "data": {
                                    "field": "value",
                                    "timestamp": "2024-05-20T12:00:00Z"
                                }
                            }
                    events:
                        success: true
                        fail: true
                -   email:
                        name: "email-watcher-1"
                        recipients:
                            to:
                                - user1@peak.ai
                                - user2@peak.ai
                    events:
                        success: true
                        fail: true
                        runtimeExceeded: 1
          properties:
              - name: user
                type: string
                title: User
                description: Email to send workflow success/fail events to
                required: false
              - name: webhook
                type: object
                title: Webhook
                description: Webhook to send workflow events to
                required: false
                properties:
                    - name: url
                      type: string
                      title: URL
                      description: Webhook URL
                      required: true
                    - name: name
                      type: string
                      title: Name
                      description: Webhook name
                      required: true
                    - name: payload
                      type: string
                      title: Payload
                      description: Webhook payload
                      required: false
              - name: email
                type: object
                title: Email
                description: Email to send workflow events to
                required: false
                properties:
                    - name: name
                      type: string
                      title: Name
                      description: Email watcher name
                      required: true
                    - name: recipients
                      type: object
                      title: Recipients
                      description: Email recipients
                      required: true
                      properties:
                          - name: to
                            type: string_array
                            title: To
                            description: Email recipients
                            required: true
              - name: events
                type: object
                title: Events
                description: Specify workflow watchers
                required: true
                properties:
                    - name: success
                      type: boolean
                      title: Success
                      description: Notify on success
                      required: false
                    - name: fail
                      type: boolean
                      title: Fail
                      description: Notify on failure
                      required: false
                    - name: runtimeExceeded
                      type: number
                      title: Runtime Exceeded
                      description: Notify after runtime exceeded
                      required: false
artifact:
    path: "."
    ignore_files:
        - ".gitignore"
        - ".dockerignore"
featured: true
scope: shared
tenants:
    - tenant1
    - tenant2

Create the spec using the following statement

peak blocks specs create path/to/block_spec.yaml.j2 -p API_KEY=<API_KEY>

Deploying the Spec

With the Block Spec ready, we can now create the deployment for the same. To create a deployment, we first need to create a config file for the same

# block_deployment.yaml.j2

body:
    metadata:
        name: workflow-block-deployment
        title: Workflow Block Deployment
        summary: Workflow Block Deployment
        description: Creating a new workflow block deployment
        descriptionContentType: text/markdown
        imageUrl: https://my-block-pics.com/image-0.jpg
        tags:
            - name: CLI
    parameters:
        build:
            instance_type: 23
            storage: 20GB
            watchers:
                - user: "someuser@peak.ai"
                  events:
                      success: false
                      fail: true
                - webhook:
                      name: info
                      url: https://abc.com/post
                      payload: |
                          {
                              "system": "external_system",
                              "action": "update",
                              "data": {
                              "field": "value",
                              "timestamp": "2024-05-20T12:00:00Z"
                              }
                          }
                  events:
                      success: false
                      fail: true
                - email:
                      name: "email-watcher-1"
                      recipients:
                          to:
                              - user1@peak.ai
                              - user2@peak.ai
                  events:
                      success: false
                      fail: true
                      runtimeExceeded: 1

    revision:
        notes: This is the initial revision
    spec:
        id: 0bddb4c6-40c5-45c3-b477-fceb2c051609
        release:
            version: 1.0.0

We can then create the deployment using the following statement

peak blocks deployments create path/to/block_deployment.yaml.j2

The result

This will create the deployment, replacing the spec config section’s parameterized values with the provided deployment build parameter values, like so:

config:
    steps:
        test:
            command: echo 1
            resources:
                instanceTypeId: 23
                storage: 20GB
            type: standard
            image:
                context: "."
                dockerfile: Dockerfile
                version: 0.0.1
                buildArguments:
                    API_KEY: {{ api_key }}
    triggers:
        - cron: "0 0 * * *"
    watchers:
        - user: "someuser@peak.ai"
          events:
              success: false
              fail: true
        - webhook:
              name: info
              url: https://abc.com/post
              payload: |
                  {
                      "system": "external_system",
                      "action": "update",
                      "data": {
                          "field": "value",
                          "timestamp": "2024-05-20T12:00:00Z"
                      }
                  }
          events:
              success: false
              fail: true
        - email:
              name: "email-watcher-1"
              recipients:
                  to:
                      - user1@peak.ai
                      - user2@peak.ai
          events:
              success: false
              fail: true
              runtimeExceeded: 1