Fix VM creation to use parent domain for subdomains #522
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 enhancements and new features to the
trellis
package, focusing on domain management and site identification. The changes include adding new utility functions, updating existing methods for better site handling, and adding comprehensive tests for the new functionalities.This pull request still needs testing!
Enhancements and New Features:
Utility Functions:
GetParentDomain
function to return the parent domain of a given site name.MainSiteName
method to determine the main site name for VM naming, prioritizing non-subdomain sites.Method Updates:
MainSiteFromEnvironment
method to use the newMainSiteName
method for determining the main site name.Testing:
GetParentDomain
to verify correct parent domain extraction from various site names.MainSiteName
to ensure it correctly identifies the main site in different configurations.TestMainSiteFromEnvironment
to include various scenarios for site selection and error handling.These changes aim to improve the accuracy and reliability of domain and site management within the
trellis
package.How These Changes Help Run Multiple Sites on a Single VM
The changes we've made to the Trellis CLI ensure that
blocks.imagewize.com
andimagewize.com
will run on the same virtual machine rather than creating separate VMs. Here's how it works:Problem Solved
Previously, Trellis CLI would create a separate VM for each site defined in your
wordpress_sites.yml
file, even when one was a subdomain of another. This caused:Solution Implemented
The core of our solution involves these key components:
We added the
GetParentDomain()
function that extracts the parent domain from any subdomain:imagewize.com
→ returnsimagewize.com
blocks.imagewize.com
→ returnsimagewize.com
The new
MainSiteName()
method determines which site name should be used for VM naming:imagewize.com
overblocks.imagewize.com
)We updated MainSiteFromEnvironment() to use this domain grouping logic, which is called by all VM commands:
trellis vm start
trellis vm stop
trellis vm delete
Practical Result
When you run trellis vm start in your project containing both
imagewize.com
andblocks.imagewize.com
:imagewize.com
is the parent domainimagewize.com
is createdThese changes ensure a more intuitive experience where related sites are properly grouped together on the same VM, which is particularly important for projects with multiple subdomains.