DEV Community

Michael Di Prisco
Michael Di Prisco

Posted on

Build, release, run - The Twelve Factor App Methodology

Welcome back to our exploration of the Twelve Factors in Software Development. In this installment, we'll delve into Factor 5: Build, Release, Run. This factor focuses on establishing a clear separation between the processes of building, releasing, and running your application.

Build, Release, Run: Define Clear Boundaries

The Build, Release, Run factor emphasizes the need for distinct and well-defined stages in your application's lifecycle: the build stage, where the code is compiled and packaged (Creating a build); the release stage, where the application is combined with its configuration to create a deployable artifact; and the run stage, where the application is executed.

Why It Matters

By separating these stages, you gain several advantages. It becomes easier to track changes, maintain consistency across environments, and automate deployment processes. Each stage has its responsibilities, enabling a more organized and efficient development pipeline.

How to Implement

Use a build tool to compile your code and package it into a deployable artifact. Popular choices include Maven for Java, Gradle for various languages, and Vite for web applications. Also, a concatenation of FROM instructions inside a Dockerfile can do the job.

The release stage combines the built artifact with configuration settings to create a release that can be deployed to different environments.

Finally, the run stage executes the application with its specific configuration.

Example in Action

Let's consider a Node.js application. During the build stage, you might compile TypeScript code into JavaScript and package it. In the release stage, you configure environment variables and package the application for deployment. The run stage executes the application using these settings.

# Build stage (using TypeScript and npm)
npm run build

# Release stage (setting environment variables)
export NODE_ENV=production

# Run stage (executing the application)
node dist/app.js
Enter fullscreen mode Exit fullscreen mode

P.S. Many people are lately arguing about the usage of the NODE_ENV variable because of the Express legacy, but keep in mind I used it just as an example.

By following the Build, Release, Run factor, you establish a structured workflow that simplifies development, testing, and deployment processes.

Stay tuned for Factor 6: Processes, where we'll explore the importance of executing the application as one or more stateless processes and delve into the benefits of process isolation.

Top comments (0)