2.6. Publish Customizations to Cloud
In the previous chapters, you added a brands feature to your Medusa application and tested it locally. In this chapter, you'll publish your customizations to Cloud, so that you can use them in your deployed Medusa application.
How Publishing to Cloud Works#
Your Cloud project is connected to a GitHub repository, with environments connected to its branches. When you push changes to the branch of an environment, Cloud builds and deploys them to that environment. During the deployment, Cloud also runs your migrations on the environment's database, such as the migrations of the Brand Module.
To avoid breaking a live environment, test your changes in a preview environment first. Cloud creates a preview environment when you open a pull request to the branch of any environment, such as Production or Staging. Each preview environment has its own database, so testing in it doesn't affect the target environment's data.
Step 1: Add Environment Variables to Cloud#
The CMS Module that you created in the Integrate Systems chapter uses the CMS_API_KEY environment variable. Since your .env file isn't pushed to the repository, you must add the variable to your Cloud environment before you deploy.
Add the variable in two places:
- Preview environments: In your project's dashboard, click Preview Settings in the sidebar, and add the variable in the environment variables section. Preview environments created afterward inherit it. Learn more in the Preview Environments guide.
- Target environment: In the dashboard of the environment you're publishing to, such as Production, click Environment variables in the sidebar, then add the variable and click Save. Each environment has its own variables, so repeat this for every environment you publish to.
In both places, enable the variable's Build toggle, since medusa-config.ts reads it during the build. Learn more in the Environment Variables Cloud guide.
Step 2: Push Changes and Open a Pull Request#
Next, create a new branch in your local Medusa application and commit your changes:
git checkout -b feat/brands
git add .
git commit -m "Add brands feature"
git push origin feat/brands
Then, on GitHub, open a pull request from the feat/brands branch to the target environment's branch, such as your production branch.
Cloud creates a preview environment for the pull request and deploys your changes to it. Medusa also posts a comment on the pull request with the preview deployment's status and links to the preview environment. You can also follow the deployment's progress in the Deployments page of your project's dashboard.
Step 3: Test Changes in the Preview Environment#
Once the deployment is live, test the brands feature in the preview environment:
- Open the preview environment's Medusa Admin from the link in Medusa's comment on the pull request. You can also find its URL as explained in the Preview Environments guide.
- Log in with the Log in with Medusa Cloud button.
- Click Brands in the sidebar to open the UI route you created in the Customize Admin chapter, and check that it lists brands.
- Open a product's details page, and check that the brand widget you created in the Customize Admin chapter shows the product's brand.
Step 4: Merge Changes to the Target Environment#
After you test your changes, merge the pull request into the target environment's branch. Cloud deploys the changes to that environment and runs the migrations on its database.
For example, if you merged into your production branch, your production store now includes the brands feature. Learn more about how Cloud deploys your changes in the Deployments guide.