Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 25, 2025

This PR implements support for selecting build infrastructure profiles at the individual CI pipeline level, addressing the feature request for more granular control over build resources.

Problem

Previously, build infrastructure profiles could only be assigned at the application level, meaning all CI pipelines within an application shared the same build resources. This limited flexibility for scenarios where:

  • Production pipelines need different infrastructure than development pipelines
  • Different build types (e.g., with security scanning vs fast builds) require specific resource configurations
  • Cost optimization requires tailored infrastructure per pipeline type

Solution

Added pipeline-level build infrastructure profile selection with the following priority hierarchy:

  1. Pipeline-level profile (highest priority - new feature)
  2. Application-level profile (existing fallback)
  3. Global profile (default fallback)

Key Changes

Database Schema

  • Added infra_profile_id column to ci_pipeline table with foreign key constraint
  • Includes proper migration and rollback scripts

API Extensions

  • Extended CI pipeline DTOs to include optional infraProfileId field
  • Both create and update operations support infra profile assignment
  • Maintains backward compatibility - field is optional

Resolution Logic

  • Enhanced workflow scope construction to include PipelineId
  • Modified infra profile service to prioritize pipeline-level profiles
  • Graceful fallback to application-level profiles when not set

Repository Layer

  • Added GetInfraProfileIdByPipelineId() method for pipeline-specific lookups
  • Updated pipeline creation/update operations to handle the new field

Usage Examples

Creating a pipeline with specific infra profile:

{
  "appId": 123,
  "ciPipelines": [{
    "name": "production-build",
    "infraProfileId": 456,
    "isManual": false
  }]
}

Updating a pipeline's infra profile:

{
  "action": "UPDATE_SOURCE",
  "ciPipeline": {
    "id": 789,
    "infraProfileId": 456
  }
}

Benefits

  • Granular Control: Different CI pipelines can use different build infrastructure
  • Cost Optimization: Assign appropriate resources based on pipeline requirements
  • Backward Compatibility: Existing configurations continue to work unchanged
  • Flexibility: Easy to modify individual pipeline infrastructure without affecting the entire application

Testing

The implementation maintains full backward compatibility and includes:

  • Database migration scripts with proper rollback support
  • Graceful error handling for missing or invalid profiles
  • Fallback logic ensuring builds always have an infra profile assigned

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Feature: Support to select the build infra on pipeline level.</issue_title>
<issue_description>### 🔖 Feature description

We have following the use case .

  1. Define the build infra for all production pipelines (for example CI pipelines attached to production environments).
  2. Provide flexibility to pass node-level selectors from the UI, allowing builds (development or production) to be scheduled on specific nodes when the pipeline is triggered.

🎤 Pitch / Usecases

We have following the use case .

  1. Define the build infra for all production pipelines (for example CI pipelines attached to production environments).
  2. Provide flexibility to pass node-level selectors from the UI, allowing builds (for eg development or production pipeline) to be scheduled on specific nodes when the pipeline is triggered.

🔄️ Alternative

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Comments on the Issue (you are @copilot in this section)

Fixes #6837

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link

Bito Automatic Review Skipped - Draft PR

Bito didn't auto-review because this pull request is in draft status.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change draft PR review settings here, or contact your Bito workspace admin at shivam@devtron.ai.

@abhibhaw abhibhaw requested a review from Copilot September 25, 2025 11:59
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI and others added 3 commits September 25, 2025 12:17
Co-authored-by: abhibhaw <39991296+abhibhaw@users.noreply.github.com>
Co-authored-by: abhibhaw <39991296+abhibhaw@users.noreply.github.com>
Co-authored-by: abhibhaw <39991296+abhibhaw@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Feature: Support to select the build infra on pipeline level. feat: Add pipeline-level build infrastructure profile support Sep 25, 2025
@Copilot Copilot AI requested a review from abhibhaw September 25, 2025 12:25
Copilot finished work on behalf of abhibhaw September 25, 2025 12:25
Copy link

@abhibhaw abhibhaw requested a review from Copilot September 25, 2025 12:49
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +74 to +77
// Query the ci_pipeline table directly for the infra_profile_id
var infraProfileId *int
query := `SELECT infra_profile_id FROM ci_pipeline WHERE id = ? AND deleted = false`
_, err := impl.infraProfileRepo.GetDbConnection().Query(&infraProfileId, query, pipelineId)
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using raw SQL query instead of the repository pattern breaks the established abstraction. Consider using the CiPipelineRepository.GetInfraProfileIdByPipelineId method that's already implemented in the same PR.

Suggested change
// Query the ci_pipeline table directly for the infra_profile_id
var infraProfileId *int
query := `SELECT infra_profile_id FROM ci_pipeline WHERE id = ? AND deleted = false`
_, err := impl.infraProfileRepo.GetDbConnection().Query(&infraProfileId, query, pipelineId)
// Use the repository method to fetch infra_profile_id for the pipeline
infraProfileId, err := impl.ciPipelineRepository.GetInfraProfileIdByPipelineId(pipelineId)

Copilot uses AI. Check for mistakes.

_, err := impl.infraProfileRepo.GetDbConnection().Query(&infraProfileId, query, pipelineId)
if err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, nil // Pipeline not found, fall back to app-level profile
Copy link
Preview

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment suggests fallback to app-level profile, but returning nil here doesn't trigger the fallback - it just returns nil. The actual fallback logic happens in the calling function when pipelineInfraProfileId is nil.

Suggested change
return nil, nil // Pipeline not found, fall back to app-level profile
return nil, nil // Pipeline not found; returning nil signals caller to handle fallback to app-level profile

Copilot uses AI. Check for mistakes.

Copy link

Bito Automatic Review Skipped - Draft PR

Bito didn't auto-review because this pull request is in draft status.
No action is needed if you didn't intend for the agent to review it. Otherwise, to manually trigger a review, type /review in a comment and save.
You can change draft PR review settings here, or contact your Bito workspace admin at shivam@devtron.ai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Support to select the build infra on pipeline level.
2 participants