Execution & Environment
This section of the blocklet.yml
file defines how a blocklet runs, its dependencies on the underlying system, and how it can be configured at runtime. Properly configuring these fields is essential for ensuring your blocklet is reliable, portable, and easy for users to manage.
Key areas of configuration include:
engine
: Specifies the runtime interpreter or binary used to execute the blocklet.docker
: Defines settings for running the blocklet as a Docker container.requirements
: Lists the system-level dependencies, such as ABT Node version, OS, and CPU architecture.environments
: Declares environment variables that the blocklet uses for configuration.scripts
: Defines lifecycle hooks that run at different stages, such as installation or startup.timeout
: Sets time limits for startup and script execution to prevent hangs.
engine
#
The engine
field specifies how the blocklet's code should be executed. It can be a single object or an array of objects to support multiple platforms.
Property | Type | Description |
---|---|---|
|
| Optional. Specifies the target OS platform (e.g., |
|
| The runtime to use. Can be |
|
| Specifies where to find the engine's code. Can be an empty string (to use the |
|
| Optional. An array of command-line arguments to pass to the interpreter. Defaults to |
Example: Basic Node.js Engine
This configuration uses the node
interpreter and points to the main
field for the entry file.
name: my-node-app
version: 1.0.0
main: 'dist/server.js'
engine:
interpreter: 'node'
source: ''
Example: Platform-Specific Binaries
This example provides different binaries for macOS (darwin
) and Linux.
engine:
- platform: darwin
interpreter: binary
source: ./bin/my-app-mac
- platform: linux
interpreter: binary
source: ./bin/my-app-linux
Example: Using another Blocklet as an Engine
This delegates execution to another blocklet, fetched from a specified store. This is common for static site generators or other reusable runtimes.
engine:
interpreter: blocklet
source:
store: https://store.arcblock.io/api
name: '@blocklet/page-engine'
version: ^1.18.0
docker
#
For blocklets that are distributed as Docker containers, the docker
field provides the necessary configuration. This field is mutually exclusive with engine
and main
.
Property | Type | Description |
---|---|---|
|
| The name of the Docker image (e.g., |
|
| The path to the Dockerfile within the blocklet bundle. Required if |
|
| The Docker network mode. |
Example: Using a Public Docker Image
did: z8iZq23838o3a8o3a8o3a8o3a8o3a8o3a8o3a
description: A blocklet running Nginx from a public image.
version: 1.0.0
docker:
image: nginx:latest
interfaces:
- type: web
name: publicUrl
path: /
protocol: http
port: 80
Note: If you specify a dockerfile
, you must also include it in the files
array to ensure it's included in the blocklet bundle.
requirements
#
This object specifies the minimum system requirements needed to install and run the blocklet, preventing installation on incompatible environments.
Property | Type | Description |
---|---|---|
|
| A valid SemVer range for the required ABT Node version. |
|
| A valid SemVer range for the required Blocklet Server version. Defaults to the latest stable version. |
|
| The compatible operating system(s) (e.g., |
|
| The compatible CPU architecture(s) (e.g., |
|
| A valid SemVer range for the required Node.js version. |
|
| An array of objects specifying required on-chain assets (tokens). |
Example: Specifying System Requirements
requirements:
abtnode: ">=1.18.0"
server: ">=1.16.29"
os: "linux"
cpu: ["x64", "arm64"]
nodejs: ">=18.0.0 <21.0.0"
environments
#
This array defines the environment variables that the blocklet requires for configuration. These are presented to the user during installation and can be updated later.
Property | Type | Description |
---|---|---|
|
| The variable name. Must be a valid variable name and cannot start with |
|
| A human-readable description of what the variable is for. Required. |
|
| A default value for the variable. Cannot be used if |
|
| Whether the user must provide a value. Defaults to |
|
| If true, the value is treated as a secret and is not displayed in the UI after being set. Defaults to |
|
| A regex string to validate the user's input. |
|
| If true, this variable can be shared among components. Defaults to |
Example: Defining Environment Variables
environments:
- name: "API_ENDPOINT"
description: "The URL of the external API to connect to."
required: true
default: "https://api.example.com/v1"
validation: "^https?://.*"
- name: "API_SECRET_KEY"
description: "A secret key for authenticating with the API."
required: true
secure: true
- name: "LOG_LEVEL"
description: "Set the application log level."
default: "info"
validation: "^(info|warn|error|debug)$"
scripts
#
Scripts define commands that are executed at specific points in the blocklet's lifecycle.
Hook | Execution Point |
---|---|
| Before installation or upgrade, used for preliminary checks. |
| Before the blocklet's dependencies are installed. |
| After the blocklet's dependencies are installed. |
| Before the blocklet's main process is started. |
| After the blocklet's main process has successfully started. |
| Before the blocklet's main process is stopped. |
| Before the blocklet is uninstalled. |
| Before the blocklet's configuration is updated. |
Example: Database Migration Script
This example runs a database migration script before the application starts.
scripts:
preStart: "node ./scripts/migrate-database.js"
postInstall: "npm run build"
timeout
#
This object configures time limits for potentially long-running operations to prevent the blocklet from getting stuck.
Property | Type | Description |
---|---|---|
|
| The maximum time in seconds to wait for the blocklet to start successfully. Min: 10, Max: 600. Defaults to |
|
| The maximum time in seconds to allow any lifecycle script to run. Min: 1, Max: 1800. |
Example: Setting Custom Timeouts
timeout:
start: 180 # 3 minutes for a slow startup process
script: 900 # 15 minutes for a long build script
This section provides the foundation for running your blocklet. For details on how to expose it to the web, see the Interfaces & Services documentation.