Run locally
Using the local run command, you can run and debug function-based Cloud Run services in the development environment. (Container-based services are not supported.)
Basic Usage
tcb cloudrun run -e <envId>
Usage Example:
# Run in normal mode, default port 3000
tcb cloudrun run -e env-123456
# Run with a specified port
tcb cloudrun run -e env-123456 --port 8080
# Enable hot restart mode to automatically restart upon code changes
tcb cloudrun run -e env-123456 -w
# Validate whether the code can be loaded normally without actually starting up the service.
tcb cloudrun run -e env-123456 --dry-run
# Load all functions in the specified directory
tcb cloudrun run -e env-123456 --loadAllFunctions
Running in Agent Mode
tcb cloudrun run --runMode agent --agentId <agentId> -e <envId>
Usage Example:
# Run Agent mode for debugging
tcb cloudrun run --runMode agent --agentId ibot-agent-xxx -e env-123456
# Agent mode with hot restart
tcb cloudrun run --runMode agent --agentId ibot-agent-xxx -e env-123456 -w
# Agent mode specify port
tcb cloudrun run --runMode agent --agentId ibot-agent-xxx -e env-123456 --port 8080
Command Line Parameters
| Parameter | Description | Required |
|---|---|---|
-e, --env-id | Environment ID | Yes |
--runMode | Run mode, optional values: normal (regular function), agent (functional Agent), default is normal | No |
--agentId | Agent ID, must be provided in agent mode | Required in agent mode |
--port | Listening port, defaults to 3000 | No |
-w, --watch | Enable hot restart mode, automatically restart the service when files change | No |
--dry-run | Only verify that the code can be loaded normally without actually starting up the service | No |
--logDirname | Log file directory, defaults to ./logs | No |
--functionsConfigFile | Multi-function definition configuration file path, defaults to ./cloudbase-functions.json | No |
--loadAllFunctions | Load all functions in the functionsRoot directory | No |
--extendedContext | JSON string used to parse context.extendedContext, e.g. '{"a":1,"b":2}' | No |
--open-debug-panel | Whether to open the debug panel, default true | No |
-h, --help | Display command help information | No |
Environment Variable Configuration
Create a .env.local file in the project root directory (note that the filename starts with a dot), and configure environment variables in the format KEY=VALUE:
# .env.local
API_KEY=your_api_key123
DATABASE_URL=mysql://localhost:3306/db
Precautions
- Only supports function-based Cloud Run services, does not support container-based services
- When using the
-wparameter, code changes automatically trigger service restarts, facilitating development and debugging - Before using Agent mode, you must create an Agent and obtain the Agent ID
- Environment variable configuration only takes effect during local runtime; after deployment, it must be configured in the console
- For more function examples, refer to: Function Examples