Using Peak Resources
To create images, workflows or services via the Command Line Interface (CLI), we can define a YAML file or pass the required options through command line arguments. This YAML file includes the payload, metadata, and configuration of the image. By utilizing jinja syntax, we have the ability to pass parameter value as {{value}}
, with the actual value being specified in a separate YAML file.
Tenants
The
tenants
resource provides required funtions/commands to Manage tenant settings and quota.The
tenants
resource currently offers only one operation namelylist-instance-options
. The command helps in getting the allowed instance type options for a giventenant
andentity-type
. Here’s how the command can be used:To obtain a list of all available instances along with their corresponding
instanceTypeId
forworkflows
, we can use the following command:peak tenants list-instance-options --entity-type workflow
To obtain a list of all available instances along with their corresponding
instanceTypeId
forwebapps
, we can use the following command:peak tenants list-instance-options --entity-type webapp
Allowed values for the
entity-type
option areapi-deployment
,data-bridge
,webapp
,workflow
,workspace
.
Defining Parameters in Resource Creation
While creating resources, we can define parameters in a separate file and then use them in the actual file. We can refer the parameters by enclosing the parameter names in {{ }}
and specifying the file path after the -v
flag in the command. We can also add parameters by adding the desired key-value pair after the -p
flag. If we specify both -v
and -p
, the parameters defined on the command line will overwrite the parameters defined in the file.
Consider the following parameters file:
# params.yaml
git_token: "random_git_token"
npm_token: "random_npm_token"
Consider the simple yaml file where we want to use the parameters defined in the above file:
# image.yaml
body:
name: upload-image
version: 0.0.1-test
description: Creating a new upload type image
type: workflow
buildDetails:
source: upload
useCache: false
buildArguments:
- name: git_token
value: {{ git_token }}
- name: npm_token
value: {{ npm_token }}
context: "."
artifact:
path: "."
ignore_files:
- ".gitignore"
- ".dockerignore"
We can use the following command to create an image:
peak images create -v path/to/params.yaml path/to/image.yaml
In the above example, the {{ git_token }}
and {{ npm_token }}
will be replaced by the values defined in the params.yaml
file.
We can also add parameters by adding the desired key-value pair after the -p
flag. If we specify both -v
and -p
, the parameters defined on the command line will overwrite the parameters defined in the file.
peak images create path/to/image.yaml -p git_token=git_token_value -p npm_token=npm_token_value
Similar approach can be used for creating other resources as well.
Using a combination of command line options and yaml
For creating resources such as images and services, we can use a combination of command line options and the yaml
. In this case the command line options will take precedence over the yaml values.
Consider the following example for creating a service:
# service_params.yaml
imageId: 2
versionId: 2
# service.yaml
body:
name: my-service
title: New Service
description: A new service
serviceType: web-app
imageDetails:
imageId: {{ imageId }}
versionId: {{ versionId }}
peak services create -v path/to/service_params.yaml <service-id> path/to/service.yaml --image-id 3
In the above example, the imageId
will be overwritten by the command line options and the final service body will look like:
{
"name": "my-service",
"title": "New Service",
"description": "A new service",
"serviceType": "web-app",
"imageDetails": {
"imageId": 3,
"versionId": 2
}
}
Creating Resource Dependencies with Artifacts
If we want to create a resource such as image, but we don’t want it to be source directly from the source code repository, then we will need to pack all the files we might need to build the image and pack them into an zip
archive which is called Artifact
.
More information for Artifact
can be found in Artifact and Compression Doc.