mcloud-local

作者: medusajs

执行mcloud本地构建,在本地机器上复现Cloud构建。用于在不推送到跟踪分支的情况下调试构建失败的部署,…

npx skills add https://github.com/medusajs/medusa-agent-skills --skill mcloud-local

Cloud CLI: Local Command

Execute mcloud local build to run a Cloud build on the local machine, mirroring how Cloud builds the project. Use it to debug build-failed deployments without pushing changes and waiting for a full Cloud build.

Constraints

  • No --json flag. local build streams plaintext build output and signals the result through its exit code (0 = success). Do not parse its output as JSON.
  • Requires Docker installed and running, and must run from inside the project's Git repository.
  • Reproduces build-failed (build) failures only — not deployment-failed (runtime) failures. For runtime failures, use 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 --docker-cache to enable it.

Command

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 --type storefront for the storefront.

mcloud local build \
  --organization <org-id> \
  --project <project-id-or-handle> \
  --environment <environment-handle>

Options:

  • -o/--organization <id> — Organization ID (falls back to active context)
  • -p/--project <id-or-handle> — Project ID or handle (falls back to active context)
  • -e/--environment <handle> — Environment whose variables are used (falls back to active context)
  • -t/--type <backend|storefront> — Build type (default: backend)
  • --root-path <path> — Backend root path relative to the repo root (inferred if omitted; . if no Cloud project found)
  • --storefront-path <path> — Storefront path relative to the repo root, for --type storefront (inferred if omitted)
  • --env-file <path> — Use a local .env file instead of the Cloud environment's variables
  • -v/--var <KEY=VALUE> — Override a single build variable; repeatable
  • --docker-cache — Enable the Docker build cache (default: false)

Output:

  • On success (exit 0), the backend image is tagged <repository-name>:cloud-local-build-<commit-hash>; a storefront build writes its output directory and prints the path.
  • On failure (non-zero exit), the command exits with the failing step's error — debug it as you would a Cloud build.

Reproduce a Build Failure

Check out the same commit the failed deployment built so the local build matches, then route on the exit code:

# Identify 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')

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>.

Examples

# Reproduce the backend build for the active context
mcloud local build

# Reproduce the storefront build
mcloud local build --type storefront --storefront-path apps/storefront

# Test a build-variable fix without editing code
mcloud local build --var NODE_ENV=production

# Build against a local .env file
mcloud local build --env-file .env

# Reuse the Docker cache for a faster rebuild
mcloud local build --docker-cache

来自 medusajs 的更多技能

creating-agents-in-medusa
medusajs
在Medusa项目中构建面向内部管理员的AI代理时使用。这些代理由商家和店铺运营者操作,而非客户。涵盖…
reviewing-prs
medusajs
审查Medusa仓库的GitHub拉取请求。检查PR模板合规性、贡献指南、代码规范、安全性、性能以及……
writing-releases
medusajs
为Medusa版本编写符合既定风格的GitHub发布说明。在需要根据提交和PR列表生成草稿发布描述时使用…
writing-tsdocs
medusajs
为Medusa代码库中的TypeScript源文件添加和更新TypeDoc(TSDoc)注释。涵盖HTTP类型、API路由、UI组件、数据模型、服务……
mcloud-variables
medusajs
执行mcloud变量命令,列出并获取云环境的环境变量。用于检查、读取或导出环境…
mcloud-deployments
medusajs
执行mcloud deployments命令以列出部署、获取部署详情和拉取构建日志。在列出部署、检查部署时使用…
writing-docs
medusajs
编写并更新Medusa文档的MDX文件,涵盖book、resources、ui、user-guide和cloud项目。当基于……进行文档更改时使用。
building-storefronts
medusajs
以SDK为先的前端集成方案,适用于Medusa商店前端,采用React Query模式并遵循关键API调用规则。所有API请求必须使用Medusa JS SDK——禁止使用常规fetch(),因其缺少必要请求头(商店路由需可发布API密钥,管理路由需认证信息)。向SDK方法传递纯JavaScript对象,切勿对请求体参数使用JSON.stringify(),SDK会自动处理序列化。GET请求使用useQuery,POST/DELETE请求使用useMutation,...