From bf59bc64133ea829ac54af085f8729f618846a0f Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Fri, 7 Jun 2024 09:54:01 -0400 Subject: [PATCH 1/7] Generate list of hosted development sites after `vagrant up` --- lib/trellis/vagrant.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index ef3c6bd13a..c571b79138 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -79,6 +79,16 @@ def post_up_message msg << "\n* You can SSH into the machine with `vagrant ssh`." msg << "\n* Then navigate to your WordPress sites at `/srv/www`" msg << "\n or to your Trellis files at `#{ANSIBLE_PATH_ON_VM}`." + sites = YAML.load_file(File.join(ANSIBLE_PATH, 'group_vars/development/wordpress_sites.yml')) + wordpress_sites = sites['wordpress_sites'] + if wordpress_sites.any? + msg << "\n\n* Your Trellis is hosting the following WordPress development sites:" + wordpress_sites.each do |site_name, site| + site_url = site['site_hosts'].first + site_url = site_url.is_a?(Hash) ? site_url['canonical'] : site_url + msg << "\n\n 🌱 Name: #{site_name}: \n 🔗 URL: http://#{site_url}" + end + end msg end From 8398e9a2fc4ac61d0359965a4453eba89c8ae81b Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Fri, 7 Jun 2024 10:02:08 -0400 Subject: [PATCH 2/7] Set the correct protocol if SSL is enabled --- lib/trellis/vagrant.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index c571b79138..8fc0ee2f53 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -86,7 +86,8 @@ def post_up_message wordpress_sites.each do |site_name, site| site_url = site['site_hosts'].first site_url = site_url.is_a?(Hash) ? site_url['canonical'] : site_url - msg << "\n\n 🌱 Name: #{site_name}: \n 🔗 URL: http://#{site_url}" + site_url = site['ssl']['enabled'] ? "https://#{site_url}" : "http://#{site_url}" + msg << "\n\n 🌱 Name: #{site_name}: \n 🔗 URL: #{site_url}" end end From 8a7c452cfdb9956616dfcf2e7b56df0b0fff2a56 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Fri, 7 Jun 2024 13:54:41 -0400 Subject: [PATCH 3/7] Add additional URLs and better formatting --- lib/trellis/vagrant.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index 8fc0ee2f53..b2f7fd02d0 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -82,12 +82,17 @@ def post_up_message sites = YAML.load_file(File.join(ANSIBLE_PATH, 'group_vars/development/wordpress_sites.yml')) wordpress_sites = sites['wordpress_sites'] if wordpress_sites.any? - msg << "\n\n* Your Trellis is hosting the following WordPress development sites:" + msg << "\n\n\e[35m🚀 Development URLs: \e[0m" wordpress_sites.each do |site_name, site| site_url = site['site_hosts'].first site_url = site_url.is_a?(Hash) ? site_url['canonical'] : site_url site_url = site['ssl']['enabled'] ? "https://#{site_url}" : "http://#{site_url}" - msg << "\n\n 🌱 Name: #{site_name}: \n 🔗 URL: #{site_url}" + msg << "\n + 🌱 \e[37mName:\e[33m #{site_name}\e[0m + ├── 🔗 \e[37mURL:\e[33m #{site_url}\e[0m + ├── 🛠️ \e[37mAdmin:\e[33m #{site_url}/wp-admin\e[0m + └── 📩 \e[37mMailpit:\e[33m #{site_url}:8025\e[0m + " end end From 95933cafa51c5248e109f3ee3118901e12a4882e Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Wed, 28 Aug 2024 10:26:39 -0400 Subject: [PATCH 4/7] Update vagrant.rb --- lib/trellis/vagrant.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index b2f7fd02d0..fb36410847 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -79,11 +79,11 @@ def post_up_message msg << "\n* You can SSH into the machine with `vagrant ssh`." msg << "\n* Then navigate to your WordPress sites at `/srv/www`" msg << "\n or to your Trellis files at `#{ANSIBLE_PATH_ON_VM}`." - sites = YAML.load_file(File.join(ANSIBLE_PATH, 'group_vars/development/wordpress_sites.yml')) - wordpress_sites = sites['wordpress_sites'] - if wordpress_sites.any? + + trellis_config = Trellis::Config.new(root_path: ANSIBLE_PATH) + if trellis_config.wordpress_sites.any? msg << "\n\n\e[35m🚀 Development URLs: \e[0m" - wordpress_sites.each do |site_name, site| + trellis_config.wordpress_sites.each do |site_name, site| site_url = site['site_hosts'].first site_url = site_url.is_a?(Hash) ? site_url['canonical'] : site_url site_url = site['ssl']['enabled'] ? "https://#{site_url}" : "http://#{site_url}" From d4c3fc615a17dfc932122fef984511fa78b718b2 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Wed, 28 Aug 2024 10:36:35 -0400 Subject: [PATCH 5/7] Update vagrant.rb --- lib/trellis/vagrant.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index fb36410847..8fd8cec921 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -72,7 +72,7 @@ def mount_options(mount_type, dmode:, fmode:) end end -def post_up_message +def post_up_message(trellis_config) msg = 'Your Trellis Vagrant box is ready to use!' msg << "\n* Composer and WP-CLI commands need to be run on the virtual machine" msg << "\n for any post-provision modifications." @@ -80,7 +80,6 @@ def post_up_message msg << "\n* Then navigate to your WordPress sites at `/srv/www`" msg << "\n or to your Trellis files at `#{ANSIBLE_PATH_ON_VM}`." - trellis_config = Trellis::Config.new(root_path: ANSIBLE_PATH) if trellis_config.wordpress_sites.any? msg << "\n\n\e[35m🚀 Development URLs: \e[0m" trellis_config.wordpress_sites.each do |site_name, site| @@ -90,7 +89,7 @@ def post_up_message msg << "\n 🌱 \e[37mName:\e[33m #{site_name}\e[0m ├── 🔗 \e[37mURL:\e[33m #{site_url}\e[0m - ├── 🛠️ \e[37mAdmin:\e[33m #{site_url}/wp-admin\e[0m + ├── 🛠️ \e[37mAdmin:\e[33m #{site_url}/wp-admin\e[0m └── 📩 \e[37mMailpit:\e[33m #{site_url}:8025\e[0m " end From 4a00b5592bee762c95245e75f5415d46f1afb198 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Wed, 28 Aug 2024 10:37:03 -0400 Subject: [PATCH 6/7] Update Vagrantfile --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 4997060552..29803603a0 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -29,7 +29,7 @@ Vagrant.configure('2') do |config| config.vm.box = box config.vm.box_version = vconfig.fetch('vagrant_box_version') config.ssh.forward_agent = true - config.vm.post_up_message = post_up_message + config.vm.post_up_message = post_up_message(trellis_config) # Fix for: "stdin: is not a tty" # https://github.com/mitchellh/vagrant/issues/1673#issuecomment-28288042 From 8b00a83c4c00462b2c3054da1868b1dd62e38201 Mon Sep 17 00:00:00 2001 From: "Michael W. Delaney" Date: Wed, 28 Aug 2024 11:07:02 -0400 Subject: [PATCH 7/7] More resilient SSL checking; different emoji for spacing reasons. --- lib/trellis/vagrant.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/trellis/vagrant.rb b/lib/trellis/vagrant.rb index 8fd8cec921..accbc6ceb9 100644 --- a/lib/trellis/vagrant.rb +++ b/lib/trellis/vagrant.rb @@ -85,12 +85,12 @@ def post_up_message(trellis_config) trellis_config.wordpress_sites.each do |site_name, site| site_url = site['site_hosts'].first site_url = site_url.is_a?(Hash) ? site_url['canonical'] : site_url - site_url = site['ssl']['enabled'] ? "https://#{site_url}" : "http://#{site_url}" + site_url = site.dig('ssl', 'enabled') ? "https://#{site_url}" : "http://#{site_url}" msg << "\n 🌱 \e[37mName:\e[33m #{site_name}\e[0m - ├── 🔗 \e[37mURL:\e[33m #{site_url}\e[0m - ├── 🛠️ \e[37mAdmin:\e[33m #{site_url}/wp-admin\e[0m - └── 📩 \e[37mMailpit:\e[33m #{site_url}:8025\e[0m + ├── \e[37m🔗 URL:\e[33m #{site_url}\e[0m + ├── \e[37m🔧 Admin:\e[33m #{site_url}/wp-admin\e[0m + └── \e[37m📩 Mailpit:\e[33m #{site_url}:8025\e[0m " end end