Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces several significant changes to the VM management and configuration handling within the Trellis CLI. The most notable updates include the addition of a new instance name management system, the centralization of VM manager creation logic, and the enhancement of testability for VM-related commands.
Key changes:
VM Instance Management:
InstanceName
field toVmConfig
struct incli_config/cli_config.go
to allow custom naming of VM instances.GetVMInstanceName
andSaveVMInstanceName
methods intrellis/vm_instance.go
to manage VM instance names with a priority system.VmStartCommand
to useGetVMInstanceName
for setting the VM name and saving it for future reference. [1] [2]Centralization and Testability:
cmd/main.go
to avoid duplicate implementations and enable easier mocking in tests.newVmManager
function fromcmd/vm.go
and updated references to use the centralized version.Testing Enhancements:
trellis/vm_instance_test.go
.VmDeleteCommand
andVmStartCommand
tests to verify instance file handling and VM name resolution. [1] [2]These changes improve the flexibility, maintainability, and testability of the Trellis CLI's VM management functionality.
VM Instance Name Resolution
The VM creation and start processes now follow a structured approach to determine which instance name to use. This is a significant improvement over the previous implementation which always defaulted to the first site alphabetically.
How VM Name Resolution Works Now
Priority Order for VM Name Resolution
The new code in
trellis/vm_instance.go
implements a priority-based approach:.trellis/lima/instance
fileVM Start Process
When running
trellis vm start
:GetVMInstanceName()
instead of directly usingMainSiteFromEnvironment()
GetVMInstanceName()
first tries to read from the instance fileimagewize.com
), it will use that nameThis ensures that once you've created a VM for a specific site, subsequent vm start commands will consistently use the same VM, rather than creating or starting a different one based on alphabetical order.
VM Creation Process
When creating a new VM:
.trellis/lima/instance
file usingSaveVMInstanceName()
Benefits
This solves your specific issue where vm start was always using "
blocks.imagewize.com
" instead of "imagewize.com
":imagewize.com
, that name is saved in the instance fileblocks.imagewize.com
comes first alphabetically, the saved instance name will be preferredThis provides consistency and predictability when managing VMs across multiple sites in a Trellis project.