DEV Community

Cover image for Release Automation through Parallel Codefresh Pipelines
Katherine Lin
Katherine Lin

Posted on

Release Automation through Parallel Codefresh Pipelines

In this post, we’ll explore how to improve your CI/CD workflow by promoting release automation using parallel Codefresh pipelines. This process includes defining custom variables, integrating approval stages, and running tasks in infradev and staging pipelines in parallel. With Codefresh’s flexibility, we can drastically reduce deployment time while maintaining a high level of control.

By the end of this guide, you will have a solid foundation to create scalable, parallel pipelines for your projects.

Let’s dive in! 💻✨


What We’ll Cover

  1. What is Codefresh?
  2. Why Parallel Pipelines?
  3. Setting Up the Infradev Pipeline
  4. Configuring Staging Pipeline
  5. Using Variables in Pipelines
  6. Adding Stage Approvals
  7. Putting It All Together

What is Codefresh?

Codefresh is a modern CI/CD tool built for cloud-native applications. It supports container-based pipelines with a highly scalable and flexible architecture.

In this guide, we’ll leverage Codefresh’s parallel pipeline capability to run an Infradev pipeline and a Staging pipeline simultaneously, configure custom variables for flexibility, and include approval stages to ensure that releases are thoroughly reviewed.


Why Parallel Pipelines?

Parallel pipelines help reduce bottlenecks in your release process by allowing different stages of your pipeline to run at the same time.

  • Faster Feedback Loops: Parallel pipelines decrease overall build time, providing quicker feedback on deployments.
  • Stage Isolation: Run Infradev and Staging pipelines in isolation to ensure environment-specific configurations without causing interference.
  • Custom Approvals: Control which stages need manual intervention and which can proceed automatically, offering a balance between automation and manual oversight.

Setting Up the Infradev Pipeline

The Infradev pipeline is designed to deploy infrastructure components or perform infrastructure validation.

1. Define Pipeline Stages

In Codefresh, you’ll need to define multiple stages for different tasks such as infrastructure provisioning, validation, and security checks.

Here’s a simple YAML configuration to define the Infradev pipeline:

version: '1.0'
stages:
  - "Provision Infrastructure"
  - "Run Security Scans"
  - "Validate Resources"
steps:
  provision_infra:
    title: "Provisioning Infrastructure"
    image: 'hashicorp/terraform'
    commands:
      - terraform init
      - terraform apply
  run_security_scan:
    title: "Running Security Scan"
    image: 'aquasec/trivy'
    commands:
      - trivy filesystem --severity HIGH --exit-code 1 .
  validate_resources:
    title: "Validating Resources"
    image: 'python:3.8'
    commands:
      - python validate_resources.py
Enter fullscreen mode Exit fullscreen mode

Each stage performs a key function, ensuring that the infrastructure is provisioned, security-compliant, and ready for further operations.


Configuring Staging Pipeline

While Infradev handles infrastructure, the Staging pipeline focuses on deploying the application to a staging environment for final validation before production.

2. Staging Pipeline Definition

Here's an example of a Staging pipeline that runs tests, deploys the application, and performs end-to-end tests:

Plain textANTLR4BashCC#CSSCoffeeScriptCMakeDartDjangoDockerEJSErlangGitGoGraphQLGroovyHTMLJavaJavaScriptJSONJSXKotlinLaTeXLessLuaMakefileMarkdownMATLABMarkupObjective-CPerlPHPPowerShell.propertiesProtocol BuffersPythonRRubySass (Sass)Sass (Scss)SchemeSQLShellSwiftSVGTSXTypeScriptWebAssemblyYAMLXMLyamlCopy codeversion: '1.0' stages: - "Run Unit Tests" - "Deploy to Staging" - "Run End-to-End Tests" steps: run_tests: title: "Running Unit Tests" image: 'node:14' commands: - npm install - npm run test deploy_staging: title: "Deploying to Staging" image: 'alpine/kubectl' commands: - kubectl apply -f deployment.yaml run_e2e_tests: title: "Running E2E Tests" image: 'cypress/included:8.3.1' commands: - npm run cypress:run

Both pipelines can be configured to run in parallel, cutting down deployment time significantly.

Using Variables in Pipelines

Variables in Codefresh pipelines provide flexibility and reusability. You can define variables at different levels – pipeline, stage, or globally – and pass them between steps.

3. Defining Variables

In our pipelines, we’ll use variables to handle configuration, environment names, or credentials dynamically.

Plain textANTLR4BashCC#CSSCoffeeScriptCMakeDartDjangoDockerEJSErlangGitGoGraphQLGroovyHTMLJavaJavaScriptJSONJSXKotlinLaTeXLessLuaMakefileMarkdownMATLABMarkupObjective-CPerlPHPPowerShell.propertiesProtocol BuffersPythonRRubySass (Sass)Sass (Scss)SchemeSQLShellSwiftSVGTSXTypeScriptWebAssemblyYAMLXMLyamlCopy codevariables: ENVIRONMENT: "staging" APP_NAME: "my-app" IMAGE_TAG: "v1.0.0"

By defining variables, we can avoid hardcoding values and easily change configurations when needed, such as switching from staging to production.

Adding Stage Approvals

Codefresh allows you to set manual approval gates between stages to ensure that critical steps get human oversight before proceeding to the next stage.

4. Adding Approval Gates

To add an approval step between the staging deployment and the production pipeline, include the manual-approval step in your pipeline:

Plain textANTLR4BashCC#CSSCoffeeScriptCMakeDartDjangoDockerEJSErlangGitGoGraphQLGroovyHTMLJavaJavaScriptJSONJSXKotlinLaTeXLessLuaMakefileMarkdownMATLABMarkupObjective-CPerlPHPPowerShell.propertiesProtocol BuffersPythonRRubySass (Sass)Sass (Scss)SchemeSQLShellSwiftSVGTSXTypeScriptWebAssemblyYAMLXMLyamlCopy codesteps: manual_approval: type: "manual" title: "Approval Required" description: "Approve deployment to Production" on_success: next_step: deploy_production

With this step in place, you can pause the pipeline at critical points, requiring a team member to manually review and approve the deployment.

Putting It All Together

Now that we’ve set up both pipelines, defined variables, and added approval stages, here’s how it all fits together in Codefresh:

  1. Parallel Pipelines: Run the Infradev and Staging pipelines simultaneously to improve efficiency.

  2. Variables: Use configurable variables to keep the pipelines dynamic and reusable.

  3. Approval Stages: Add approval gates at key points to ensure that releases are carefully reviewed before moving forward.

This configuration offers a highly flexible and efficient workflow for deploying infrastructure and applications with proper safeguards in place.

Final Thoughts

By implementing parallel pipelines, custom variables, and manual approvals in Codefresh, you can automate your CI/CD process while maintaining control over critical deployments. This setup ensures high availability and efficient workflow across environments like infradev and staging.

If you have any questions or need further clarification, feel free to ask in the comments! 🚀

Related Resources:

  • Codefresh Documentation

  • Terraform Documentation

  • Kubernetes Documentation

Top comments (0)