Best way to combine Composer+Wordpress & Roots+Node+Grunt workflows?

Mark Jaquith has a couple of videos on WPTV that give a high level overview. He also has WP-Stack on Github as a model Capistrano deploy for WP. Itā€™s enough to get started and get a feel for what works and what you need to build yourself.

Iā€™m a bit concerned by his position that the media assets donā€™t need to be versioned. If the customer changes their logo and overhauls their site and the new logo is a different size, it seems like rollback without the ability to rollback the media would create appearance issues.

There are other solutions as well. One of the guys from the VVV team has Salty-WordPress, which uses SaltStack to set up something like a VVV vagrant. I looked at SaltStack long enough to determine it could be used for software deployment.

Thereā€™s also Ansible, which can do server provisioning and software deploys and requires nothing but Python and SSH on the target server. (Iā€™m exploring Ansible more because I donā€™t know Ruby and YAML is easy to writeā€“among other features.)

1 Like

Iā€™m a but curios about this aswell.
From what I gathered I should be working like this:

  • Develop locally and commit to develop branch on remote repo (bitbucket in my case).

  • Pull the dev branch to my online dev enviroment, which I intend to use to
    keep the client up to date with the current status.

  • When project is nearly done, merge develop with another branch, called stage branch this branch is then pulled into the stage enviroment. Stage is on the clients server. In this scenario the client will start to replace my dummy content with the real deal, this is the first time the clientā€™s allowed to login and make those changes themselves.

Now here is where I think it becomes tricky. Because ideally I will let the client work with the stage enviroment before itā€™s moved onto production. Thus Iā€™d like to pull the db from the stage to my local setup regularly so that I have live media and text content so that my dev enviroment is as close to the real stuff as possible. But since I wonā€™t be version controlling the media, this wonā€™t work. So how should I do it?

I think for stage to development, you could just copy the database (dump, copy dump, load, use a search and replace script to fix links). Hereā€™s one solution http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ that Iā€™ve tried. There are others I havenā€™t tried. WP-Stack seems to script production to stage minus the search and replace (see namespace :db in lib/tasks.rb). You could use the same process for stage to development. (Yes, itā€™s Ruby, but the important parts are shell commands.)

The bigger challenge is moving to production. Ideally, all changes should be done with SQL scripts so theyā€™re repeatable, controllable, and versionable. (Certainly true if youā€™re talking 12-factor.) At initial load, that isnā€™t a big deal (production database is empty). The second load, though, you have to find what changed and script the changes. (Iā€™m still trying to sort out how you make that work without a lot of manual intervention. There are some database compare tools out there that should help, but I havenā€™t found the ideal answer.)

Also, would you really let clients develop in staging? I thought staging was supposed to be user acceptance testing, which should mean no changes to staging that donā€™t go through development and unit testing first. You might have an exception case for a blog segment of the site, but the non-blog site should be controlled. If clients are creating content, shouldnā€™t that should be in another development environment with changes versioned into a script and pushed to UAT-staging?

As far as media, I think itā€™s completely possible for media to break a site or at least make it look horrible. If you canā€™t rollback to the previous version of media, youā€™re stuck. I think you have to version media somehow. Maybe not git. Maybe the deployment preparation process identifies changed files and puts them somewhere the deploy process can find it (and can backup the corresponding files), but some kind of packaging and versioning so you can revert in a crisis.

1 Like

Hm, not sure. Iā€™m new to all this.
But would it be better to bring in the client at production? I rather let them add all their content, rather than having me organize that for them. Itā€™s also a good way for them to learn using Wordpress.

I guess you could move up to production and protect the site with htpasswd while theyā€™re add their content. But then you wonā€™t be able to have a placeholder site at the same time (if adding content takes along time, thatā€™s not so good).

The situation Iā€™m envisioning is four environments. Vagrant for the web developer, Vagrant or content-dev.xyz.com for clients developing content, staging.xyz.com for user acceptance testing, xyz.com for production. The client-dev site can be a vhost on the same site as staging if needed. The trick to making that works is some kind of tool to package the database changes and clean up revisions, or work in progress before moving to staging and production. (This is one of those areas I want to research more, but havenā€™t gotten to yet.)

Many sites I see in the gallery look like they have rarely changing content. In this case, thereā€™s no reason the client couldnā€™t provide the copy and the developer install that copy in the site (create posts/pages). If thereā€™s a blog/news component or other dynamic aspect, itā€™s possible to identify and isolate that data and manage it appropriately. If the client wants to edit copy directly, see paragraph above.

The client selling point is control and security. See [HMVā€™s Twitter debacle] (Inside HMVā€™s Twitter Disaster: What went wrong (and how to keep your company safe)) and imagine someone doing something similar on the clientā€™s site. That isnā€™t an issue if youā€™re dealing with a sole-proprietor client, but if the client organization has several employees and someone other than the owner/CEO is doing most of the site management, the owner/CEO or his highly trusted designee should check content before it goes into production and should want content migration to happen in a way that it canā€™t be changed after s/he approves it.

The same rationale raises the question, do you really want people to be able to comment on your pages and posts?

EDIT: Yes, WP has a contributor/approver system. Iā€™m still not sure I would want to see edits happen in production if I could find an efficient way to extract the data and move a script instead. Some long-winded, non-copywriter decides to rewrite a finely tuned 50-word paragraph into a 750-word babble that breaks the flow of the site and SEO. (My real job is in a very risk-aware organization where nothing goes into production without careful controls, so I tend to be paranoid about this kind of stuff.)

WP-Stack was great when it first came out but itā€™s a bit behind the times. The way he uses Capistrano isnā€™t great and itā€™s also using the old v2 version. Capistrano v3 is much simpler, faster, and better. Thereā€™s also nothing Rails specific in the core Gem anymore which is great.

The ā€œstackā€ that weā€™re working on is Chef based but Iā€™ve also been thinking of switching it to Ansible. Itā€™s much simpler and easier to use especially if you donā€™t have Ruby experience.

My main interest in WP-Stack (after the Ruby nightmare @_@) was sorting out what it did so I could replicate it in something else.

I know enough about Ansible to be dangerous. Iā€™m building a set of roles to prepare a WP-ready web server on Debian based on VVV in my evening research time. Parts of that could probably be easily modified to align with your Chef.

My real job gives me vacation, and I have most of it scheduled in December, so I should have some time on my hands that I can throw toward helping out with an Ansible experiment if youā€™re interested.

That could work. Not exactly sure what the plan is right now since the Chef stuff is basically done. Might be a future project to switch over.

This has to be my favorite topic in Roots by far. Learning so much just in 1 topic itā€™s crazy! Not to mention the awesomeness of Roots itself.

And then I have to mention Bootstrap. WordPress. On and on and on. OSS is too awesome.

Iā€™m nowhere near you guys with this workflow and itā€™s been great to learn a lot from this topic. Canā€™t wait for @swalkinshaw updates about Caps. I canā€™t do much to contribute but I do use Pagodabox.com for most of my clients. If thereā€™s anyone using that (or interested) I can write and share my QuickStart recipe and some stuffs I learn the hard way working with PB. Iā€™ll say those who use WPengine and love the git-based workflow might consider PagodaBox as one of the alternatives for their tools.

Canā€™t wait to see the wp-stack but just what Iā€™m using at the moment:
wp-migrate-db-pro plugin to move the database around
Using grunt ftpush to deploy the project (only the appropriate folders) to my server, this stores the changes a bit like git so it only pushes up new changes.

Probably not the most optimum setup but it works pretty well. Going to look into ansible now though.

@swalkinshaw Hi Scott, I was wondering how the new screencast is comming along. I have a new website pending and would love to use what you can teach us for the new deployment.

Thanks again for all your work,

Mauro

By the end of this week I promise (weekend)! Finally have a good 4-5 days of more time to finish it.

2 Likes

For those waiting on the screencast, Iā€™m 90% done and it looks like Iā€™ll break my promise a bit but the screencast should be up in the next day or two. Unfortunately itā€™s always the editing and final publishing that take the longest :frowning:

2 Likes

Screencast is finally out! http://roots.io/screencasts/deploying-wordpress-with-capistrano/

Sorry for the long wait but making these screencasts is actually pretty time consuming! Iā€™ll probably start a separate thread for feedback/questions about it.

2 Likes

Awesome stuffs gonna get it when I get back home! Canā€™t wait!

Iā€™ve made a thread dedicated to the screencast/general Capistrano talk here: Deploying WordPress with Capistrano screencast

Keeping databases in sync in my opinion is one of the more difficult challenges to solve, yet least talked about on forums about deployment. After a ton of different approaches, hereā€™s what I recommend:

  1. WP Migrate DB Pro If youā€™re a WP developer, itā€™s one of the best ways to spend $99. It is SO easy to push and pull databases between local, dev, prod, etc., including updating URLs that have been serialized in widgets. You can push the entire db, or select which tables. This helps if you simply update the wp_options table or wp_posts/wp_postmeta. The only downside is that currently you need to run it through a browser in the WP admin, but they are potentially working on a command line solution. They also have a beta add-on for keeping media files in sync, due out in the main plugin soon.

  2. The next best option is to set up wp-cli. This allows you to run WordPress commands via the command line, and you can hook in and create your own. It has a built in search-replace function to update URLs & serialized data (it actually used the interconnectit search-and-replace mentioned elsewhere here). What I do to prepare the database is to use the search-replace function to update the URLs, export it via wp-cli, and then take that dump.sql and import it into the target database somehow. Easiest is via phpMyAdmin or Sequel Pro. OR, I have also written simple scripts that SCP the dump to the server and then import it via mysql command line.

  3. Use interconnectit search-and-replace in your project. This has a browser base or CLI option. Iā€™ve used the CLI as a part of a custom deploy bash script.

  4. Use WP Engine. They have a push button production to/from staging setup which also allows for full or table-based db migration. Downside is that you still need to do one of the other options above for deployment to/from local. And, if you want to do any of the great Capistrano kind of stuff mentioned in this post, you are out of luck with WP Engine since they do not allow SSH access.

2 Likes

Hey merchantguru,

Wish I read this post before i posted to the capistrano screencast thread.

I too am looking to solve the database issue.

Option 2 sounds like the best plan, although i just use sed for find and replace, works a treat.

For all the love (or addiction) I have for Railsless Capistrano it always seemed wrong. Better to stand on the shoulders of giants: http://tech.toptable.co.uk/blog/2013/08/08/grunt-your-deployments-too/

I realize Iā€™m super late to the game on this but just thought youā€™d find it interesting. Iā€™ll be giving this a whirl in an upcoming Roots site.

1 Like

Keep in mind that Capistrano v3 was rewritten and no longer has anything Rails specific in it. You actually need to require Rails gems for it if you want. v3 is generally must better, simpler, and faster.