Site setup, development environment and deploy tooling for WordPress VIP Go:
- Uses Composer for adding project dependencies, including plugins and themes.
- Uses Composer autoloader for using any of the popular PHP packages anywhere in the codebase.
- Includes a local development environment based on Docker with support for PHP Xdebug and a mail catcher.
- Includes automated build and deploy pipelines to WordPress VIP Go using Travis CI.
- PHP 7.2 or higher
- Composer
- Node.js version 12
- Docker with Docker Compose
- rsync for deployments
The following configuration must be requested from VIP Go to use this site repository:
- Deployments from
*-built
branches such asmaster-built
anddevelop-built
. - Staging environment tracking the
develop-built
branch.
We suggest using Homebrew on macOS or Chocolatey for Windows to install the project dependencies.
brew install git php composer node@12 mkcert
# Homebrew < 2.6.0
brew cask install docker
# Homebrew >= 2.6.0
brew install --cask docker
This repository includes a list of suggested extensions for the Visual Studio Code editor and Xdebug support in the .vscode
directory.
A user-friendly Git client such as GitHub Desktop or Tower enables smaller commits and simplifies merge conflict resolution.
- Project plugins and themes can be added as Composer dependencies or manualy to this repository under
plugins/your-plugin
andthemes/your-theme
. - Composer dependencies are placed under
plugins/vendor
since it has to be in the same location relative to the project root (which is not the case forvip-config
which is mapped to the WP root directory on the server). - Composer autoloader
plugins/vendor/autoload.php
is included inpublicvip-config/vip-config.php
.
Important: This section can be deleted once you've completed the initial setup from the VIP Go Site template.
-
Ensure that VIP has configured the site to deploy from the
*-built
branches. -
Create a fresh Git repository from this reference repository:
composer create-project xwp/vip-go-site --stability dev
-
Add your theme and plugins as Composer dependencies:
composer require your/theme your/plugin another/plugin
or by manually copying them to
themes
orplugins
. Remember to start tracking those directories by excluding them inthemes/.gitignore
andplugins/.gitignore
. -
Add the VIP Go upstream repository as another remote to this repository locally and force-push the current
master
to that upstream repository to override themaster
branch with this. Do the same for thedevelop
branch.
-
Clone this repository:
git clone git@github.com:wpcomvip/example.git
-
Move into the project directory:
cd example
-
Install the project dependencies:
npm install
-
Start the development environment using Docker:
npm run start
and
npm run stop
to stop the virtual environment at any time. Runnpm run start-debug
to start the environment in debug mode where all output from containers is displayed. Runnpm run stop-all
to stop all active Docker containers in case you're running into port conflicts. -
Install the local WordPress multisite environment:
npm run setup
with the configuration from
local/public/wp-cli.yml
. -
Visit local.devgo.vip to view the development environment. WordPress username
devgo
and passworddevgo
. -
Visit mail.local.devgo.vip to view all emails sent by WordPress.
The local development environment uses a self-signed SSL sertificate for HTTPS so the "Your connection is not private" error can be ignored to visit the site.
-
Setup the local environment environment as described in the "Setup" section above.
-
Create a Git branch such as
feature/name
orfix/vertical-scroll
when you start working on a feature or a bug fix. Commit your work to that branch until it's ready for quality assurance and testing. -
Open a pull request from your feature branch to the
develop
branch or the staging environment. -
Review any feedback from the automated checks. Note that your local environment is configured to automatically check for any issues before each commit so there should be very few issues if you commit early and often.
-
Merge the feature branch into
develop
on GitHub if all check pass. The automated Travis CI workflow (see the "Deployments" section below for details) will deploy it to thedevelop-built
branch. -
Test your feature on the VIP Go staging server. Open a new pull request from the same feature branch to
develop
if any fixes or changes are necessary. -
Once the feature is ready for production, open a new pull request from the same feature branch to the
master
branch. -
Ensure that all automated checks pass and merge in the pull request. The automated Travis CI workflow will deploy it to the
master-build
branch.
Add new themes and plugins as Composer dependencies:
composer require your/theme your/plugin another/plugin
or manually copy them to themes
, plugins
or client-mu-plugins
directories. Remember to start tracking the directories copied manually by excluding them from being ignored in themes/.gitignore
and plugins/.gitignore
.
Use client-mu-plugins/plugin-loader.php
to force-enable certain plugins.
To update plugins and themes added as Composer dependencies, use composer install package/name
or composer install --dev package/name
where package/name
is the name of the plugin or theme package. Be sure to commit the updated composer.json
with composer.lock
to the GitHub repository.
For manually installed plugins and themes replace the directory with the updated set of files and commit them to the GitHub repository.
We use Docker containers to replicate the VIP Go production environment with all VIP dependencies added as Composer packages and mapped to specific directories inside the containers as defined in docker-compose.yml
.
Requests to port 80 of the container host are captured by an Nginx proxy container that routes all requests to the necessary service container based on the HTTP host name.
Use VaultPress to download the database data from the production environment.
-
Run
npm run cli -- wp db export
to export and backup the database of your local development environment which will place a file likewordpress-2020-03-04-448b132.sql
in thelocal/public/wp
directory. -
Run
npm run cli -- wp db import export.sql
to importlocal/public/wp/export.sql
into your local development environment. Runcat export/*.sql > combined.sql
to combine all.sql
files in theexport
directory into onecombined.sql
file for quicker import (useful for working with exports from VaultPress). -
Run
npm run cli -- bash -c "pv import.sql | wp db query"
to import a large database filelocal/public/wp/import.sql
while monitoring the progress withpv
which is bundled with the WordPress container. Thebash -c
prefix allows us to run multiple commands inside the container without affecting the mainnpm run cli
command.
We use npm
as the canonical task runner for things like linting files and creating release bundles. Composer scripts (defined in composer.json
) are used only for PHP related tasks and they have a wrapper npm script in package.json
for consistency with the rest of the registered tasks.
-
npm run start
andnpm run stop
to start and stop the local development environment. Runnpm run start-debug
to start the environment in debug mode where all output from containers is displayed. Runnpm run stop-all
to stop all active Docker containers in case you're running into port conflicts. Runnpm run stop -- --volumes
to stop the project containers and delete the database data volume. -
npm run lint
to check source code against the defined coding standards. -
npm run cli -- wp help
wherewp help
is any command to run inside the WordPress docker container. For example, runnpm run cli -- wp plugin list
to list all of the available plugins ornpm run cli -- composer update
to update the Composer dependencies using the PHP binary in the container instead of your host machine. Runnpm run cli -- wp user create devgo local@devgo.vip --role=administrator --user_pass=devgo
to create a new administrator user withdevgo
as username and password. -
npm run vip
to run VIP CLI commands on staging and production environments.
The deployment process always starts from the same clean state which enables reproducable builds accross different environments such as local development machines and continuous integration services.
Deployments to the VIP Go upstream repository are handled automatically by the Travis CI build process after a feature branch is merged into master
for production or develop
for staging.
The Travis CI process (see .travis.yml
) checks the code against the VIP coding standards, builds the release bundle and pushes the changes to the master-built
branch for production or develop-built
for staging deployment.
Internally it runs the local/scripts/deploy.sh
script which does a clean checkout of the deploy source branch to local/deploy/src
, runs the build process and copies the project files with the release artifects to deploy/dist
using rsync
. It then commits the changes to the matching *-built
branch which is then imported by the VIP Go servers.
⏳Check the Travis CI dashboard to monitor the progress of the automated deployments and check the NewRelic reports for any issues or errors.