Skip to main content

tcb cloudrun deploy

Publish local project code or an image to a CloudBase Run service.

Usage​

tcb cloudrun deploy [options]

Parameters​

ParameterRequiredDescriptionDefault
-e, --env-id <envId>NoEnvironment ID—
-s, --serviceName <serviceName>NoService name—
--port <port>NoPort of a container-type service, ignored for function-type services—
--source <source>NoCode directory, resolved against the current directory; optional for image deploymentsProject directory
--imageUrl <imageUrl>NoImage address, for example ccr.ccs.tencentyun.com/ns/img:v1—
--createAgentNoCreate a function-type Agent and deploy the function-type services it depends onfalse
--forceNoSkip every confirmation promptfalse
--yesNoConfirm the pre-deploy prompt, useful in CI/CDfalse
--installDependency <bool>NoInstall dependencies online, true / false—
--trafficNoCanary deployment, traffic must be switched manually after publishfalse
--min-num <minNum>NoMinimum replica count, non-negative integer—
--max-num <maxNum>NoMaximum replica count, non-negative integer—
--open-access-types <types>NoAccess policy types, comma-separated: OA / PUBLIC / MINIAPP / VPC—
--vpcConfig <json>NoVPC network configuration JSON with vpcId, vpcCIDR, subnetId, subnetCIDR—
--waitNoBlock until the deployment finishes, polling every 3 seconds for up to 30 minutes; cannot be combined with --trafficfalse
--env-params <json>NoEnvironment variables as JSON (v3.8.9+), values must be strings; replaces the whole set on an existing service—
--dry-runNoValidate code loading and configuration without deployingfalse

Examples​

# Interactive deployment, the CLI asks for service and environment
tcb cloudrun deploy

# Deploy the current directory to a specific service
tcb cloudrun deploy -e env-123456 -s my-service

# Deploy a container-type service with a port
tcb cloudrun deploy -e env-123456 -s api-service --port 8080

# Deploy code from a specific directory
tcb cloudrun deploy -e env-123456 -s my-service --source ./dist

# Deploy without confirmation
tcb cloudrun deploy -e env-123456 -s my-service --force

# Deploy from an image
tcb cloudrun deploy -e env-123456 -s my-service --imageUrl ccr.ccs.tencentyun.com/ns/img:v1 --port 3000

# Deploy with a VPC configuration
tcb cloudrun deploy -e env-123456 -s my-service --vpcConfig '{"vpcId":"vpc-xxx","vpcCIDR":"10.0.0.0/16","subnetId":"subnet-xxx","subnetCIDR":"10.0.1.0/24"}'

# Wait for the deployment, useful in CI/CD
tcb cloudrun deploy -e env-123456 -s my-service --force --yes --wait

Create an Agent and deploy​

# Create a function-type Agent and deploy the services it depends on
tcb cloudrun deploy -e env-123456 --createAgent

# Create an Agent and force the deployment
tcb cloudrun deploy -e env-123456 --createAgent --force

Environment variables​

--env-params takes a JSON string whose values must be strings; {"PORT":8080} is rejected:

tcb cloudrun deploy -e env-123456 -s my-service --env-params '{"NODE_ENV":"production","REDIS_HOST":"10.0.0.10"}'

The value replaces the whole set rather than merging by key:

InputResult
--env-params '{"A":"1"}'Online variables become {"A":"1"}, every other variable is removed
--env-params omittedOnline variables stay unchanged
--env-params '{}'Online variables are cleared

To change a single variable, pass the others along. Variables are submitted with the deployment, so a change only takes effect after redeploying.

Notes​

  • Code deployment uploads a package of the --source directory and lets the platform build the image, which is pushed to the TCR Personal Edition instance under your account (Guangzhou region). The image is not kept locally and is not pushed to your own repository; to own the image, build and push it yourself and deploy with --image-url
  • Container-type services need --port, function-type services do not
  • Verify the code locally with tcb cloudrun run first
  • Sample project: nodejs_hello_world