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

package manager for vendor pull #768

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open

package manager for vendor pull #768

wants to merge 65 commits into from

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Nov 9, 2024

what

  • New Feature interactive package manager for vendor pull
    interactive shell for atmos vendor pull --everything
  • Support --everything flag for test non TTY mod run atmos vendor pull --everything </dev/null |& cat > atmos_vendor_pull.log

screenshots

2024-11-09 15_02_32-vendor_model go - atmos  WSL_ Ubuntu  - Visual Studio Code
2024-11-09 15_02_51-vendor_model go - atmos  WSL_ Ubuntu  - Visual Studio Code

why

Build an interface for a package manager using bubbletea

references

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced user interface for vendor commands utilizing the Bubble Tea framework.
    • New --everything flag for the vendorPullCmd command, allowing users to vendor all components in one go.
    • Improved functionality for managing vendor package installations, including enhanced error handling and progress feedback.
    • Updated configuration files (atmos.yaml) to utilize the new --everything option in vendor commands.
    • Expanded documentation on vendoring commands, including examples and OCI registry support in vendor-manifest.mdx.
  • Bug Fixes

    • Refined validation logic for command-line flags to prevent conflicts.
  • Refactor

    • Modularized code structure for better readability and maintainability.
    • Improved error handling and logging for vendor operations.
  • Documentation

    • Revised CLI Commands Cheat Sheet and other documentation to include the new --everything flag for vendor commands.
    • Enhanced the vendor-manifest.mdx documentation with detailed examples.

@osterman
Copy link
Member

osterman commented Nov 9, 2024

running download error: could not open a new TTY: open /dev/tty: no such device or address

We need a fallback for headless terminals. This is probably handled by charmbracelet as well. We might just not be using it.

Copy link
Contributor

coderabbitai bot commented Nov 9, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces updates focused on dependency management in the go.mod file and enhancements to vendor component handling in the codebase. Key changes include updates to dependency versions, the addition of new functions for managing vendor components, and a restructuring of existing functions to improve modularity and error handling. These modifications aim to refine the user experience for vendor operations within the CLI application.

Changes

File Path Change Summary
go.mod - Updated github.com/charmbracelet/bubbletea to v1.2.1.
- Re-added github.com/mattn/go-isatty v0.0.20.
- Added github.com/charmbracelet/harmonica v0.2.0.
- Confirmed github.com/charmbracelet/x/ansi at v0.4.5.
internal/exec/vendor_component_utils.go - Added ExecuteStackVendorInternal function.
- Refactored ExecuteComponentVendorInternal for improved structure and error handling.
- Introduced CheckTTYSupport function.
internal/exec/vendor_model.go - Added pkgType and updated pkgAtmosVendor and modelVendor types.
- Added methods for managing vendor installations and progress.
internal/exec/vendor_model_component.go - Added pkgComponentVendor type.
- Introduced methods for initializing and managing component installations.
internal/exec/vendor_utils.go - Refactored ExecuteVendorPullCommand and ExecuteAtmosVendorInternal functions for better modularity.
- Added functions for source validation and logging.
cmd/vendor_pull.go - Added --everything flag to vendorPullCmd for executing the command to vendor all components.

Assessment against linked issues

Objective Addressed Explanation
Support atmos vendor pull --everything (DEV-2716)
Improve vendor pull UX (DEV-270)

Possibly related PRs

Suggested reviewers

  • aknysh

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f25946 and fbe3504.

📒 Files selected for processing (1)
  • website/docs/core-concepts/vendor/vendor-manifest.mdx (1 hunks)
🔇 Additional comments (2)
website/docs/core-concepts/vendor/vendor-manifest.mdx (2)

157-158: Restore the previous working example as suggested.

The command examples are well-structured and align with the PR objectives. However, as noted in the previous review, please restore the working example that was removed.


Line range hint 1-24: Documentation is comprehensive and well-structured!

The documentation effectively covers all aspects of the vendor manifest functionality, including:

  • Clear command examples with the new --everything flag
  • Detailed explanations of configuration options
  • Practical examples for different use cases
  • Important warnings and notes for users

This will greatly help users understand and utilize the vendor pull functionality.

Also applies to: 157-158


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.

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: 6

🧹 Outside diff range and nitpick comments (9)
internal/exec/vendor_model.go (1)

148-148: Add missing space in completion message

There's a missing space after the period in the string "Vendored %d components.Failed to vendor %d components.\n", which causes the message to read incorrectly. Adding a space will improve readability.

Apply this diff to fix the formatting:

return doneStyle.Render(fmt.Sprintf("Vendored %d components.Failed to vendor %d components.\n", n-m.failedPkg, m.failedPkg))
+return doneStyle.Render(fmt.Sprintf("Vendored %d components. Failed to vendor %d components.\n", n-m.failedPkg, m.failedPkg))
internal/exec/vendor_model_component.go (5)

23-34: Export pkgComponentVendor struct

If there's a possibility of using pkgComponentVendor outside this package in the future, consider exporting it by capitalizing the struct name. Adding comments to structs and fields will also enhance code readability.


135-137: Add missing space in status message

There's a missing space after the period in the status message. This will improve the readability of the output.

-return doneStyle.Render(fmt.Sprintf("Vendored %d components.Failed to vendor %d components.\n", n-m.failedPkg, m.failedPkg))
+return doneStyle.Render(fmt.Sprintf("Vendored %d components. Failed to vendor %d components.\n", n-m.failedPkg, m.failedPkg))

166-199: Refactor to eliminate duplicate code in downloadComponentAndInstall

The function downloadComponentAndInstall contains similar code blocks for handling components and mixins. Refactoring can reduce duplication and simplify maintenance.

Here's a possible refactor:

 func downloadComponentAndInstall(p pkgComponentVendor, dryRun bool, cliConfig schema.CliConfiguration) tea.Cmd {
     return func() tea.Msg {
         if dryRun {
             time.Sleep(100 * time.Millisecond)
             return installedPkgMsg{
                 err:  nil,
                 name: p.name,
             }
         }

-        if p.IsComponent {
-            err := installComponent(p, cliConfig)
-            if err != nil {
-                return installedPkgMsg{
-                    err:  err,
-                    name: p.name,
-                }
-            }
-            return installedPkgMsg{
-                err:  nil,
-                name: p.name,
-            }
-        }
-        if p.IsMixins {
-            err := installMixin(p, cliConfig)
-            if err != nil {
-                return installedPkgMsg{
-                    err:  err,
-                    name: p.name,
-                }
-            }
-            return installedPkgMsg{
-                err:  nil,
-                name: p.name,
-            }
-        }
+        var err error
+        if p.IsComponent {
+            err = installComponent(p, cliConfig)
+        } else if p.IsMixins {
+            err = installMixin(p, cliConfig)
+        } else {
+            err = fmt.Errorf("unknown install operation")
+        }
         return installedPkgMsg{
             err:  err,
             name: p.name,
         }
     }
 }

258-259: Include package type in error message

Adding the package type to the error message will help in debugging unknown package types.

-return fmt.Errorf("unknown package type")
+return fmt.Errorf("unknown package type: %v", p.pkgType)

297-298: Include package type in error message

Similarly, in installMixin, include the package type in the error message for better clarity.

-return fmt.Errorf("unknown package type")
+return fmt.Errorf("unknown package type: %v", p.pkgType)
internal/exec/vendor_component_utils.go (3)

96-105: Implement ExecuteStackVendorInternal function

The ExecuteStackVendorInternal function currently returns a "not supported yet" error. Consider implementing the necessary logic or providing a more detailed message.

Would you like assistance in drafting the implementation or creating a GitHub issue to track this task?


343-343: Wrap error with %w for proper error handling

To enable error unwrapping, replace %v with %w when formatting errors.

Apply this diff:

- return fmt.Errorf("error initializing model: %v", err)
+ return fmt.Errorf("error initializing model: %w", err)

341-345: Handle errors from the TUI run

Ensure that errors from tea.NewProgram(model).Run() are properly handled to maintain robustness.

Apply this diff:

if _, err := tea.NewProgram(model).Run(); err != nil {
-   return fmt.Errorf("running download error: %w", err)
+   return fmt.Errorf("error running TUI program: %w", err)
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3342e8e and 5248650.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod (1 hunks)
  • internal/exec/vendor_component_utils.go (4 hunks)
  • internal/exec/vendor_model.go (1 hunks)
  • internal/exec/vendor_model_component.go (1 hunks)
  • internal/exec/vendor_utils.go (5 hunks)
🔇 Additional comments (10)
go.mod (1)

96-96: LGTM! Clean dependency addition for TUI animations.

The addition of github.com/charmbracelet/harmonica aligns perfectly with implementing an improved vendor pull interface using Bubble Tea. This indirect dependency will provide smooth animation capabilities for the TUI.

Let's verify the harmonica package usage in the codebase:

internal/exec/vendor_utils.go (8)

10-10: Importing Bubble Tea library for TUI functionality

The addition of the tea import integrates the Bubble Tea library, enabling the new TUI enhancements.


178-179: Calling logInitialMessage to enhance user feedback

Incorporating logInitialMessage improves the user experience by logging initial processing information.


Line range hint 250-309: Refactoring source processing into modular functions

The introduction of shouldSkipSource and validateSourceFields enhances code readability and maintainability by encapsulating specific logic.


271-280: Clarifying source type determination logic

The determineSourceType function cleanly separates the logic for source type determination, improving code clarity.


311-321: Implementing TUI for package processing

Introducing the TUI enhances the user interface during package processing with Bubble Tea.


372-379: Defining logInitialMessage function

Centralizing initial logging supports better code organization and reduces redundancy.


380-392: Duplicate issue: Modifying a value receiver in validateSourceFields

As mentioned earlier, modifying s.File won't affect the original struct since s is passed by value.


435-491: Generating skip function for file copying

The generateSkipFunction effectively handles inclusion and exclusion patterns, enhancing modularity and reusability.

internal/exec/vendor_component_utils.go (1)

15-15: Bubble Tea import added for TUI integration

The addition of the Bubble Tea package is appropriate for implementing TUI features, aligning with the PR objectives.

internal/exec/vendor_model.go Outdated Show resolved Hide resolved
internal/exec/vendor_model.go Outdated Show resolved Hide resolved
internal/exec/vendor_model.go Outdated Show resolved Hide resolved
internal/exec/vendor_utils.go Outdated Show resolved Hide resolved
internal/exec/vendor_component_utils.go Outdated Show resolved Hide resolved
internal/exec/vendor_component_utils.go Outdated Show resolved Hide resolved
@osterman osterman changed the title Dev 270 n @auto-title Nov 9, 2024
@osterman osterman added the minor New features that do not break anything label Nov 9, 2024
@osterman
Copy link
Member

osterman commented Nov 9, 2024

Running atmos vendor pull --logs-level Debug provides no useful debug information.

image

@osterman osterman changed the title @auto-title @coderabbitai Nov 9, 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: 1

🧹 Outside diff range and nitpick comments (2)
internal/exec/vendor_component_utils.go (2)

98-105: Add more descriptive error message for unsupported stack vendor command.

The error message could be more helpful by suggesting alternatives or explaining why it's not supported yet.

-	return fmt.Errorf("command 'atmos vendor pull --stack <stack>' is not supported yet")
+	return fmt.Errorf("command 'atmos vendor pull --stack <stack>' is not supported yet. Please use 'atmos vendor pull --component <component>' instead")

340-353: Consider adding fallback progress indicator for non-TTY environments.

While the code correctly handles non-TTY environments by disabling the TUI renderer, it could benefit from a simple text-based progress indicator as a fallback.

 if !CheckTTYSupport() {
     opts = []tea.ProgramOption{tea.WithoutRenderer(), tea.WithInput(nil)}
     u.LogWarning(cliConfig, "TTY is not supported. Running in non-interactive mode")
+    // Add simple text-based progress updates
+    model.OnProgress = func(progress float64, status string) {
+        fmt.Printf("Progress: %.0f%% - %s\n", progress*100, status)
+    }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdb218b and e2e5cc7.

📒 Files selected for processing (1)
  • internal/exec/vendor_component_utils.go (4 hunks)
🧰 Additional context used
📓 Learnings (1)
internal/exec/vendor_component_utils.go (1)
Learnt from: aknysh
PR: cloudposse/atmos#768
File: internal/exec/vendor_component_utils.go:312-316
Timestamp: 2024-11-20T18:38:34.525Z
Learning: Ensure that mixin package type determination supports local files, handling them consistently with component package type determination.
🔇 Additional comments (3)
internal/exec/vendor_component_utils.go (3)

111-113: Improve .git directory exclusion logic.

Using filepath.Base(src) == ".git" is more precise than string suffix matching.


247-265: LGTM: Clean package type determination logic.

The package type determination is well-structured and handles all cases (OCI, local, remote) appropriately.


359-361: LGTM: Simplified TTY support check.

The function correctly focuses on stdout TTY support since the vendoring process doesn't require user input.

internal/exec/vendor_component_utils.go Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 22, 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: 0

🧹 Outside diff range and nitpick comments (1)
website/docs/core-concepts/vendor/vendor-manifest.mdx (1)

414-414: Consider enhancing the example output with timing information.

The command output effectively demonstrates the hierarchical processing of vendor configurations. To make it even more informative for users, consider adding timing information to show how long each pull operation takes.

Add timing information using the time prefix:

> atmos vendor pull --everything

-Processing vendor config file 'vendor.yaml'
-Pulling sources for the component 'my-vpc6' from 'github.com/cloudposse/terraform-aws-components.git//modules/vpc?ref=1.315.0' into 'components/terraform/infra/my-vpc6'
+[00:00] Processing vendor config file 'vendor.yaml'
+[00:01] Pulling sources for the component 'my-vpc6' from 'github.com/cloudposse/terraform-aws-components.git//modules/vpc?ref=1.315.0' into 'components/terraform/infra/my-vpc6'
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b791f9e and c0577cf.

📒 Files selected for processing (2)
  • website/docs/cheatsheets/commands.mdx (1 hunks)
  • website/docs/core-concepts/vendor/vendor-manifest.mdx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/docs/cheatsheets/commands.mdx
🔇 Additional comments (1)
website/docs/core-concepts/vendor/vendor-manifest.mdx (1)

157-157: LGTM! Example has been properly restored.

The CLI command examples are clear and demonstrate all supported usage patterns. The example that was previously requested to be restored is now present.

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: 1

🧹 Outside diff range and nitpick comments (2)
website/docs/cli/commands/vendor/vendor-pull.mdx (1)

Line range hint 1-1: Add a troubleshooting section.

Consider adding a troubleshooting section to help users handle common issues, such as TTY errors and debug logging. This would be particularly helpful given the reported issues.

Add this section at the end of the file:

## Troubleshooting

### Common Issues

1. TTY Errors
   - Error: "could not open a new TTY: open /dev/tty: no such device or address"
   - Solution: The command automatically falls back to non-interactive mode. Redirect output to a log file if needed.

2. Debug Logging
   - For detailed logging: Use `--logs-level Debug`
   - Example: `atmos vendor pull --everything --logs-level Debug`

3. CI/CD Environments
   - Always use non-interactive mode by redirecting output
   - Example: `atmos vendor pull --everything > vendor-pull.log 2>&1`
website/docs/core-concepts/vendor/vendor-manifest.mdx (1)

157-158: Consider clarifying the default behavior of atmos vendor pull

Since we're introducing the --everything flag, it would be helpful to clarify the difference between atmos vendor pull and atmos vendor pull --everything. Consider adding a note explaining when to use each variant.

-# atmos vendor pull 
+# Default behavior - requires specifying type, stack, or component
+# atmos vendor pull
+
+# Pull all definitions
 # atmos vendor pull --everything
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c0577cf and 5f25946.

📒 Files selected for processing (2)
  • website/docs/cli/commands/vendor/vendor-pull.mdx (2 hunks)
  • website/docs/core-concepts/vendor/vendor-manifest.mdx (2 hunks)
🔇 Additional comments (2)
website/docs/cli/commands/vendor/vendor-pull.mdx (1)

32-36: 🛠️ Refactor suggestion

Documentation needs to cover both interactive and non-TTY modes.

The command usage section should explain both the interactive mode (using Bubble Tea framework) and the non-TTY fallback behavior. This is particularly important given the reported issues with headless terminals.

Add a section explaining both modes:

atmos vendor pull 
atmos vendor pull --everything
atmos vendor pull --component <component> [options]
atmos vendor pull -c <component> [options]
atmos vendor pull --tags <tag1>,<tag2> [options]
+
+## Terminal Modes
+
+The command supports two operational modes:
+
+1. Interactive Mode (Default for TTY)
+   - Provides a user-friendly interface with progress tracking
+   - Automatically enabled when running in a terminal
+
+2. Non-Interactive Mode
+   - Automatically used in non-TTY environments (CI/CD, redirected output)
+   - Suitable for logging and automation
+   - Example: `atmos vendor pull --everything > pull.log`
website/docs/core-concepts/vendor/vendor-manifest.mdx (1)

415-415: LGTM! Terminal output example is comprehensive

The terminal output example effectively demonstrates:

  • Usage of the new --everything flag
  • Pulling from multiple sources (OCI and Git)
  • Version handling in targets

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.

atmos vendor pull --tags ... --dry-run doesn't do a full run
3 participants