DEV Community

Cover image for Accelerate CI/CD with Ephemeral Environments
Pavan Belagatti
Pavan Belagatti

Posted on • Originally published at harness.io

Accelerate CI/CD with Ephemeral Environments

The world of DevOps today is characterized by exciting new approaches and tools revolving around developer experience and productivity. Gone are the days when manual testing and deployment used to take days to complete. These new tools automate and streamline the software development pipeline. Typically, whenever any application is created, it’s entered into a continuous integration (CI) tool or platform that tests the code through various frameworks. If the tests are passed, the code will be deployed.

However, increasing velocity is difficult if your processes and tools are tedious and complex to configure. That’s why ease of use is non-negotiable for every developer evaluating any new tool. Developers like a CI tool that’s not only easy to set up but can also scale to test their applications. Configuring infrastructure and other related tasks is daunting and time-consuming, taking resources away from deployments.

This is where a concept called ephemeral environments comes in. Ephemeral environments can be used to test your applications much faster by spinning up short-lived environment instances and automatically destroyed after the work is done. This tutorial will discuss ephemeral environments, how they work, and how to configure them.

What are Ephemeral Environments?

Ephemeral environments are an excellent way for engineering and development teams to collaborate and test new features quickly and efficiently. They provide a temporary, isolated environment for running tests and previewing features without worrying about making any permanent changes that may impact production systems. This allows for rapid iteration and development without committing to long-term changes.
ephemeral environments main image

Configuring an ephemeral environment allows you to customize the environment to meet specific needs and preferences, such as the preferred operating system, number of servers, or type of memory and storage. Once the environment is set up, you can utilize that environment to run tests and experiments on your application.

Running an application in an ephemeral environment is relatively simple. All of the necessary files and configurations will be packaged into a single deployable artifact. This can then be deployed to the ephemeral environment and quickly spun up, allowing for rapid application development and testing.

The process is usually automated, allowing for continuous deployments and the environment to be easily rolled back if necessary. Additionally, the process can be configured to run certain tests or other checks before the deployment is finalized. This helps ensure that the application runs as expected and is free of errors or issues.

Advantages of Ephemeral Environments

Overall, ephemeral environments provide a robust, on-demand platform for quickly testing and previewing new features. Let’s dive into some of their distinct advantages over traditional static or shared staging environments.

Asynchronous Collaboration

Ephemeral environments make it easier for teams to collaborate asynchronously. This is especially useful when teams are distributed across different time zones. Setting up an ephemeral environment allows teams to share their work and collaborate on projects without having to work at the same time. They are also commonly used for previewing features as teams can quickly spin up a new environment to test out new ideas without affecting existing services.

Cost Effective

Ephemeral environments are cost-effective, simple to set up, and can be destroyed and recreated when needed, making them an excellent choice for teams collaborating across multiple projects. They give the developers temporary environments that can be efficiently utilized to test and experiment and destroy after the experiment is finished. Developers don’t need to worry about adding additional costs by running resources directly from their cloud providers.

Agile and Flexible

The ephemeral environment is far more agile and flexible than conventional environments, allowing developers to quickly spin up an instance of their application with the exact specifications they need. This makes it easier to deploy and test changes without waiting for a new application version to be built and deployed. Additionally, ephemeral environments allow teams to quickly scale up their applications to meet the demands of their users and reduce operational costs by automatically shutting down instances that are no longer needed. Finally, ephemeral environments also provide increased security and reliability, as they are entirely isolated from other instances and automatically destroyed after a specific period.

Create Ephemeral Environments Using Harness

Harness is a modern continuous delivery platform helping various organizations with their DevOps journey.

With Harness, you can setup and configure ephemeral environments automatically. With just a click of a button, you will be presented with an environment to utilize. Harness offers hosted virtual machines (VMs) to run your builds, so you can test and build your code without worrying about setting up anything. Harness can provide the infrastructure, so you can focus on developing great software.

First, sign up for the Harness free account, create a project, and select the CI module.

project creation

Harness CI module

Click on Get Started to create your pipeline.
first pipeline

Connect your code repository.
select your repo

(I am using this Simple-Node-App repository. You can fork the same and use it in this tutorial. It has a simple test case.)

By default, the pipeline is configured for you with a simple Echo Welcome Message in the execution step.
Harness pipeline studio

If you click on the Echo Welcome Message step, you will see the configuration.
echo message

Now you have your ephemeral environment to test our application.

If you click on the Infrastructure tab, you can see the options: VMs and Kubernetes.

We will select 'Cloud' as our choice for our infrastructure to test and build our application.

Harness cloud

You can click continue and save the pipeline.

When you save and execute this pipeline, you will see the output that prints Welcome to Harness CI.
print message demo

You can edit the pipeline to add the ‘run test’ step under execution. We will see how a run step can be configured using the ephemeral environment.

Add a step and select the ‘Run’ step.
run step

build

Configure the Run step as below,
configure run step

At this point, your pipeline looks like this:
Harness execution stage

Now, save and run the pipeline. You can see that both - the default Echo Welcome Message and the newly added Run Test steps are successfully getting executed.
Harness pipeline successful

We can now make use of multiple environments to add more tests and to experiment with our application.

Build and Test Faster with Ephemeral Environments

Organizations need to find ways to speed up the software deployment process in order to compete in today’s highly competitive software market, and doing so involves making developers' lives easier by providing them with the necessary tools and knowledge. Using ephemeral environments is a best practice to ensure your applications are tested and deployed at speed without worrying about the underlying infrastructure and its setup. When executing a pipeline on Harness, your builds run on VMs that contain the required settings, so you can start building and testing your applications in no time.

Also, take a look at my other tutorial, where I showed a complete CI/CD setup from the scratch.

Top comments (0)