Skip to content

Conversation

@dalepgrant
Copy link
Contributor

@dalepgrant dalepgrant commented Feb 24, 2025

Relates to #514

A WIP but I've run out of time today, hopefully will pick this back up this week. Pushing up as I'm not even sure this is the right approach or wanted functionality, any feedback welcomed.

Edit: Have been using this locally for a couple of weeks, haven't hit any issues. Opening this up for review & approval after a nudge in Discourse from @jasperf.

@dalepgrant dalepgrant marked this pull request as ready for review March 11, 2025 03:04
@dalepgrant dalepgrant force-pushed the feature/vm-instance-name branch from 70054fd to 47fa754 Compare March 11, 2025 03:08
@dalepgrant dalepgrant changed the title First stab at allowing a custom instance name to be set Allow setting a custom instance name in Lima Mar 11, 2025
@jasperf
Copy link

jasperf commented Mar 17, 2025

Thanks for the pull request @dalepgrant . Hope @swalkinshaw can have a look see one of these days. Would really help getting macOS VMs to work with multiple sites on one virtual machine.

@jasperf
Copy link

jasperf commented Mar 25, 2025

@dalepgrant for testing this change how should I do this ? Local go build and use path to that binary instead of installed main Trellis CLI binary? Any tests I can help with ?

Here is what I did:

cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = git@github.com:dalepgrant/trellis-cli.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
        vscode-merge-base = origin/master
        vscode-merge-base = origin/master
[branch "feature/vm-instance-name"]
        remote = origin
        merge = refs/heads/feature/vm-instance-name
        vscode-merge-base = origin/feature/vm-instance-name
git checkout feature/vm-instance-name
go build -o trellis-custom
 jasper@mbp  ~/code/trellis-cli-dale   feature/vm-instance-name  chmod +x ./trellis-custom
jasper@mbp  ~/code/imagewize.com   blocks-subdomain  ~/code/trellis-cli-dale/trellis-custom vm start
Running command => limactl start blocks.imagewize.com
INFO[0000] Using the existing instance "blocks.imagewize.com" 
INFO[0000] Starting the instance "blocks.imagewize.com" with VM driver "vz" 
WARN[0000] vmType vz: ignoring networks[0]: [Metric]    
INFO[0000] [hostagent] hostagent socket created at /Users/jasperfrumau/.lima/blocks.imagewize.com/ha.sock 
INFO[0000] [hostagent] Starting VZ (hint: to watch the boot progress, see "/Users/jasperfrumau/.lima/blocks.imagewize.com/serial*.log") 
INFO[0000] SSH Local Port: 58246                        
INFO[0000] [hostagent] [VZ] - vm state change: running  
INFO[0000] [hostagent] Waiting for the essential requirement 1 of 2: "ssh" 
INFO[0010] [hostagent] Waiting for the essential requirement 1 of 2: "ssh" 
INFO[0010] [hostagent] The essential requirement 1 of 2 is satisfied 
INFO[0011] [hostagent] Waiting for the essential requirement 2 of 2: "user session is ready for ssh" 
INFO[0011] [hostagent] The essential requirement 2 of 2 is satisfied 
INFO[0011] [hostagent] Waiting for the guest agent to be running 
INFO[0011] [hostagent] Guest agent is running           
INFO[0011] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished" 
INFO[0011] [hostagent] Not forwarding TCP 127.0.0.53:53 
INFO[0011] [hostagent] Not forwarding TCP 127.0.0.54:53 
INFO[0011] [hostagent] Forwarding TCP from 127.0.0.1:3306 to 127.0.0.1:3306 
INFO[0011] [hostagent] The final requirement 1 of 1 is satisfied 
INFO[0011] READY. Run `limactl shell blocks.imagewize.com` to open the shell. 

Updating /etc/hosts file (sudo may be required, see `trellis vm sudoers` for more details)
Password:

Your Trellis VM is ready to use!

* Composer and WP-CLI commands need to be run on the virtual machine for any post-provision modifications.
* You can SSH into the machine with 'trellis vm shell'

So it started the wrong vm blocks.imagewize.com again.So I did

limactl delete blocks.imagewize.com
INFO[0000] The vz driver process seems already stopped  
INFO[0000] The host agent process seems already stopped 
INFO[0000] Removing *.pid *.sock *.tmp under "/Users/jasperfrumau/.lima/blocks.imagewize.com" 
INFO[0000] Removing "/Users/jasperfrumau/.lima/blocks.imagewize.com/default_ep.sock" 
INFO[0000] Removing "/Users/jasperfrumau/.lima/blocks.imagewize.com/default_fd.sock" 
INFO[0000] Removing "/Users/jasperfrumau/.lima/blocks.imagewize.com/ha.sock" 
INFO[0000] Deleted "blocks.imagewize.com" ("/Users/jasperfrumau/.lima/blocks.imagewize.com") 

and then did a ~/code/trellis-cli-dale/trellis-custom vm start and again it started creating blocks.imagewize.com :

~/code/trellis-cli-dale/trellis-custom vm start
Running command => limactl create --tty=false --name=blocks.imagewize.com -
INFO[0000] Terminal is not available, proceeding without opening an editor 
WARN[0000] vmType vz: ignoring networks[0]: [Metric]    
INFO[0000] Attempting to download the image              arch=aarch64 digest= location="https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-arm64.img"
INFO[0001] Using cache "/Users/jasperfrumau/Library/Caches/lima/download/by-url-sha256/7c8e4507222e57734b580a24bf30b7828afaae43c2f040f6e0977f45669ce961/data" 
INFO[0001] Converting "/Users/jasperfrumau/.lima/blocks.imagewize.com/basedisk" (qcow2) to a raw disk "/Users/jasperfrumau/.lima/blocks.imagewize.com/diffdisk" 
3.50 GiB / 3.50 GiB [---------------------------------------] 100.00% 1.06 GiB/s
...

So does not seem to work for me.

P.S. This is my wordpress_sites.yml:

# Created by trellis-cli v1.13.0
# Documentation: https://roots.io/trellis/docs/wordpress-sites/

wordpress_sites:
  imagewize.com:
    site_hosts:
    - canonical: imagewize.test
      redirects:
      - www.imagewize.test
    local_path: ../site
    admin_email: admin@imagewize.test
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false
  blocks.imagewize.com:
    site_hosts:
    - canonical: blocks.imagewize.test
      redirects:
      - www.blocks.imagewize.test
    local_path: ../blocks
    admin_email: admin@blocks.imagewize.test
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: self-signed
    cache:
      enabled: false

Update:

I decided to create the config file:

echo 'vm:
  instance_name: "imagewize.com"' > trellis.cli.yml

Delete existing VMs (if needed)

limactl delete blocks.imagewize.com

Start with your custom binary

~/code/trellis-cli-dale/trellis-custom vm start

BUT, when I tried that it seemed to ignore the trellis.cli.yml in the root of the project and still build the vm blocks.imagewize.com:

limactl list
NAME                    STATUS     SSH                VMTYPE    ARCH       CPUS    MEMORY    DISK      DIR
blocks.imagewize.com    Running    127.0.0.1:58448    vz        aarch64    4       4GiB      100GiB    ~/.lima/blocks.imagewize.com
imagewize.com           Stopped    127.0.0.1:0        vz        aarch64    4       4GiB      100GiB    ~/.lima/imagewize.com
...

and not just use the existing vm imagewize.com Perhaps an issue with location custom Trellis and Trellis config file. Not sure yet.

@dalepgrant
Copy link
Contributor Author

Sanity check: This file should have something like:

vm:
  manager: "lima"
  ubuntu: 22.04
  instance_name: "imagewize.com"

@jasperf
Copy link

jasperf commented Mar 27, 2025

As discussed on discord I got it working using trellis/trellis.cli.yml with:

# Trellis CLI example config file
# https://roots.io/trellis/docs/cli/#configuration
#
# database_app: sequel-ace
# open:
#   admin: "https://mysite.com/wp/wp-admin"
vm:
  instance_name: "imagewize.com"

Works really well.

@dalepgrant dalepgrant force-pushed the feature/vm-instance-name branch from 47fa754 to abf7259 Compare March 28, 2025 01:49
@swalkinshaw swalkinshaw force-pushed the feature/vm-instance-name branch from abf7259 to d75de75 Compare March 29, 2025 19:36
@swalkinshaw swalkinshaw merged commit 5e64afb into roots:master Mar 29, 2025
3 checks passed
@swalkinshaw
Copy link
Member

Thank you 🚀

@jasperf
Copy link

jasperf commented Mar 30, 2025

@swalkinshaw thanks for the merger & @dalepgrant thanks again for the pull request!

# Cleanup previous versions (if installed)
brew uninstall roots/tap/trellis-cli

# Install
brew install --HEAD roots/tap/trellis-cli-dev

# Upgrade
brew upgrade --fetch-HEAD roots/tap/trellis-cli-dev

et voilà!

@dalepgrant dalepgrant deleted the feature/vm-instance-name branch April 1, 2025 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants