Skip to main content

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

ParameterDescriptionRequired
-e, --env-idEnvironment IDYes
--runModeRun mode, optional values: normal (regular function), agent (functional Agent), default is normalNo
--agentIdAgent ID, must be provided in agent modeRequired in agent mode
--portListening port, defaults to 3000No
-w, --watchEnable hot restart mode, automatically restart the service when files changeNo
--dry-runOnly verify that the code can be loaded normally without actually starting up the serviceNo
--logDirnameLog file directory, defaults to ./logsNo
--functionsConfigFileMulti-function definition configuration file path, defaults to ./cloudbase-functions.jsonNo
--loadAllFunctionsLoad all functions in the functionsRoot directoryNo
--extendedContextJSON string used to parse context.extendedContext, e.g. '{"a":1,"b":2}'No
--open-debug-panelWhether to open the debug panel, default trueNo
-h, --helpDisplay command help informationNo

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 -w parameter, 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