mcloud-local
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCloud CLI: Local Command
Cloud CLI:本地命令
Execute to run a Cloud build on the local machine, mirroring how Cloud builds the project. Use it to debug deployments without pushing changes and waiting for a full Cloud build.
mcloud local buildbuild-failed执行在本地机器上运行Cloud构建,复刻Cloud构建项目的方式。无需推送变更并等待完整的Cloud构建,即可用它来调试标记为的部署问题。
mcloud local buildbuild-failedConstraints
限制条件
- No flag.
--jsonstreams plaintext build output and signals the result through its exit code (local build= success). Do not parse its output as JSON.0 - Requires Docker installed and running, and must run from inside the project's Git repository.
- Reproduces (build) failures only — not
build-failed(runtime) failures. For runtime failures, usedeployment-failed.mcloud logs --deployment <id> - Available since mcloud CLI v0.1.10.
- The Docker build cache is disabled by default so variable changes always invalidate the cache; pass to enable it.
--docker-cache
- 不支持参数。
--json会输出纯文本构建日志,并通过退出码(local build表示成功)标识结果。请勿将其输出解析为JSON格式。0 - 需要安装并运行Docker,且必须在项目的Git仓库内执行命令。
- 仅能重现(构建阶段)的失败,无法重现
build-failed(运行阶段)的失败。针对运行阶段失败,请使用deployment-failed命令。mcloud logs --deployment <id> - 从mcloud CLI v0.1.10版本开始提供此功能。
- Docker构建缓存默认处于禁用状态,因此变量变更总会使缓存失效;可传入参数启用缓存。
--docker-cache
Command
命令
local build
local build
Run a Cloud build locally. Infers the root path and build variables from the linked Cloud project and environment. Builds the backend by default; pass for the storefront.
--type storefrontbash
mcloud local build \
--organization <org-id> \
--project <project-id-or-handle> \
--environment <environment-handle>Options:
- — Organization ID (falls back to active context)
-o/--organization <id> - — Project ID or handle (falls back to active context)
-p/--project <id-or-handle> - — Environment whose variables are used (falls back to active context)
-e/--environment <handle> - — Build type (default:
-t/--type <backend|storefront>)backend - — Backend root path relative to the repo root (inferred if omitted;
--root-path <path>if no Cloud project found). - — Storefront path relative to the repo root, for
--storefront-path <path>(inferred if omitted)--type storefront - — Use a local
--env-file <path>file instead of the Cloud environment's variables.env - — Override a single build variable; repeatable
-v/--var <KEY=VALUE> - — Enable the Docker build cache (default:
--docker-cache)false
Output:
- On success (exit ), the backend image is tagged
0; a storefront build writes its output directory and prints the path.<repository-name>:cloud-local-build-<commit-hash> - On failure (non-zero exit), the command exits with the failing step's error — debug it as you would a Cloud build.
在本地运行Cloud构建。从关联的Cloud项目和环境中自动推断根路径和构建变量。默认构建后端;若需构建前端商城,传入参数。
--type storefrontbash
mcloud local build \
--organization <org-id> \
--project <project-id-or-handle> \
--environment <environment-handle>选项:
- —— 组织ID(若未指定,回退到当前活跃上下文)
-o/--organization <id> - —— 项目ID或标识(若未指定,回退到当前活跃上下文)
-p/--project <id-or-handle> - —— 使用其变量的环境(若未指定,回退到当前活跃上下文)
-e/--environment <handle> - —— 构建类型(默认值:
-t/--type <backend|storefront>)backend - —— 相对于仓库根目录的后端根路径(若省略则自动推断;若未找到Cloud项目则默认为
--root-path <path>). - —— 相对于仓库根目录的前端商城路径,仅当使用
--storefront-path <path>时生效(若省略则自动推断)--type storefront - —— 使用本地
--env-file <path>文件替代Cloud环境的变量.env - —— 覆盖单个构建变量;可重复使用该参数
-v/--var <KEY=VALUE> - —— 启用Docker构建缓存(默认值:
--docker-cache)false
输出:
- 成功时(退出码),后端镜像会被标记为
0;前端商城构建会生成输出目录并打印其路径。<repository-name>:cloud-local-build-<commit-hash> - 失败时(非零退出码),命令会伴随失败步骤的错误退出;可像调试Cloud构建一样排查问题。
Reproduce a Build Failure
重现构建失败场景
Check out the same commit the failed deployment built so the local build matches, then route on the exit code:
bash
undefined检出失败部署所基于的提交版本,确保本地构建与云端一致,然后根据退出码进行排查:
bash
undefinedIdentify the failing deployment and the commit it built
识别失败的部署及其所基于的提交版本
DEPLOYMENT_ID=$(
mcloud deployments list --json
| jq -r '[.[] | select(.backend_status == "build-failed")][0].id' ) COMMIT=$(mcloud deployments get "$DEPLOYMENT_ID" --json | jq -r '.commit_hash')
| jq -r '[.[] | select(.backend_status == "build-failed")][0].id' ) COMMIT=$(mcloud deployments get "$DEPLOYMENT_ID" --json | jq -r '.commit_hash')
git checkout "$COMMIT"
if mcloud local build; then
echo "Build succeeded locally; failure not reproducible from this commit."
else
echo "Build failed locally; inspect the streamed output for the failing step."
fi
Once the local build exits `0`, push the fix to the tracked branch and start a fresh Cloud build with `mcloud environments trigger-build <env>`.DEPLOYMENT_ID=$(
mcloud deployments list --json
| jq -r '[.[] | select(.backend_status == "build-failed")][0].id' ) COMMIT=$(mcloud deployments get "$DEPLOYMENT_ID" --json | jq -r '.commit_hash')
| jq -r '[.[] | select(.backend_status == "build-failed")][0].id' ) COMMIT=$(mcloud deployments get "$DEPLOYMENT_ID" --json | jq -r '.commit_hash')
git checkout "$COMMIT"
if mcloud local build; then
echo "本地构建成功;此提交版本无法重现失败场景。"
else
echo "本地构建失败;查看输出日志定位失败步骤。"
fi
当本地构建退出码为`0`后,将修复内容推送到跟踪分支,并使用`mcloud environments trigger-build <env>`启动全新的Cloud构建。Examples
示例
bash
undefinedbash
undefinedReproduce the backend build for the active context
重现当前活跃上下文的后端构建
mcloud local build
mcloud local build
Reproduce the storefront build
重现前端商城构建
mcloud local build --type storefront --storefront-path apps/storefront
mcloud local build --type storefront --storefront-path apps/storefront
Test a build-variable fix without editing code
无需修改代码即可测试构建变量的修复效果
mcloud local build --var NODE_ENV=production
mcloud local build --var NODE_ENV=production
Build against a local .env file
基于本地.env文件进行构建
mcloud local build --env-file .env
mcloud local build --env-file .env
Reuse the Docker cache for a faster rebuild
复用Docker缓存以加快重建速度
mcloud local build --docker-cache
undefinedmcloud local build --docker-cache
undefined