local Command - Medusa Cloud CLI Reference
In this guide, you'll learn how to reproduce a Cloud build on your machine using the CLI. This is useful for debugging build failures without pushing changes and waiting for a Cloud deployment.
local build#
Run a Cloud build on your machine, mirroring how Cloud builds your project. Run the command from within your project.
By default, the command builds the backend. Pass --type storefront to build the storefront instead.
The CLI infers the project's root path and environment variables from the linked Cloud project and environment, so it reproduces the Cloud build as closely as possible.
The command streams the build progress to your terminal. It prepares a build directory, generates a Dockerfile that mirrors the Cloud build, then builds the Docker image. The output looks similar to the following:
❯Running local backend build in /tmp/mcloud-local-build/myuser-my-repo/backend❯Generating Dockerfile❯#1 [internal] load build definition from Dockerfile❯#1 transferring dockerfile: 2.34kB done❯#1 DONE 0.0s❯ ❯# ... Docker build output for each layer ...❯ ❯#24 exporting to image❯#24 exporting layers done❯#24 writing image sha256:0a1b2c3d4e5f done❯#24 naming to docker.io/library/my-repo:cloud-local-build-a1b2c3d done❯#24 DONE 1.2s
If the build succeeds, the resulting image is tagged . If it fails, the command exits with the failing command's error so you can debug it the same way you would a Cloud build.
Override Environment Variables#
To build with a local .env file instead of the Cloud environment's variables, or to override specific variables, use --env-file or --var:
Build the Storefront#
To build the storefront instead of the backend, pass --type storefront (or -t storefront). The CLI infers the storefront's path from the linked Cloud project, or you can set it with --storefront-path:
The command builds the storefront in a Docker container and writes the build output to a local directory. When it finishes, it prints the output path:
Options#
Option | Description | Required | Default |
|---|---|---|---|
| The ID of the organization that the project belongs to. | No | Falls back to the organization in the active context, if set. |
| The ID or handle of the project to build. | No | Falls back to the project in the active context, if set. |
| The handle of the environment whose variables are used for the build. | No | Falls back to the environment in the active context, if set. |
| The build type to run. Accepts | No |
|
| The root path of the Medusa project relative to the repository root. Used for backend builds. Inferred from the Cloud project if not specified, or | No | Inferred |
| The path to the storefront project relative to the repository root. Used for storefront builds. Inferred from the Cloud project if not specified. | No | Inferred |
| Path to a | No | Inferred |
| An environment variable to override for the build, in | No | - |
| Enable the Docker build cache. Disabled by default so that environment variable changes always invalidate the cache. | No |
|