www/apps/cloud/app/environments/long-lived/page.mdx
import { InlineIcon, getOsShortcut, Kbd } from "docs-ui" import { EllipsisHorizontal, ChevronUpDown } from "@medusajs/icons"
export const metadata = {
title: Long-Lived Environments,
}
In this guide, you'll learn about long-lived environments in Cloud and how to manage them.
Long-lived environments are stable environments that you create for specific branches in your GitHub repository, such as Production or Staging. They allow you to test changes in a production-like environment before deploying them to the live application.
<Note>Learn more about what environments are and their types in the Environments guide.
</Note>Production and long-lived environments are stable and scalable, making them ideal for hosting your Medusa applications. Medusa ensures that they're:
It's recommended to create long-lived environments for different stages of your project's development.
For example, you can create a Staging environment to test new features and updates before deploying them to Production. That way, you can test changes in a production-like environment without affecting the live application.
This section explains how to create a long-lived environment in Cloud.
A long-lived environment is associated with a specific branch in your GitHub repository. So, before creating an environment, make sure you have the necessary branch for it in your repository.
For example, if you're creating a Staging environment, create and push a staging branch in your repository:
git checkout -b staging # create branch
git push origin staging # push branch to remote
To create a long-lived environment:
<Note title="Tip">You can also navigate to the environment creation form from the command palette. Press <Kbd>{getOsShortcut()}</Kbd> + <Kbd>K</Kbd>, select Create Environment, then choose a project.
</Note>Staging.staging.
medusajs.app, and their storefront is a subdomain of medusajs.site.
The created environment will appear in the project's dashboard as a card.
After creating the environment, Medusa will automatically trigger a deployment for the environment using the associated branch (for example, staging). This includes:
After that, Medusa will automatically deploy the environment whenever you push a new commit to the associated branch.
After the environment is deployed, you can log in to the Medusa Admin either with:
Refer to the Access Deployment guide for troubleshooting steps.
</Note>You can set the initial admin user's email and password only once if they aren't already set in the environment. Updating these environment variables later won't change the existing admin user's credentials.
To set the initial admin user's email and password:
[email protected]
USER_INITIAL_PASSWORD=secret
You can paste the above variables directly in the Key field and both environment variables will be filled.
</Note>Make sure to replace the values with your desired email and password.
If you added the initial admin user's email and password environment variables, you need to redeploy the environment for the changes to take effect:
This will redeploy the environment's live deployment with the new admin user credentials.
Then, wait for the deployment to finish. You can check its status in the "Deployments" section. Once it's deployed, you can access the environment using its URL.
Once an environment is deployed, you can access it through its URL.
Learn more about how to access an environment's deployment in the Access Deployment guide.
On the environment's dashboard, you can view its details, logs, and settings. You can also manage the environment's variables, deployment rules, and database dump.
To open an environment's dashboard:
This will open the environment's dashboard. You can see the environment's name at the top of the Cloud dashboard.
On the environment's dashboard, you can find the following details:
Aside from the subdomain you set when creating the environment, Medusa also provides a unique, randomly generated URL for each environment. Both of these URLs point to the same deployment.
</Note>The environment's name at the top of the dashboard is also an environment switcher.
To switch to a different environment:
This will change the view to the selected environment, and you'll see its details, logs, and settings.
You can view build and runtime logs for an environment in the "Logs" section of the environment's dashboard. These logs help you debug issues in your Medusa application and storefront.
Learn more in the Logs guide.
You can monitor the performance of your environment in the "Monitoring" section of the environment's dashboard. This includes monitoring HTTP requests, background jobs, and more.
Learn more in the Monitoring guide.
In the environment's "Settings" tab, you can manage the environment variables for the environment's Medusa application and storefront. Environment variables are key-value pairs that store sensitive information, such as API keys, or configurations that your application needs to run.
Learn how to manage environment variables in the Environment Variables guide.
Your long-lived environment has two types of domains:
medusajs.app (backend) and medusajs.site (storefront) subdomains assigned to the environment. For example, acme.medusajs.app and acme.medusajs.site.acme.com.To update these domains, see the Subdomains and Custom Domains guides.
You can't change the branch of preview environments. This section only applies to long-lived environments, such as Production or Staging.
</Note>In an environment's "Settings" tab, you can manage the deployment rules for the environment. Deployment rules allow you to control how and when deployments are triggered for the environment.
To change the branch associated with an environment using deployment rules:
branch rule.Changes will take effect the next time you push a commit to the new branch. The environment will be redeployed with the latest changes from the new branch.
In the environment's "Settings" tab, you can export a database dump of the environment. This is useful for backing up the environment's data, debugging issues, or migrating the data to another environment.
You can also import a database dump to use existing data that you have, or to restore the environment to a previous state.
Learn more in the Database guide.
Deleting an environment will delete all its resources and settings, including its database and environment variables. This action is irreversible. You won't be able to recover any data after deletion.
</Note>You can delete any environment in your project, except for the Production environment.
To delete an environment: