Execution
This section details how to configure your Blocklet's execution environment. You can define the runtime engine, specify lifecycle scripts that run at key moments, and declare necessary environment variables. Blocklet Server uses these configurations to install, start, and manage your application.
Blocklets can be executed either directly on the host system using the engine
property or within an isolated Docker container via the docker
configuration.
Runtime Engine (engine
)#
The engine
field specifies the command used to start your Blocklet. This is the primary method for running Blocklets that don't require containerization. It can be a simple string for basic commands or a more detailed object for complex setups.
Property | Type | Description |
---|---|---|
|
| Optional. Specifies the target OS. Valid values: |
|
| The interpreter to use. Valid values: |
|
| The engine source. Can be a string (e.g., |
|
| An array of arguments to pass to the engine. Defaults to |
Examples
A simple Node.js application:
engine: 'node dist/index.js'
A more explicit configuration using an object:
engine:
interpreter: 'node'
source: 'dist/index.js'
args: ['--port', '3000']
Docker Container (docker
)#
For greater isolation and consistency, you can run your Blocklet inside a Docker container. If the docker
field is present, the engine
field is ignored.
Property | Type | Description |
---|---|---|
|
| The name of the Docker image to use (e.g., |
|
| The path to a |
Examples
Using a pre-built image from Docker Hub:
docker:
image: 'arcblock/arc-bridge-node:latest'
Using a local Dockerfile:
docker:
dockerfile: 'Dockerfile'
# The 'Dockerfile' in your project root will be bundled and used.
files:
- Dockerfile
Lifecycle Scripts (scripts
)#
The scripts
field allows you to define commands that are executed at specific points in the Blocklet's lifecycle. These are useful for tasks like database migrations, dependency setup, or cleanup.
The following diagram illustrates when these scripts are executed:
Available Hooks
Hook | Description |
---|---|
| Command to run for local development. |
| Runs before any installation or update steps. |
| Runs before the Blocklet is installed. |
| Runs after the Blocklet is successfully installed. |
| Runs before the main |
| Runs after the main process has successfully started. |
| Runs before the Blocklet is stopped. |
| Runs before the Blocklet is uninstalled. |
| Runs before the configuration interface is shown to the user. |
Example
scripts:
preInstall: 'npm install --production'
postInstall: 'node ./db-migrate.js'
preStart: 'echo "Starting Blocklet..."'
Environment Variables (environments
)#
Define a list of environment variables your Blocklet needs to run. The Blocklet Server will prompt the user to provide values for these variables during installation and configuration. These values are then injected into the Blocklet's execution environment.
Property | Type | Description |
---|---|---|
|
| Required. The name of the environment variable (e.g., |
|
| Required. A user-friendly description of what this variable is for, which will be shown in the UI. |
|
| An optional default value for the variable. Cannot be used when |
|
| If |
|
| If |
|
| An optional regex string to validate the user's input. |
|
| If |
Example
environments:
- name: 'API_ENDPOINT'
description: 'The API endpoint for the external service.'
required: true
default: 'https://api.example.com/v1'
validation: '^https?://.*'
- name: 'API_SECRET_KEY'
description: 'The secret key for accessing the external API.'
required: true
secure: true
Timeouts (timeout
)#
You can configure timeouts for specific operations to prevent your Blocklet from getting stuck during startup or script execution.
Property | Type | Description |
---|---|---|
|
| The time in seconds that Blocklet Server waits for the Blocklet to start before considering it failed. Range: 10-600. Default: 60. |
|
| The maximum time in seconds that any lifecycle script is allowed to run before being terminated. Range: 1-1800. |
Example
timeout:
start: 120 # Allow 2 minutes for the blocklet to start
script: 300 # Allow 5 minutes for any script to run
You now have a complete understanding of how to configure your Blocklet's execution behavior. By combining engine
or docker
with scripts
and environments
, you can create robust and configurable applications.
After setting up how your Blocklet runs, the next step is to define how it communicates with the outside world. Proceed to the Networking section to learn about configuring interfaces, ports, and public URLs.