Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1635 from Varying-Vagrant-Vagrants/tomjn-site-pro…
…vision-warnings

Site Provisioner Improvements
  • Loading branch information
tomjn committed Sep 20, 2018
2 parents 1860077 + c3ee9d1 commit 449d7f7
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 31 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,31 @@ title: Changelog
permalink: /docs/en-US/changelog/
---

## 2.3.1 ( WIP 2018 )

### Enhancements

* Support for git-lfs
* Replaced MailCatcher with MailHog
* Network tests now use Launchpad instead of Google.com
* Improved Splash screen and warning messages
* Improved the default vvv config to prevent confusion
* Improved the default prompt when using `vagrant ssh`
* Improved the welcome message when you SSH in
* If provisioning fails, VVV now aborts instead of continuing and failing
* Apt-get keys are now bundled with the VM

### Bug Fixes

* VVV will now warn you when you add a site without a site template
* Fixed issues wrapping bash prompt colours on some environments
* Fixed an issue with dpkg failures

### Deprecations

- VVV will now search 3 folders down for vvv-init.sh vvv-hosts and vvv-nginx.conf not 4 folders
- Ruby was replaced with GoLang, and MailCatcher removed for new users

## 2.2.1 (May, 2018)

Note that to update to 2.2.1, you must remove the Vagrant triggers plugin and install Vagrant 2.1
Expand Down
97 changes: 66 additions & 31 deletions provision/provision-site.sh
Expand Up @@ -46,6 +46,31 @@ is_utility_installed() {
return 1
}

function vvv_provision_site_nginx() {
SITE_NAME=$1
SITE_NGINX_FILE=$2
DEST_NGINX_FILE=${SITE_NGINX_FILE//\/srv\/www\//}
DEST_NGINX_FILE=${DEST_NGINX_FILE//\//\-}
DEST_NGINX_FILE=${DEST_NGINX_FILE/%-vvv-nginx.conf/}
DEST_NGINX_FILE="vvv-auto-${DEST_NGINX_FILE}-$(md5sum <<< "$SITE_NGINX_FILE" | cut -c1-32).conf"
VVV_HOSTS=$(get_hosts)
# We allow the replacement of the {vvv_path_to_folder} token with
# whatever you want, allowing flexible placement of the site folder
# while still having an Nginx config which works.
#env
DIR="$(dirname "$SITE_NGINX_FILE")"
sed "s#{vvv_path_to_folder}#$DIR#" "$SITE_NGINX_FILE" > "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"
sed -i "s#{vvv_path_to_site}#$VM_DIR#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"
sed -i "s#{vvv_site_name}#$SITE#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"
sed -i "s#{vvv_hosts}#$VVV_HOSTS#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"
sed -i "s#{upstream}#$NGINX_UPSTREAM#" "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"

# Resolve relative paths since not supported in Nginx root.
while grep -sqE '/[^/][^/]*/\.\.' "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"; do
sed -i 's#/[^/][^/]*/\.\.##g' "/etc/nginx/custom-sites/${DEST_NGINX_FILE}"
done
}

if [[ true == $SKIP_PROVISIONING ]]; then
REPO=false
fi
Expand All @@ -61,41 +86,50 @@ if [[ false != "${REPO}" ]]; then
noroot git pull origin ${BRANCH} -q
noroot git checkout ${BRANCH} -q
fi
else
echo "The site: '${SITE}' does not have a site template, assuming custom provision/vvv-init.sh and provision/vvv-nginx.conf"
if [[ ! -d ${VM_DIR} ]]; then
echo "Error: The '${SITE}' has no folder, VVV does not create the folder for you, or set up the Nginx configs. Use a site template or create the folder and provisioner files, then reprovision VVV"
fi
fi

if [[ false == "${SKIP_PROVISIONING}" ]]; then
# Look for site setup scripts
find ${VM_DIR} -maxdepth 4 -name 'vvv-init.sh' -print0 | while read -d $'\0' SITE_CONFIG_FILE; do
DIR="$(dirname "$SITE_CONFIG_FILE")"
(
cd "$DIR"
source vvv-init.sh
)
done


if [[ -d ${VM_DIR} ]]; then
# Look for Nginx vhost files, symlink them into the custom sites dir
for SITE_CONFIG_FILE in $(find ${VM_DIR} -maxdepth 4 -name 'vvv-nginx.conf'); do
DEST_CONFIG_FILE=${SITE_CONFIG_FILE//\/srv\/www\//}
DEST_CONFIG_FILE=${DEST_CONFIG_FILE//\//\-}
DEST_CONFIG_FILE=${DEST_CONFIG_FILE/%-vvv-nginx.conf/}
DEST_CONFIG_FILE="vvv-auto-$DEST_CONFIG_FILE-$(md5sum <<< "$SITE_CONFIG_FILE" | cut -c1-32).conf"
VVV_HOSTS=$(get_hosts)
# We allow the replacement of the {vvv_path_to_folder} token with
# whatever you want, allowing flexible placement of the site folder
# while still having an Nginx config which works.
DIR="$(dirname "$SITE_CONFIG_FILE")"
sed "s#{vvv_path_to_folder}#$DIR#" "$SITE_CONFIG_FILE" > "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"
sed -i "s#{vvv_path_to_site}#$VM_DIR#" "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"
sed -i "s#{vvv_site_name}#$SITE#" "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"
sed -i "s#{vvv_hosts}#$VVV_HOSTS#" "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"
sed -i "s#{upstream}#$NGINX_UPSTREAM#" "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"

# Resolve relative paths since not supported in Nginx root.
while grep -sqE '/[^/][^/]*/\.\.' "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"; do
sed -i 's#/[^/][^/]*/\.\.##g' "/etc/nginx/custom-sites/${DEST_CONFIG_FILE}"
# Look for site setup scripts
if [[ -f "${VM_DIR}/.vvv/vvv-init.sh" ]]; then
( cd "${VM_DIR}/.vvv" && source vvv-init.sh )
elif [[ -f "${VM_DIR}/provision/vvv-init.sh" ]]; then
( cd "${VM_DIR}/provision" && source vvv-init.sh )
elif [[ -f "${VM_DIR}/vvv-init.sh" ]]; then
( cd "${VM_DIR}" && source vvv-init.sh )
else
find ${VM_DIR} -maxdepth 3 -name 'vvv-init.sh' -print0 | while read -d $'\0' SITE_CONFIG_FILE; do
DIR="$(dirname "$SITE_CONFIG_FILE")"
(
cd "$DIR"
source vvv-init.sh
)
done
done
fi

# Look for Nginx vhost files, symlink them into the custom sites dir
if [[ -f "${VM_DIR}/.vvv/vvv-nginx.conf" ]]; then
vvv_provision_site_nginx $SITE "${VM_DIR}/.vvv/vvv-nginx.conf"
elif [[ -f "${VM_DIR}/provision/vvv-nginx.conf" ]]; then
vvv_provision_site_nginx $SITE "${VM_DIR}/provision/vvv-nginx.conf"
elif [[ -f "${VM_DIR}/vvv-nginx.conf" ]]; then
vvv_provision_site_nginx $SITE "${VM_DIR}/vvv-nginx.conf"
else
NGINX_CONFIGS=$(find ${VM_DIR} -maxdepth 3 -name 'vvv-nginx.conf');
if [[ -z $results ]] ; then
echo "Warning: No nginx config was found, VVV will not know how to serve this site"
else
for SITE_CONFIG_FILE in $NGINX_CONFIGS; do
vvv_provision_site_nginx $SITE $SITE_CONFIG_FILE
done
fi
fi

# Parse any vvv-hosts file located in the site repository for domains to
# be added to the virtual machine's host file so that it is self aware.
Expand All @@ -120,7 +154,8 @@ if [[ false == "${SKIP_PROVISIONING}" ]]; then
echo " * Added $line from ${VVV_CONFIG}"
fi
done

service nginx restart
fi
service nginx restart
fi

0 comments on commit 449d7f7

Please sign in to comment.