Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add /srv/vvv #2328

Draft
wants to merge 7 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( #2328 )
* Improved PHP configuration file installation

### Bug Fixes
Expand Down
4 changes: 2 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
#
Expand Down Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ export BLUE="\033[0;38;5;4m" # 33m"
export PURPLE="\033[0;38;5;5m" # 129m"
export CRESET="\033[0m"


VVV_CONFIG=/vagrant/vvv-custom.yml
if [[ -f /vagrant/config.yml ]]; then
VVV_CONFIG=/vagrant/config.yml
fi
configs=(
tomjn marked this conversation as resolved.
Show resolved Hide resolved
/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
export VVV_CURRENT_LOG_FILE=""
Expand Down Expand Up @@ -158,7 +165,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}"
Expand Down
2 changes: 0 additions & 2 deletions provision/provision-site.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 19 additions & 23 deletions provision/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -79,7 +77,5 @@ vvv_hook after_packages
vvv_info " * Finalizing"
vvv_hook finalize

#set +xv
# And it's done

provisioner_success
4 changes: 2 additions & 2 deletions provision/provisioners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>'${VVV_PROVISIONER_RUNNING}'</b><success> provisioner...</success>"
start_seconds="$(date +%s)"
Expand All @@ -33,7 +33,7 @@ function provisioner_end() {
local elapsed="$(( end_seconds - start_seconds ))"
if [[ $PROVISION_SUCCESS -eq "0" ]]; then
vvv_success " ✔ The <b>'${VVV_PROVISIONER_RUNNING}'</b><success> provisioner completed in </success><b>${elapsed}</b><success> seconds.</success>"
rm -f "/vagrant/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}"
rm -f "/srv/vvv/failed_provisioners/provisioner-${VVV_PROVISIONER_RUNNING}"
else
vvv_error " ! The <b>'${VVV_PROVISIONER_RUNNING}'</b><error> provisioner ran into problems, check the full log for more details! It completed in <b>${elapsed}</b><error> seconds."
fi
Expand Down
18 changes: 13 additions & 5 deletions provision/tests/provisioners.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ 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
fi
# refresh VVV_CONFIG, as the main provisioner actually creates the /srv/vvv/config.yml
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
}