Accelerate your Backstage development and testing with on-demand ephemeral environments
Backstage is an open-source developer portal designed to streamline and automate the software development process. Developed by Spotify, Backstage provides a unified interface for managing software projects, tools, and infrastructure. By consolidating various development tasks and services into a single platform, Backstage helps developers efficiently navigate and interact with their software ecosystem, reducing context-switching and improving productivity. The platform supports a plugin-based architecture, allowing developers to extend its functionality and customize it to fit their organization's specific needs. We will look at how B Backstage development can be sped up with the help of ephemeral environments.
Ephemeral environments are temporary, on-demand instances of an application or service that can be spun up quickly for development, testing, and collaboration purposes. They play a crucial role in the Backstage development process by enabling developers to work in isolated environments, minimizing the risk of conflicts and ensuring a consistent development experience.
In the context of Backstage, ephemeral environments can be used to develop and test plugins, as well as the platform itself, without affecting the main development or production instances. These environments allow developers to experiment with new features and validate their changes before merging them into the main codebase. Additionally, they facilitate collaboration by providing shareable instances for team members to review, debug, and test together, ensuring a smooth integration process.The following are a few specific ways of using the ephemeral environments:
You can learn more about the life of an entity here and about Backstage’s incremental entity provider over here.
You can learn more about software templates here.
Now that we understand how ephemeral environments can be helpful, let’s see how we can get started with building them for your Backstage development.
Uffizzi runs on top of Kubernetes but the end user doesn’t have to bother with all that. If the application has a preconfigured Dockerfile and docker-compose ready to go with it then configuring Uffizzi is going to be straightforward. If your application doesn’t already have a Dockerfile and/or a docker-compose config we will be discussing a little bit about that in this blog, but these two configurations are prerequisites for Uffizzi.
To learn more about Uffizzi ephemeral environments check out the documentation here.
We are going to use this Backstage sample repository to understand what it means to develop a sample Backstage application.The repository contains two different ways of spinning up a Uffizzi instance for a backstage application:
Let’s explore each of the two ways of setting up Uffizzi for your Backstage development method.
The following is the directory structure of this sample application with the relevant files and directories for this guide:
Project directory structure
The backstage backend service will be built into a container image which is used to create the backstage container. The builds for both these images need to be mentioned in the uffizzi-build.yml configuration file which can be seen in the build-backstage job. The image tag is built and pushed from here are then referenced in the Uffizzi Compose using the ${BACKSTAGE_IMAGE} placeholder. To understand more on how this can be done, check out this blog which will guide you through extending Github Actions with Uffizzi. We will not be going through how to set up the uffizzi-build.yml and uffizzi-preview.yml in this blogpost.
A backstage application created from the `npm @backstage/create-app` initially needs a more straightforward setup. We will be discussing what the setup for such a backstage application looks like in this case. We will discuss the architecture and the workflow definition to create the ephemeral environments below.
We are extending the reusable Github Action workflow for Uffizzi. The reusable workflow here, can be extended to work in a two stage mode to allow contributors to create pull requests and consume ephemeral environments without needing credentials or accounts on Uffizzi if they are new uses on Uffizzi itself.
The workflow in this case is divided between the build and deploy part where the build part is executed in context of the pull request branch to build the relevant image. The deploy part of the repo runs in context of the main repo. It is triggered when the build is completed. If you are interested in the motivation and working of the two stage workflow, this blog post dives deeper in the same. Let’s look at the triggers for each to understand their relationship, let’s take meilisearch as an example where this has been implemented:
https://github.com/UffizziCloud/backstage-ephemeral-environments
https://github.com/UffizziCloud/backstage-ephemeral-environments
In the above excerpts from the two stage workflow files we can see that there is a natural trigger for the uffizzi-build.yml. The build workflow is triggered when a pull request is opened or updated. In the uffizzi-preview-deploy.yml we can see that the workflow is triggered only when the first workflow completes.
The deploy phase of the workflow works as follows :
https://github.com/UffizziCloud/backstage-ephemeral-environments
Here we are using OIDC tokens provided by Github to secure the identity of the contributors. Hence, providing ease of use and security in one package. Meanwhile, workflows scoped to the default branch of the base repository are the only ones able to authenticate with Uffizzi. To learn more about the two stage workflow, check this blog post here.
The Backstage project itself uses Uffizzi for speeding up its development with Ephemeral instances. The team primarily uses the ephemeral instances as preview environments. Considering that we have already seen how the two stage workflow works above, we are going to see how we can set up a Backstage fork for an enterprise with a one stage workflow to restrict the ephemeral environment creation access to internal developers.
Let’s start with an example fork of Backstage. The only difference between the original Backstage and this fork is the Uffizzi workflow being used. The origin backstage repo is using Uffizzi’s two stage workflow, if you want to learn more about the different Uffizzi github action workflows, check out this blog. Considering the nature of the backstage project, they need contributors to be able to see previews of Backstage as well. The two stage workflow helps well with that. But if you are developing on Backstage directly for your internal needs, you should use Uffizzi’s one stage github actions workflow. This workflow makes sure that a contributor without the right permissions won’t be able to get Uffizzi previews.
The difference between the two different workflows is that there is no context change between the build stage and the deploy stage. The build and deploy steps happen in the same stage, hence it is called the one stage workflow. You can see the excerpt definition of the workflow below :
https://github.com/UffizziCloud/backstage-fork
In the above workflow the following two jobs are running:
To set up your backstage fork with Uffizzi, you have to copy the above workflow to your repo and that’s how straightforward it is to get started with Uffizzi.
After doing the basic setup of creating a workflow for Ephemeral Environments for your Backstage, you can think about how you can start sharing or leveraging the Uffizzi URL for your Backstage instance in the following ways:
Once you have figured out how to share the Uffizzi URL for the ephemeral environment instance for your Backstage, you can go further and improve your ephemeral environmet experience by adding customizations like the one below:
Uffizzi environments are used by the core Backstage team. Considering that it is currently being used by Spotify for Backstage we keep improving the Uffizzi experience for all Backstage contributors and see to it that we are able to provide the best experience for Backstage developers. Check out the blogpost Substantial increase in Development Velocity because of Uffizzi which has statistics and analysis on Backstage’s increased productivity after integrating Uffizzi into their workflows and how adopting Uffizzi increased Backstage’s development velocity by more than 20%.
If you have a Backstage project for which you would like to build ephemeral environments for and discuss the different ways you can use them to better fit your needs, we look forward to speaking with you. You can get in touch with us by going to https://www.uffizzi.com/contact and we will reach out to you !
Visit docs.uffizzi.com for more information on ephemeral environments. Visit backstage.io for further guides on Backstage development.