What are the best practices for environment setup in Layer0

When I create a new site in Layer0, it generates a default environment which is also my production environment (it has the production tag next to it). I want to have multiple staging and development environments and be able to use CI/CD by simply pushing to github. What are the best practices to set up these environments?

You have the ability to create and deploy to unlimited environments on Layer0 very easily by just pushing code up to your favorite version control platform as described here: Layer0 Documentation - Deploying. This ease of deployment however means that there should be special caution and care when deploying to production.

If you have multiple people working and deploying to your site and/or have multiple environments, you want to be careful with following some best practices, especially with production.The best practices for production environments are listed below:

  • Have a designated production environment named appropriately such as production.

  • Have the access rules being used for the production environment more restricted in terms of who can deploy to it (make sure only admins can deploy to production)

  • Don’t set up CI/CD integration for production. Instead use the following workflow:

    1. Create a CI/CD integration between your version control platform and a pre-production environment in Layer0 named appropriately such as pre-production or staging
    2. Push your code up to the repo and see it being deployed to your pre-prod environment
    3. Run your full gamut of testing on the pre-prod environment.
      4a. Once ready to deploy to production, go to the Layer0 page for the latest deployment on the environment that you tested and promote it to the production environment.
      4b. Alternatively, if you want to roll it out to only a percentage of your users, you can use split testing as described here: Layer0 Documentation - Split Testing

Note: If you’re not using CI/CD integration, the same best practices of deploying to the pre-prod environment, testing there and finally promoting the deployment to production apply to your flow as well. The differences being that you want to skip to step 2 where you deploy directly to your pre-prod environment instead of having it done automatically and then follow the remaining steps.