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

Enhanced the provisioning to better adhere to VVV2 standards #2

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ This repo is to be used to set up a development site with [Varying Vagrant Vagra

## Installation

All you need to do is add this section to the `site` section of your `vvv-config.yml`
All you need to do is add this section to the `sites` section of your `vvv-custom.yml`

yoast-acf-analysis-development:
yoast-acf:
repo: https://github.com/kraftner/yoast-acf-analysis-development.git
hosts:
- yoast-acf-analysis.vvv.dev
- acf-content-analysis-for-yoast-seo.test

**Note that you can change `acf-content-analysis-for-yoast-seo.test` to any other name, if that's what you prefer.**

If you do not want to provision the default sites that come with VVV make sure to *only* have this in the `site` section.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should say sites here


For more details on configuring VVV please consult the [VVV documentation](https://varyingvagrantvagrants.org/docs/en-US/vvv-config/).

Reprovision your VVV by running `vagrant provision`. After this, ensure you run `composer install` and `yarn install` (or `npm install`) in the plugin folder before proceeding.

## Tests

### PHPUnit
Expand All @@ -25,7 +29,7 @@ The PHPUnit Tests can be run from the plugin folder with the script `composer ru

To be able to run the [Nightwatch](http://nightwatchjs.org/) browser tests you also need to have Chrome and xfvb installed:

If you want to auto-configure your VVV machine with those add the following to your `vvv-config.yml`
If you want to auto-configure your VVV machine with those add the following to your `vvv-custom.yml`

utilities:
yoast-acf-analysis-development-utilities:
Expand All @@ -36,7 +40,10 @@ If you want to auto-configure your VVV machine with those add the following to y

After that to run the tests for ACF 4 run `npm run test-acf4` inside the plugin folder.

To run the tests for ACF 5 you first need to install ACF 5 as we cannot do this automatically as it isn't a free plugin.
After you've done that you can simply run `npm run test-acf5pro`.
To run tests for ACF 5 Pro you first need to install ACF 5 Pro manually, as we cannot do this automatically due to it not being a free plugin.
After you've installed ACF 5 Pro, you can simply run `npm run test-acf5pro`.

**Note:**
If you do not want to run the browser tests with Chrome and/or in headless mode, you'll need to make changes to `nightwatch.json`, `nightwatch.conf.example.js` or `env.js` in your virtual machine.

If you do not want to run the browser tests with chrome, headless, inside your VVV machine you'll need to change some of `nightwatch.json`, `nightwatch.conf.example.js` and `env.js`. Consult the corresponding documentation on how to do that.
Consult the [corresponding documentation](http://nightwatchjs.org/gettingstarted/#settings-file) on how to do that.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
}
],
"require": {
"wecodemore/wpstarter": "~2.0",
"wpackagist-plugin/advanced-custom-fields": "^4.4",
"wpackagist-plugin/wordpress-seo": "^5.3",
"yoast/yoast-acf-analysis": "dev-develop"
Expand All @@ -37,10 +36,11 @@
"optimize-autoloader": true
},
"scripts": {
"post-install-cmd": "WCM\\WPStarter\\Setup::run",
"post-update-cmd": "WCM\\WPStarter\\Setup::run"
},
"extra": {
"wordpress-install-dir": "wp"
"installer-paths": {
"public_html/wp-content/plugins/{$name}/": ["type:wordpress-plugin"]
},
"wordpress-install-dir": "public_html"
}
}
39 changes: 18 additions & 21 deletions provision/.env.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
var childProcess = require('child_process');
var chromedriver = require('chromedriver');
var psTree = require('ps-tree');

module.exports = {
"user" : "admin",
"password" : "password",
before : function(done) {
this.chromedriverInstance = childProcess.exec('xvfb-run ' + chromedriver.path);
done();
},
after : function(done) {
if (this.chromedriverInstance != null){
psTree(this.chromedriverInstance.pid, function (err, children) {
childProcess.spawn('kill', ['-9'].concat(children.map(function (p) { return p.PID })));
});
}
done();
},
beforeEach: function( browser, done ) {
var page = browser.page.WordPressHelper();
page.login();
}
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to check back on this but there was a particular reason why I was doing it like this...I just can't remember now. Should have documented that...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I attempted to use the previous configuration, I couldn't get the tests to run at all. @moorscode found that basic configuration which did seem to do the trick, hence why I changed it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I remember now what the issue was: When using the plain chromedriver without xvfb the headless chrome wasn't properly working on any interaction with an input (something about missing keycode conversion without a window manager).
Did you try provisioning with that change and run the Nightwatch tests successfully? Maybe they have meanwhile fixed this in a recent Chrome version.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests weren't successful as logging in resulted in an immediate redirect to the login page. I don't believe that's related to this change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I've looked into this and it seems as if Chrome fixed this in the meantime, so yeah, this change is ok by now.

"user" : "admin",
"password" : "password",
before : function(done) {
chromedriver.start();

done();
},
after : function(done) {
chromedriver.stop();

done();
},
beforeEach: function( browser, done ) {
var page = browser.page.WordPressHelper();

page.login();
}
};
1 change: 0 additions & 1 deletion provision/vvv-hosts

This file was deleted.

78 changes: 61 additions & 17 deletions provision/vvv-init.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,75 @@
#!/usr/bin/env bash

# Make a database, if we don't already have one
echo -e "\nCreating database 'yoast_acf_analysis_development' (if it's not already there)"
mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS yoast_acf_analysis_development"
mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON yoast_acf_analysis_development.* TO wp@localhost IDENTIFIED BY 'wp';"
# Variables to use for proper provisioning.
DOMAIN=`get_primary_host "${VVV_SITE_NAME}".test`
DOMAINS=`get_hosts "${DOMAIN}"`
SITE_TITLE=`get_config_value 'site_title' "${DOMAIN}"`
WP_VERSION=`get_config_value 'wp_version' 'latest'`
WP_TYPE=`get_config_value 'wp_type' "single"`
DB_NAME=`get_config_value 'db_name' "${VVV_SITE_NAME}"`
DB_NAME=${DB_NAME//[\\\/\.\<\>\:\"\'\|\?\!\*-]/}

# Make a database, if we don't already have one.
echo -e "\nCreating database '${DB_NAME}' (if it's not already there)"
mysql -u root --password=root -e "CREATE DATABASE IF NOT EXISTS ${DB_NAME}"
mysql -u root --password=root -e "GRANT ALL PRIVILEGES ON ${DB_NAME}.* TO wp@localhost IDENTIFIED BY 'wp';"
echo -e "\n DB operations done.\n\n"

# Nginx Logs
mkdir -p ${VVV_PATH_TO_SITE}/log
touch ${VVV_PATH_TO_SITE}/log/error.log
touch ${VVV_PATH_TO_SITE}/log/access.log

cd ${VVV_PATH_TO_SITE}

noroot composer install

cd ${VVV_PATH_TO_SITE}/wp-content/plugins/yoast-acf-analysis
noroot composer install
noroot npm install
# Install and configure the latest stable version of WordPress
if [[ ! -f "${VVV_PATH_TO_SITE}/public_html/wp-load.php" ]]; then
echo "Downloading WordPress..."
noroot wp core download --version="${WP_VERSION}"
echo "Downloading WordPress complete"
fi

if [[ ! -d "${VVV_PATH_TO_SITE}/wp" ]]; then
cp ${VVV_PATH_TO_SITE}/provision/.env.js ${VVV_PATH_TO_SITE}/wp-content/plugins/yoast-acf-analysis/tests/js/system/.env.js
if [[ ! -f "${VVV_PATH_TO_SITE}/public_html/wp-config.php" ]]; then
echo "Configuring WordPress Stable..."
noroot wp core config --dbname="${DB_NAME}" --dbuser=wp --dbpass=wp --quiet --extra-php <<PHP
define( 'WP_DEBUG', true );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lacks

define( 'AC_YOAST_ACF_ANALYSIS_ENVIRONMENT', 'development' );

without which the testing data won't get loaded.

PHP
echo "Configuring WordPress complete"
fi

if ! $(noroot wp core is-installed); then
noroot wp core install --url=yoast-acf-analysis.vvv.dev --title="Yoast ACF Analysis Development" --admin_name=admin --admin_email="admin@local.dev" --admin_password="password" --skip-email
noroot wp plugin activate --all
# This is needed because the test relies on at least one attachment existing
noroot wp media import https://s.w.org/about/images/logos/wordpress-logo-notext-rgb.png
echo "Installing WordPress Stable..."

if [ "${WP_TYPE}" = "subdomain" ]; then
INSTALL_COMMAND="multisite-install --subdomains"
elif [ "${WP_TYPE}" = "subdirectory" ]; then
INSTALL_COMMAND="multisite-install"
else
INSTALL_COMMAND="install"
fi

noroot wp core ${INSTALL_COMMAND} --url="${DOMAIN}" --quiet --title="${SITE_TITLE}" --admin_name=admin --admin_email="admin@local.test" --admin_password="password" --skip-email

# This is needed because the test relies on at least one attachment existing
noroot wp media import https://s.w.org/about/images/logos/wordpress-logo-notext-rgb.png
echo "WordPress installation complete"

echo "Installing necessary plugins..."
cd ${VVV_PATH_TO_SITE}
noroot composer install -q
echo "Installing necessary plugins complete"

echo "Configuring Yoast ACF Analysis..."
cp ${VVV_PATH_TO_SITE}/provision/.env.js ${VVV_PATH_TO_SITE}/public_html/wp-content/plugins/yoast-acf-analysis/tests/js/system/.env.js
cp ${VVV_PATH_TO_SITE}/public_html/wp-content/plugins/yoast-acf-analysis/tests/js/system/nightwatch.conf.example.js ${VVV_PATH_TO_SITE}/public_html/wp-content/plugins/yoast-acf-analysis/tests/js/system/nightwatch.conf.js

sed -i "s#{{DOMAIN}}#http://${DOMAINS}#" "${VVV_PATH_TO_SITE}/public_html/wp-content/plugins/yoast-acf-analysis/tests/js/system/nightwatch.conf.js"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also automatically do

cd ${VVV_PATH_TO_SITE}/public_html/wp-content/plugins/yoast-acf-analysis
composer install
npm install

instead of adding this note. Without that the plugin won't init anyway because of the lack of the vendor folder.

echo "Configuring complete"

noroot wp plugin activate --all
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By installing WP without composer we now have "Hello Dolly" and "Akismet" installed. 😒
So I'd either replace this with

 noroot wp plugin activate advanced-custom-fields wordpress-seo yoast-acf-analysis

or add a

noroot wp plugin delete hello akismet

before this line.

else
echo "Updating WordPress Stable..."
cd ${VVV_PATH_TO_SITE}/public_html

noroot wp core update --version="${WP_VERSION}"
fi

sed -i "s#{{DOMAINS_HERE}}#${DOMAINS}#" "${VVV_PATH_TO_SITE}/provision/vvv-nginx.conf"
4 changes: 2 additions & 2 deletions provision/vvv-nginx.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
server {
listen 80;
listen 443 ssl;
server_name yoast-acf-analysis.vvv.dev;
root {vvv_path_to_site};
server_name {{DOMAINS_HERE}};
root {vvv_path_to_site}/public_html;

error_log {vvv_path_to_site}/log/error.log;
access_log {vvv_path_to_site}/log/access.log;
Expand Down
1 change: 1 addition & 0 deletions wp-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
path: public_html