Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for vendor path setting in atmos.yaml #737

Merged
merged 36 commits into from
Nov 13, 2024
Merged

Conversation

Cerebrovinny
Copy link
Collaborator

@Cerebrovinny Cerebrovinny commented Oct 20, 2024

what

  • Added new support for vendor files under folders or multiple vendor files to be processed in Lexicographic order

  • Refactored logic that does check the presence of vendor file

why

  • Users now should be able to use new variable vendor in atmos.yaml and process different locations and amounts of vendor files.

references

#DEV-2378

CleanShot 2024-10-22 at 23 34 50@2x

New tests after general refactoring base path
CleanShot 2024-10-30 at 17 02 50

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a vendor section in the atmos.yaml configuration, allowing users to specify a base_path for vendor files.
    • Added support for the new command-line flag --vendor-base-path to enhance configuration options.
    • Enhanced documentation to clarify new configuration options and loading behavior.
  • Configuration Updates

    • New YAML files for development, production, and staging environments with structured variable management.
    • Added new vendor configuration files to demonstrate sourcing components from GitHub.
  • Documentation

    • Updated CLI documentation to include new parameters and configuration options for better usability.
    • Expanded details on the loading order of configuration files, logging behavior, and added sections for aliases and templates.

@Cerebrovinny Cerebrovinny requested review from a team as code owners October 20, 2024 20:27
Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce a new vendor section in the atmos.yaml configuration file, which includes a base_path key for specifying vendor configuration files. The logic for reading and processing vendor configurations has been enhanced in the vendor_utils.go file. Additionally, new fields related to vendor configurations have been added to various structs in the schema and configuration files. Documentation updates reflect these changes, and several new example configurations for different environments have been created.

Changes

File Path Change Summary
atmos.yaml Added vendor section with base_path set to ./vendor.yaml. Updated existing base_path.
internal/exec/vendor_utils.go Modified ReadAndProcessVendorConfigFile to enhance vendor config reading and error handling.
pkg/schema/schema.go Added Vendor struct and fields for CliConfiguration, ArgsAndFlagsInfo, and ConfigAndStacksInfo.
pkg/config/const.go Introduced constant VendorBasePathFlag with value "--vendor-base-path".
pkg/config/utils.go Enhanced processEnvVars to retrieve ATMOS_VENDOR_BASE_PATH environment variable.
internal/exec/utils.go Added cfg.VendorBasePathFlag to commonFlags for command-line parsing.
website/docs/cli/configuration/configuration.mdx Updated documentation to reflect new vendor.base_path key and other configuration enhancements.
examples/demo-vendoring/atmos.yaml Introduced vendor section with base_path set to ./vendor.yaml.
examples/demo-vendoring/stacks/catalog/myapp.yaml Added new myapp component under terraform with specified variables.
examples/demo-vendoring/stacks/deploy/dev.yaml Created dev.yaml for development environment with myapp component.
examples/demo-vendoring/stacks/deploy/prod.yaml Created prod.yaml for production environment with myapp component.
examples/demo-vendoring/stacks/deploy/staging.yaml Created staging.yaml for staging environment with myapp component.
examples/demo-vendoring/vendor/vendor1.yaml Added vendor1.yaml for vendor configuration with ipinfo component.
examples/demo-vendoring/vendor/vendor2.yaml Added vendor2.yaml for vendor configuration with weather component.
examples/demo-vendoring/vendor.d/vendor1.yaml Added vendor1.yaml in vendor.d for vendor configuration with ipinfo component.

Assessment against linked issues

Objective Addressed Explanation
Vendor path setting in atmos.yaml to specify vendor.yaml path (DEV-2378)

Possibly related PRs

Suggested reviewers

  • aknysh
  • osterman
  • gberenice

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Cerebrovinny Cerebrovinny requested a review from aknysh October 20, 2024 20:28
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 332a1a9 and cca19f7.

📒 Files selected for processing (3)
  • atmos.yaml (1 hunks)
  • internal/exec/vendor_utils.go (1 hunks)
  • pkg/schema/schema.go (2 hunks)
🧰 Additional context used
🪛 yamllint
atmos.yaml

[error] 359-359: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (2)
pkg/schema/schema.go (2)

18-18: LGTM: Addition of Vendor field to CliConfiguration

The new Vendor field in the CliConfiguration struct is well-implemented. It follows the existing naming conventions and properly uses the omitempty tag, making it an optional configuration. This change aligns with the PR objective of supporting vendor path specification in the Atmos YAML configuration.


18-18: Summary: Vendor configuration support successfully implemented

The changes made to pkg/schema/schema.go effectively implement support for vendor path specification in the Atmos YAML configuration. The additions are well-integrated into the existing code structure and follow established conventions. These modifications enable users to define vendor settings, aligning with the PR's objectives.

Key points:

  1. The CliConfiguration struct now includes an optional Vendor field.
  2. A new Vendor struct has been added to represent vendor-specific settings.

These changes provide a solid foundation for handling vendor configurations in the Atmos setup.

Also applies to: 549-551

atmos.yaml Outdated Show resolved Hide resolved
atmos.yaml Outdated Show resolved Hide resolved
pkg/schema/schema.go Outdated Show resolved Hide resolved
internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
internal/exec/vendor_utils.go Show resolved Hide resolved
internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
atmos.yaml Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

please see comments and resolve the conflicts

@osterman osterman changed the title Feat: Vendor path setting in yaml support #DEV-2378 Feat: Vendor path setting in yaml support Oct 21, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between cca19f7 and 62b7c7d.

📒 Files selected for processing (3)
  • atmos.yaml (1 hunks)
  • internal/exec/vendor_utils.go (1 hunks)
  • pkg/schema/schema.go (2 hunks)
🧰 Additional context used
🪛 yamllint
atmos.yaml

[error] 359-359: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (7)
atmos.yaml (1)

355-359: Excellent addition of the vendor configuration!

The new vendor section with the vendor_yaml_path setting is well-implemented and aligns perfectly with the PR objectives. Great job on:

  1. Providing a meaningful default path ("./vendor.yaml").
  2. Supporting both absolute and relative paths.
  3. Allowing override via environment variable or command-line argument.

This implementation offers flexibility and clear configuration options for users.

🧰 Tools
🪛 yamllint

[error] 359-359: no new line character at the end of file

(new-line-at-end-of-file)

pkg/schema/schema.go (1)

18-18: LGTM: CliConfiguration struct updated correctly

The addition of the Vendor field to the CliConfiguration struct is well-implemented. The use of omitempty in the tags is appropriate, making the field optional in serialized forms. This change aligns with the PR objective of introducing support for specifying a vendor path within the Atmos YAML configuration file.

internal/exec/vendor_utils.go (5)

137-143: Well-implemented handling of custom vendor YAML path

The logic correctly checks if a vendor_yaml_path is specified in the atmos.yaml configuration and appropriately constructs an absolute path if necessary. It enhances flexibility for users to define custom paths.


145-149: Effective addition of default paths to check

By including both the current directory and the base_path directory in pathsToCheck, the code ensures that the vendor configuration file can be located even if it's placed in different common directories.


152-158: Efficient search for the vendor configuration file

The loop over pathsToCheck efficiently finds the first existing vendor config file without unnecessary checks, improving the performance of the configuration loading process.


160-162: Clear error messaging when vendor config file is not found

Returning an error with the list of paths tried provides valuable debugging information to the user, aiding in quick resolution of configuration issues.


177-180: Proper validation of the vendor config 'kind' field

The code correctly validates the kind field of the vendor configuration, ensuring that only supported configurations are processed, which enhances robustness.

atmos.yaml Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 62b7c7d and 2fb288c.

📒 Files selected for processing (2)
  • atmos.yaml (1 hunks)
  • internal/exec/vendor_utils.go (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
internal/exec/vendor_utils.go (4)

Line range hint 83-89: LGTM!

The error handling and vendorConfig existence check are properly implemented.


142-155: LGTM with existing suggestions!

The fallback logic for finding the vendor config file is correct, but please address the existing comment about using filepath.Join instead of path.Join.


159-159: LGTM!

The file reading and validation logic is well-implemented with proper error handling.


131-141: Verify usage of vendor yaml path in the codebase

Let's verify how the new vendor yaml path feature is used across the codebase to ensure compatibility.

✅ Verification successful

Let me gather more context about the implementation to ensure we fully understand the impact.


Let me try one more verification to check the complete implementation context:


Based on the gathered information, I can now provide a final response:

The vendor yaml path changes are safely implemented

The code changes are safe and well-integrated for the following reasons:

  • The VendorYamlPath is properly defined in the Vendor struct in pkg/schema/schema.go with appropriate yaml/json/mapstructure tags
  • The implementation in vendor_utils.go handles both absolute and relative paths correctly
  • The feature is only used in ReadAndProcessVendorConfigFile which is called in just two places, both in vendor_utils.go
  • The changes maintain backward compatibility as the VendorYamlPath check is guarded by an empty string check
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all references to vendor yaml configuration to verify compatibility
# with the new vendor yaml path feature.

# Test 1: Find all references to vendor config file
echo "=== Finding references to vendor config file ==="
rg -l "vendor\.ya?ml"

# Test 2: Find all calls to ReadAndProcessVendorConfigFile
echo -e "\n=== Finding calls to ReadAndProcessVendorConfigFile ==="
ast-grep --pattern 'ReadAndProcessVendorConfigFile($$$)'

# Test 3: Find all references to VendorYamlPath in struct initialization
echo -e "\n=== Finding VendorYamlPath usage ==="
rg "VendorYamlPath"

Length of output: 1757


Script:

#!/bin/bash
# Let's examine the ReadAndProcessVendorConfigFile implementation and its usage context

# Check the implementation of ReadAndProcessVendorConfigFile
echo "=== ReadAndProcessVendorConfigFile implementation ==="
ast-grep --pattern 'func ReadAndProcessVendorConfigFile($$$) {
  $$$
}'

# Check the Vendor struct definition and usage
echo -e "\n=== Vendor struct definition ==="
ast-grep --pattern 'type Vendor struct {
  $$$
}'

# Look for any tests related to vendor yaml path
echo -e "\n=== Tests related to vendor yaml path ==="
rg -l "VendorYamlPath.*Test"

Length of output: 656


Script:

#!/bin/bash
# Let's examine the complete implementation context

# Check the full content of vendor_utils.go to understand the implementation
echo "=== Vendor utils implementation context ==="
rg -A 10 -B 10 "func ReadAndProcessVendorConfigFile" internal/exec/vendor_utils.go

# Check for any error handling or validation related to vendor yaml path
echo -e "\n=== Error handling related to vendor yaml path ==="
rg -A 5 -B 5 "VendorYamlPath.*err" 

# Check for any config validation
echo -e "\n=== Config validation ==="
rg -A 5 -B 5 "func.*[Vv]alidate.*Vendor"

Length of output: 1132

atmos.yaml (1)

355-359: LGTM! Well-structured vendor configuration.

The new vendor configuration follows the established pattern of other path configurations in the file, with:

  • Clear documentation of supported path types (absolute/relative)
  • Consistent environment variable override support
  • Command-line argument override support

internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
atmos.yaml Outdated Show resolved Hide resolved
osterman
osterman previously approved these changes Oct 23, 2024
atmos.yaml Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

please see comments

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@Cerebrovinny the PR looks good, please address the comment

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed minor New features that do not break anything labels Nov 6, 2024
@osterman osterman added the minor New features that do not break anything label Nov 6, 2024
@aknysh aknysh removed the no-release Do not create a new release (wait for additional code changes) label Nov 11, 2024
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

LGTM, please see comments

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
internal/exec/vendor_utils.go (3)

126-166: Consider improving error handling for base path resolution

The logic for resolving vendor config paths is correct, but the error handling could be more informative.

Consider adding more context to error messages when paths can't be resolved:

-            return vendorConfig, vendorConfigFileExists, "", fmt.Errorf("vendor config file or directory '%s' does not exist", pathToVendorConfig)
+            return vendorConfig, vendorConfigFileExists, "", fmt.Errorf("vendor config file or directory '%s' does not exist (base_path: %s)", pathToVendorConfig, cliConfig.BasePath)

187-228: Consider adding validation for source component names

While the code handles duplicate components well, it might be worth adding validation for component name format.

Consider adding validation to ensure component names follow a consistent format:

+       // Validate component name format
+       if source.Component != "" {
+           if !isValidComponentName(source.Component) {
+               return vendorConfig, false, "", fmt.Errorf("invalid component name '%s' in config file '%s'. Component names must match pattern [a-z0-9-]+",
+                   source.Component, configFile)
+           }
+       }
        if sourceMap[source.Component] {

192-223: Consider adding logging for skipped duplicate imports

The code silently skips duplicate imports. While this is correct behavior, adding debug logs would help with troubleshooting.

Consider adding debug logging for skipped imports:

        if importMap[imp] {
+           u.LogDebug(cliConfig, fmt.Sprintf("Skipping duplicate import '%s' in config file '%s'", imp, configFile))
            continue // Skip duplicate imports
        }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c451f53 and af5d4ef.

📒 Files selected for processing (1)
  • internal/exec/vendor_utils.go (5 hunks)
🧰 Additional context used
📓 Learnings (1)
internal/exec/vendor_utils.go (2)
Learnt from: Cerebrovinny
PR: cloudposse/atmos#737
File: internal/exec/vendor_utils.go:181-182
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In `internal/exec/vendor_utils.go`, the variables `mergedSources` and `mergedImports` are declared and used later in the code. Do not suggest removing them as unused variables.
Learnt from: Cerebrovinny
PR: cloudposse/atmos#737
File: internal/exec/vendor_utils.go:131-141
Timestamp: 2024-11-12T05:52:05.088Z
Learning: In the `ReadAndProcessVendorConfigFile` function in `internal/exec/vendor_utils.go`, the existence of the vendor config file is already checked, so additional file existence checks may be unnecessary.
🔇 Additional comments (3)
internal/exec/vendor_utils.go (3)

9-9: LGTM: Import changes are well-structured

The addition of sort, upgrade to yaml.v3, and inclusion of doublestar/v4 are appropriate for the new functionality.

Also applies to: 18-18, 20-20


169-182: LGTM: Robust directory handling with doublestar

The implementation correctly handles both single file and directory-based configurations, with proper sorting and empty directory checks.


600-600: LGTM: Proper file tracking in imported sources

The code correctly tracks the origin file for each source in imported configurations.

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

thanks @Cerebrovinny

@aknysh aknysh changed the title Feat: Vendor path setting in yaml support Add support for vendor path setting in atmos.yaml Nov 13, 2024
@aknysh aknysh merged commit 9acca77 into main Nov 13, 2024
23 checks passed
@aknysh aknysh deleted the feat/dev-2378 branch November 13, 2024 20:32
Copy link

These changes were released in v1.106.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants