-
Notifications
You must be signed in to change notification settings - Fork 3
Env and deploy #732
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
Env and deploy #732
Conversation
…ructure - Introduced development guidelines in `onctl-development.md` for Go best practices, error handling, testing, and CLI design patterns. - Updated `AGENTS.md` to include the new guidelines. - Enhanced `create`, `destroy`, `list`, `ssh`, and `vm` commands by registering them at the root level for easier access. - Implemented `deploy` command for deploying Docker images to remote VMs with progress tracking and architecture compatibility checks. - Improved error handling and logging in various commands and internal functions. - Added support for environment management with `env` command, allowing creation and destruction of environments from template files.
…and architecture validation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #732 +/- ##
=========================================
+ Coverage 9.08% 10.23% +1.15%
=========================================
Files 32 35 +3
Lines 2521 2970 +449
=========================================
+ Hits 229 304 +75
- Misses 2268 2627 +359
- Partials 24 39 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the CLI command structure and adds new features including a deploy command, environment management, VM type configuration, and improved file transfer capabilities. The changes focus on better code organization, enhanced user experience with progress tracking, and more flexible cloud resource management.
- Reorganized CLI commands under
vmandenvparent commands for better structure - Added
deploycommand for Docker image deployment to remote VMs with architecture validation - Enhanced file transfer with progress reporting for SCP operations
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/tools/scp.go | Added progress callback support for file transfers and new SCP-based transfer method |
| internal/tools/remote-run.go | Fixed EOF error handling in session cleanup |
| internal/provideraws/common.go | Updated AWS image selection to support wildcards and dynamic image configuration |
| internal/cloud/hetzner.go | Added support for VM type override from configuration |
| internal/cloud/cloud.go | Added YAML tag to VM Type field for config file support |
| cmd/vm.go | New parent command for VM management subcommands |
| cmd/ssh.go | Registered ssh command at root level for backward compatibility |
| cmd/root.go | Removed direct command registration (moved to subcommands) |
| cmd/list.go | Registered list command at root level for backward compatibility |
| cmd/env.go | New environment management command with create/destroy subcommands |
| cmd/destroy.go | Registered destroy command at root level for backward compatibility |
| cmd/deploy.go | New Docker deployment command with architecture validation and progress tracking |
| cmd/create.go | Registered create command at root level for backward compatibility |
| cmd/common.go | Added VM type merging in config merge function |
| AGENTS.md | Updated development guidelines with comprehensive Go best practices |
| .clinerules/onctl-development.md | New development guidelines file (duplicate of AGENTS.md) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
internal/tools/scp.go
Outdated
| } | ||
|
|
||
| if readErr != nil { | ||
| if readErr.Error() == "EOF" { |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comparing error strings is fragile and not idiomatic Go. Use errors.Is(readErr, io.EOF) or direct comparison readErr == io.EOF instead. This requires importing the io package.
internal/tools/scp.go
Outdated
| return err | ||
| } | ||
| defer os.Remove(tmpKeyFile.Name()) | ||
| defer tmpKeyFile.Close() |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is closed twice: once with defer tmpKeyFile.Close() at line 163 and again explicitly at line 169. The explicit close at line 169 will succeed, but the deferred close will return an error for closing an already-closed file. Remove the defer statement and keep only the explicit close with error handling.
| defer tmpKeyFile.Close() |
internal/provideraws/common.go
Outdated
| for i := 0; i < len(result.Images)-1; i++ { | ||
| for j := i + 1; j < len(result.Images); j++ { | ||
| if result.Images[i].CreationDate != nil && result.Images[j].CreationDate != nil { | ||
| if *result.Images[i].CreationDate < *result.Images[j].CreationDate { | ||
| result.Images[i], result.Images[j] = result.Images[j], result.Images[i] | ||
| } | ||
| } | ||
| } | ||
| } |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using bubble sort with O(n²) complexity for sorting images is inefficient. Use Go's built-in sort.Slice() function for O(n log n) performance: sort.Slice(result.Images, func(i, j int) bool { return *result.Images[i].CreationDate > *result.Images[j].CreationDate })
| remoteImagePath := "image.tar.gz" | ||
|
|
||
| // Upload using SCP | ||
| err = remote.SCPCopyFileWithProgress(imageTarPath, remoteImagePath, progressCallback) |
Copilot
AI
Nov 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment at line 187-188 states 'we'll use a polling approach since scp doesn't have built-in progress reporting', but the implementation doesn't actually poll for progress. It only reports completion after the transfer finishes. Update the comment to reflect the actual implementation or implement true progress polling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…remote session closure
There was a problem hiding this 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 20 out of 20 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
cmd/common.go:130
- The comment states 'will use this function in the future', but the function is already being used in cmd/destroy.go and cmd/env.go. The lint ignore comment and documentation should be updated to reflect current usage.
//lint:ignore U1000 will use this function in the future
func yesNo() bool {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer func() { | ||
| if removeErr := os.Remove(tmpKeyFile.Name()); removeErr != nil { | ||
| log.Printf("Warning: failed to remove temporary key file: %v", removeErr) | ||
| } | ||
| }() |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary key file cleanup only logs warnings on failure, which could leave sensitive private keys on disk. Consider using a more robust cleanup mechanism or at least ensuring the file is removed before the function returns, possibly by attempting removal multiple times or using os.RemoveAll for more aggressive cleanup.
| progressCallback := func(current, total int64) { | ||
| percentage := float64(current) / float64(total) * 100 |
Copilot
AI
Nov 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero can occur if total is 0 (e.g., empty file). Add a guard condition to check if total > 0 before calculating percentage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
There was a problem hiding this 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 25 out of 25 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
* Initial plan * fix: add guard condition to prevent division by zero in upload progress callback Co-authored-by: cdalar <62673+cdalar@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cdalar <62673+cdalar@users.noreply.github.com>
No description provided.