From 78bce85134c3f86b7d35f1421a5131912b6cca61 Mon Sep 17 00:00:00 2001 From: tomjn Date: Sun, 27 Dec 2020 11:55:40 +0000 Subject: [PATCH 1/4] refactor config detection and use a /srv/vvv folder instead --- provision/provision-helpers.sh | 19 +++++++++++---- provision/provision-site.sh | 2 -- provision/provision.sh | 42 +++++++++++++++------------------ provision/provisioners.sh | 4 ++-- provision/tests/provisioners.sh | 8 +++---- 5 files changed, 39 insertions(+), 36 deletions(-) diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh index 23827ef17..e638a2a0d 100644 --- a/provision/provision-helpers.sh +++ b/provision/provision-helpers.sh @@ -17,11 +17,20 @@ export BLUE="\033[0;38;5;4m" # 33m" export PURPLE="\033[0;38;5;5m" # 129m" export CRESET="\033[0m" +configs=( + /srv/vvv/config.yml + /vagrant/config.yml + /vagrant/vvv-config.yml +) +VVV_CONFIG=/srv/vvv/config.yml +for item in ${configs[*]}; do + if [[ -f $item ]]; then + VVV_CONFIG=$item + break + fi +done + -VVV_CONFIG=/vagrant/vvv-custom.yml -if [[ -f /vagrant/config.yml ]]; then - VVV_CONFIG=/vagrant/config.yml -fi export VVV_CONFIG export VVV_CURRENT_LOG_FILE="" @@ -158,7 +167,7 @@ export -f network_check # # @arg $1 string name of the provisioner function log_to_file() { - local date_time=$(cat /vagrant/provisioned_at) + local date_time=$(cat /srv/vvv/provisioned_at) local logfolder="/var/log/provisioners/${date_time}" local logfile="${logfolder}/${1}.log" mkdir -p "${logfolder}" diff --git a/provision/provision-site.sh b/provision/provision-site.sh index f0d575782..9d55f52e6 100644 --- a/provision/provision-site.sh +++ b/provision/provision-site.sh @@ -26,8 +26,6 @@ VVV_HOSTS="" SUCCESS=1 -VVV_CONFIG=/vagrant/config.yml - . "/srv/provision/provisioners.sh" # @description Takes 2 values, a key to fetch a value for, and an optional default value diff --git a/provision/provision.sh b/provision/provision.sh index 6fef90e34..83cb62e11 100755 --- a/provision/provision.sh +++ b/provision/provision.sh @@ -9,30 +9,31 @@ . "/srv/config/bash_aliases" # cleanup -mkdir -p /vagrant -rm -rf /vagrant/failed_provisioners -mkdir -p /vagrant/failed_provisioners +mkdir -p /srv/vvv +if [[ ! -d /vagrant ]]; then + ln -s /srv/vvv /vagrant +fi +rm -rf /srv/vvv/failed_provisioners +mkdir -p /srv/vvv/failed_provisioners -rm -f /vagrant/provisioned_at -rm -f /vagrant/version -rm -f /vagrant/vvv-custom.yml -rm -f /vagrant/config.yml +rm -f /srv/vvv/provisioned_at +rm -f /srv/vvv/version +rm -f /srv/vvv/vvv-custom.yml +rm -f /srv/vvv/config.yml -touch /vagrant/provisioned_at -echo $(date "+%Y.%m.%d_%H-%M-%S") > /vagrant/provisioned_at +touch /srv/vvv/provisioned_at +echo $(date "+%Y.%m.%d_%H-%M-%S") > /srv/vvv/provisioned_at # copy over version and config files -cp -f /home/vagrant/version /vagrant -cp -f /srv/config/config.yml /vagrant - -sudo chmod 0644 /vagrant/config.yml -sudo chmod 0644 /vagrant/version -sudo chmod 0644 /vagrant/provisioned_at +cp -f /home/vagrant/version /srv/vvv +cp -f /srv/config/config.yml /srv/vvv -# change ownership for /vagrant folder -sudo chown -R vagrant:vagrant /vagrant +sudo chmod 0644 /srv/vvv/config.yml +sudo chmod 0644 /srv/vvv/version +sudo chmod 0644 /srv/vvv/provisioned_at -export VVV_CONFIG=/vagrant/config.yml +# change ownership for /srv/vvv folder +sudo chown -R vagrant:vagrant /srv/vvv # initialize provisioner helpers a bit later . "/srv/provision/provisioners.sh" @@ -55,9 +56,6 @@ export VVV_PACKAGE_LIST=() . "/srv/provision/core/wp-cli/provision.sh" . "/srv/provision/core/phpcs/provision.sh" -### SCRIPT -#set -xv - vvv_hook init if ! network_check; then @@ -79,7 +77,5 @@ vvv_hook after_packages vvv_info " * Finalizing" vvv_hook finalize -#set +xv # And it's done - provisioner_success diff --git a/provision/provisioners.sh b/provision/provisioners.sh index 4e889d7d0..133eb1d9d 100644 --- a/provision/provisioners.sh +++ b/provision/provisioners.sh @@ -18,7 +18,7 @@ VVV_PROVISIONER_RUNNING="" # @arg $1 string Name of the provisioner function provisioner_begin() { VVV_PROVISIONER_RUNNING="${1:-${FUNCNAME[1]}}" - touch "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" + touch "/srv/vvv/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" log_to_file "provisioner-${VVV_PROVISIONER_RUNNING}" vvv_success " ▷ Running the '${VVV_PROVISIONER_RUNNING}' provisioner..." start_seconds="$(date +%s)" @@ -33,7 +33,7 @@ function provisioner_end() { local elapsed="$(( end_seconds - start_seconds ))" if [[ $PROVISION_SUCCESS -eq "0" ]]; then vvv_success " ✔ The '${VVV_PROVISIONER_RUNNING}' provisioner completed in ${elapsed} seconds." - rm -f "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" + rm -f "/srv/vvv/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}" else vvv_error " ! The '${VVV_PROVISIONER_RUNNING}' provisioner ran into problems, check the full log for more details! It completed in ${elapsed} seconds." fi diff --git a/provision/tests/provisioners.sh b/provision/tests/provisioners.sh index b2418cd5a..a8c762eb9 100644 --- a/provision/tests/provisioners.sh +++ b/provision/tests/provisioners.sh @@ -155,10 +155,10 @@ function provision_main() { vvv_run_provisioner /srv/provision/provision.sh fi - # refresh VVV_CONFIG, as the main provisioner actually creates the /vagrant/config.yml - VVV_CONFIG=/vagrant/vvv-custom.yml - if [[ -f /vagrant/config.yml ]]; then - VVV_CONFIG=/vagrant/config.yml + # refresh VVV_CONFIG, as the main provisioner actually creates the /srv/vvv/config.yml + VVV_CONFIG=/srv/vvv/vvv-custom.yml + if [[ -f /srv/vvv/config.yml ]]; then + VVV_CONFIG=/srv/vvv/config.yml fi export VVV_CONFIG } From eba9508f681713c4b0de31d11574768cc528ba9a Mon Sep 17 00:00:00 2001 From: tomjn Date: Sun, 27 Dec 2020 12:24:30 +0000 Subject: [PATCH 2/4] more config location changes --- Vagrantfile | 4 ++-- provision/provision-helpers.sh | 2 -- provision/tests/provisioners.sh | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index 6cf33f5da..a9f0c0713 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -554,7 +554,7 @@ Vagrant.configure('2') do |config| # Disable the default synced folder to avoid overlapping mounts config.vm.synced_folder '.', '/vagrant', disabled: true - config.vm.provision 'file', source: "#{vagrant_dir}/version", destination: '/home/vagrant/version' + config.vm.provision 'file', source: "#{vagrant_dir}/version", destination: '/srv/vvv/version' # /srv/database/ # @@ -730,7 +730,7 @@ Vagrant.configure('2') do |config| unless Vagrant::Util::Platform.windows? if Process.uid == 0 # the VM should know if vagrant was ran by a root user or using sudo - config.vm.provision "flag-root-vagrant-command", type: 'shell', keep_color: true, inline: "mkdir -p /vagrant && touch /vagrant/provisioned_as_root" + config.vm.provision "flag-root-vagrant-command", type: 'shell', keep_color: true, inline: "mkdir -p /srv/vvv && touch /srv/vvv/provisioned_as_root" end end diff --git a/provision/provision-helpers.sh b/provision/provision-helpers.sh index e638a2a0d..1cbe45259 100644 --- a/provision/provision-helpers.sh +++ b/provision/provision-helpers.sh @@ -30,8 +30,6 @@ for item in ${configs[*]}; do fi done - - export VVV_CONFIG export VVV_CURRENT_LOG_FILE="" diff --git a/provision/tests/provisioners.sh b/provision/tests/provisioners.sh index a8c762eb9..489a5a460 100644 --- a/provision/tests/provisioners.sh +++ b/provision/tests/provisioners.sh @@ -156,9 +156,17 @@ function provision_main() { fi # refresh VVV_CONFIG, as the main provisioner actually creates the /srv/vvv/config.yml - VVV_CONFIG=/srv/vvv/vvv-custom.yml - if [[ -f /srv/vvv/config.yml ]]; then - VVV_CONFIG=/srv/vvv/config.yml - fi + configs=( + /srv/vvv/config.yml + /vagrant/config.yml + /vagrant/vvv-config.yml + ) + VVV_CONFIG=/srv/vvv/config.yml + for item in ${configs[*]}; do + if [[ -f $item ]]; then + VVV_CONFIG=$item + break + fi + done export VVV_CONFIG } From 13fc070a08ee2757c8e6a5c55221f6e1236555fe Mon Sep 17 00:00:00 2001 From: tomjn Date: Sun, 27 Dec 2020 12:24:44 +0000 Subject: [PATCH 3/4] update the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc1dfe58e..518a3f60f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ permalink: /docs/en-US/changelog/ * Minor refactors and colours added to the main provisioner * Improved output of backup and import scripts * SHDocs added to core provisioners +* A new `/srv/vvv` folder for files created inside the VM related to provisioning ### Bug Fixes * Fixed the user of `vvv_warn` `vvv_success` `vvv_error` and `vvv_info` outside of provisioners From 13b5a0ffebb9b04903a234ea31a4aa697a4beaae Mon Sep 17 00:00:00 2001 From: Tom J Nowell Date: Sat, 2 Jan 2021 20:02:57 +0000 Subject: [PATCH 4/4] make sure that /srv/vvv exists before copying /srv/vvv/version --- Vagrantfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Vagrantfile b/Vagrantfile index a9f0c0713..f17a54fad 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -554,6 +554,7 @@ Vagrant.configure('2') do |config| # Disable the default synced folder to avoid overlapping mounts config.vm.synced_folder '.', '/vagrant', disabled: true + config.vm.provision "setup-srv-vvv", type: 'shell', keep_color: true, inline: "mkdir -p /srv/vvv" config.vm.provision 'file', source: "#{vagrant_dir}/version", destination: '/srv/vvv/version' # /srv/database/