Skip to main content

Assets Library

Introduction

The library provides ways to import templates, software and static asset files for exec or render operations.

Sources

https://github.com/milaboratory/platforma/blob/main/sdk/workflow-tengo/src/assets.lib.tengo

API

Import

assets := import("@platforma-sdk/workflow-tengo:assets")

importTemplate

Returns an internal template identifier for loaded templates. It then can be passed to render library for creating an actual template.

Arguments:

  • tplName: string - full name of a template, including namespace (package name).

Local templates (within the same package) can omit namespace part and start the name with colon:

  • "@company/package:someTemplateName"
  • ":myLocalTemplate"

Return:

  • template: smart.resource - resource of tengo template with given name.

Example:

render.create(assets.importTemplate(":myLocalTemplate"), {
argument1: 11,
argument2: 31,
nested: [{a: 1, b: 2}],
smartResourceOrField: resource1
})

importSoftware

Returns software description suitable for exec library operations.

Arguments:

  • swName: string - full name of the software entrypoint, including namespace (NPM package name).

Local software entrypoints (within the same package) can omit namespace part and start the name with colon:

  • "@company/package:some-oftware"
  • ":my-local-software"

Return:

  • softwareInfo: softwareInfo - structure with software info.

Example:

mixcrSw := assets.importSoftware("@platforma-open/milaboratories.software-mixcr:main")

mixcrForBackCmd := exec.builder().
software(mixcrSw).
secret("MI_LICENSE", "MI_LICENSE").
printErrStreamToStdout().
arg("presetSpecificationsForBack").
addFile("preset.yaml", aFile).
arg("preset.yaml").
arg("presetForBack.json").
saveFileContent("presetForBack.json").
run()

isSoftwareInfo

Checks if given item is a software info.

Arguments:

  • toCheck: any - item to check

Return:

importAsset

Returns asset description suitable for exec library operations.

Asset is the way to put static files into working directory before execution of the command. It can be used with addAsset() builder method.

Arguments:

  • assetName: string - full name of asset entrypoint, including namespace (NPM package name).

Local software entrypoints (within the same package) can omit namespace part and start the name with colon:

  • "@company/package:some-asset"
  • ":my-local-asset"

Example:

asset := assets.importAsset("@platforma-open/milaboratories.software-small-binaries:small-asset")

// here we unpack file2.txt into a root of the working directory.
run := exec.builder().
addAsset(asset, ".", ["file2.txt"]).
cmd("/usr/bin/env").
arg("cat").
arg("file2.txt").
saveStdoutContent().
run()

isAssetInfo

Checks if given item is an asset info.

Arguments:

  • toCheck: any - item to check

Return:

  • isAsset: boolean - true for asset info, loaded with importAsset()