Moving to a Faster and Safer Deployment Workflow with Grunt and the WP-CLI tools.
The presentation will discuss my grunt.js and WP CLI deployment flow, just one part of the full package I use. In doing so it will also cover how to use the boilerplate git repository I’ve built to set it all up in just a few minutes, as well as basic git practices and alternate deployment methods such as Capistrano.
Beyond FTP: What I’ve Learned from Years of Deploying WordPress the Wrong Way
1. Beyond FTP
W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
E L I S I L V E R M A N - C A L I P E R C R E A T I V E
2. W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
Or: What I’ve Learned from
Years of Deploying
WordPress the Wrong Way
E L I S I L V E R M A N - C A L I P E R C R E A T I V E
3. BEYOND FTP |
it me!
CALIPER
I build websites, design for
both screen and print, create
web-based software and
business tools, and offer
creative direction for digital
and physical design projects.
Caliper works with
businesses to establish
strong brands and
fluid workflows.
4. BEYOND FTP | OVERVIEW
Q: Do you rely on WordPress
to make a living?
5. ´
BEYOND FTP |
My main goal is to expose more of the
WordPress community to really powerful
development tools in a way that aren’t
intimidating and can be quickly adopted
and installed.
OVERVIEW
You deserve the best tools.
6. ´
BEYOND FTP |
What it looks like to sync WordPress installs in
seconds.
What “software deployment” means, and
specifically what it means in WordPress.
Show you why, if you love FTP, it’s time to let it go.
How WP devs can use tools from the non-WP world.
How quickly you can start using the toolkit.
OVERVIEW
WHAT YOU’LL SEE TODAY
7. BEYOND FTP | OVERVIEW
Q: Who’s seen WordPress
managed from the
command line?
9. B E Y O N D F T P - W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
Breaking Bad
(Habits)
10. BEYOND FTP |
You can pretty much deliver a WP
website without knowing how to write
a word of code.
But if you dive deeper into WordPress
through a Cut-and-Paste Education, it
can prevent you from becoming a
better developer.
BREAKING BAD (HABITS)
WP IS SUPER
EASY TO WORK
WITH, BUT THAT
CAN LEAD TO
BAD PRACTICE.
I learned this the hard way.
11. BEYOND FTP |
Working against a deadline
for my first “legit” client, my
workflow failed me…big time.
BREAKING BAD (HABITS)
12. BEYOND FTP |
Q: Has this ever happened
to anyone else?
BREAKING BAD (HABITS)
A: Yes. To Everyone.
13. BEYOND FTP |
My inexperience wasn’t
cute anymore.
It was a glaring liability.
BREAKING BAD (HABITS)
14. BEYOND FTP |
I had been working in a
vacuum and I had no
mentor to show me the
ropes, or point out the
things I was doing
totally wrong.
FREELANCERS
ARE ALONE.
A LOT.
BREAKING BAD (HABITS)
15. BEYOND FTP |
Desperately, I thought:
“Other developers MUST
have a better way.”
Turns out, they do.
BREAKING BAD (HABITS)
16. B E Y O N D F T P - W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
“Deployment”
17. ´
BEYOND FTP |
“all of the activities
that make a software
system available for
use”
“DEPLOYMENT”
WHAT…IS…
DEPLOYMENT?
(WikiPedia)
18. ´
BEYOND FTP |
AND WHAT
DOES THAT MEAN
IN WORDPRESS?
our “software system”
is both the
files and the database.
core, themes, plugins,
uploaded content
customization, post
content, session data
“DEPLOYMENT”
19. BEYOND FTP |
Q: Do you develop locally
and push code to a
remote server?
“DEPLOYMENT”
20. ´
BEYOND FTP |
THEN YOU KNOW THIS LIST…
“DEPLOYMENT”
Install WordPress. DB up and running. All plugins
are installed and configured…The theme is installed
(including the parent) and customized properly…
The uploads are all there…
I’M. SO. BORED.
21. ´
BEYOND FTP | “DEPLOYMENT”
CANT WE MAKE OUR
MACHINES DO ALL THIS,
AHEM, GRUNT WORK FOR US?
22. B E Y O N D F T P - W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
Why You Haven’t
Left FTP Behind
The Excuses:
23. BEYOND FTP |
“IT’S OVER MY HEAD”
FTP EXCUSES
But, before you knew how to swim,
so did the deep end.
$ ../I/know/the --command line_seems SCARY.
24. BEYOND FTP |
Just like any text editor, you can
take control of the command
line and let it adapt to you.
iTerm
oh-my-zsh
aliases
$ htdocs client
$ cd /Applications/MAMP/htdocs/clientsite.com/wp-content/themes/my-clients-theme/
instead of
“IT’S OVER MY HEAD”
FTP EXCUSES
25. BEYOND FTP |
“it’s such a timesaver that any
time I spent setting it up, I got
back immediately after it was
working, and then some…”
“IT TAKES TOO LONG TO SETUP”
- Paid Actor, Not a real Doctor
FTP EXCUSES
26. BEYOND FTP |
“I’M NOT A DEVELOPER AND
I HAVE BETTER THINGS TO
LEARN”
If you’re spending even a few hours a week
messing WordPress – even content or
theme config – this is worth your while. And
if you’re writing code maybe it’s time you
start calling yourself a developer…
FTP EXCUSES
27. BEYOND FTP |
Instead of WordPress,
let’s say I work as a
lumberjack.
r
Choppin wood all
damn day.
HOW IT LOOKS
IN ANOTHER
INDUSTRY
FTP EXCUSES
28. BEYOND FTP |
This is me trying to
do my job done with
the wrong tools…
FTP EXCUSES
29. BEYOND FTP |
This is me trying to
do my job done with
the wrong tools…
FTP EXCUSES
30. BEYOND FTP |
and here’s me with
the right tools, gettin
paid and clockin out…
FTP EXCUSES
32. BEYOND FTP |
NOW THAT YOU HAVE
A CHOICE, WHICH ONE
DO YOU CHOOSE?
FTP EXCUSES
33. B E Y O N D F T P - W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
Deployment for
WordPress “In the Wild”
34. BEYOND FTP |
The deploy needs to transfer the
“software system” ( files & db )
OUR CRITERIA
Needs to work on (or help with)
crappy $2/mo hosting services that a
lot of are FORCED to use with clients.
IN THE WILD
1.
2.
35. BEYOND FTP |
RESEARCH &
IMPLEMENTATION
Roots’ Trellis is an amazing solution but
caters to devs deploying enterprise-grade
WP apps.
Most likely, it won’t work with a cheap
shared-server, and it’s tied to git, which is
“smarter” but not what I wanted.
IN THE WILD
36. BEYOND FTP |
&
I K N O W , I K N O W . G U L P I S C O O L E R .
P L E A S E , W R I T E A P O R T , P L Z …
. / WP-CLI
IN THE WILD
37. BEYOND FTP |
I was already using grunt.js
for CSS + JS processing.
Found and forked
grunt-wordpress-deploy
on npm (node package manager)
Dario Ghilardi – @webrain on github
GRUNT.JS
IN THE WILD
Javascript “task runner”
38. BEYOND FTP |
๏ Many times faster than FTP (like, 100x)
๏ Intelligent: only touches files that changed
๏ Repeatable, reliable, configurable
IN THE WILD
GRUNT
WORDPRESS
DEPLOY
Uses rsync, a standard
command line file syncing
service, and it’s a huge step
up from FTP.
39. BEYOND FTP |
$ grunt sync_up --target=dev
ANATOMY OF A GRUNT “CALL”
IN THE WILD
40. BEYOND FTP |
$ grunt sync_up --target=dev
“$” often represents cmd line.
Don’t type this!
run the grunt “executable”
the grunt “task” you
want to execute
sets the server “target” flag (variable)
to our “dev” environment.
ANATOMY OF A GRUNT “CALL”
IN THE WILD
41. BEYOND FTP |
Made for WP using SSH/rsync
• push all local plugins
• push all local uploads
• build + compress theme/plugin
• push theme/plugin
• push the database
GRUNT
WORDPRESS
DEPLOY
IN THE WILD
grunt sync_up
42. BEYOND FTP |
• Creates a clean folder that you
deploy from – fallback for FTP
• Simple versioning : creates
“releases” – deliver to client,
upload via wp-admin, don’t
need to know git
GRUNT
WORDPRESS
DEPLOY
IN THE WILD
Made for WP in The Wild
grunt build
43. BEYOND FTP |
GRUNT
WORDPRESS
DEPLOY • build
• push_theme
• push_files
• push_plugin
• push_plugins
• deploy
• push_db
• pull_db
• sync_up
Other grunt Tasks
MANAGING FILES MANAGING THE DB
ALL THE THINGS
IN THE WILD
44. BEYOND FTP |
“WP-CLI is a set of command-line
tools for managing WordPress
installations. You can update
plugins, configure multisite
installs and much more, without
using a web browser.”
WP-CLI
(wp-cli.org)
IN THE WILD
45. BEYOND FTP |
$ wp plugin install query-monitor
ANATOMY OF A BASIC WP-CLI
IN THE WILD
46. BEYOND FTP |
$ wp plugin install query-monitor
run the wp-cli “executable”
the wp thing “type” you
want to manipulate
the action you want to
perform with that thing
additional info. In this case,
the plugin slug from the wp
plugins directory
ANATOMY OF A BASIC WP-CLI
IN THE WILD
47. BEYOND FTP |
BROWSER
REFRESH GOT
YA DOWN?
No need to click around in wp-admin
every time you need to de/activate a
plugin. Want to see if that new slider
plugin is causing the site to break?
$ wp plugin deactivate acme-slider
$ dp acme-slider
or with my “deactivate-plugin” alias
IN THE WILD
48. BEYOND FTP |
ALIASES As of very recently, you can
specify a remote target WP
install using wp-cli aliases.
$ wp @dev plugin deactivate query-monitor
alias name, defined in config
“ssh: user@ssh.dev-site.com/remote/wp/path”
MORE WP-CLI AWESOMENESS
IN THE WILD
View Config Docs
49. B E Y O N D F T P - W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6
Getting it Running
50. BEYOND FTP |
I MADE YOU
A THING!
BOILERPLATE
A github project that
makes it super easy to
get this up and running.
I. Follow the 4 steps on github to install
II. Add your DB and SSH details to the config
III. Test using the —dry-run flag
IV. Get to work!
https://github.com/madebycaliper/grunt-wp-deploy-boilerplate
53. BEYOND FTP | CONCERNS
๏ This method is not tied to version control like Capistrano or Deploy HQ. You cannot
auto “roll back” to a previous version.
✓ You can checkout a local commit and just run ‘grunt deploy’
๏ Still some chance of human error, it’s possible to overwrite files (these are irreversible
operations)
✓ Play it safe by enabling rsync’s --dry-run flag first – shows you what files will be
changed without doing it.
๏ MySQL and PHP configs can vary between hosts and create errors with the DB
operations (command line outputs unexpected strings/results)
✓ Use the ‘sql_remove’ option in the wordpresdeploy.coffee file to sanitize output
๏ This hasn’t been tested on very large databases. Test it out for me?
๏ I’ve only ever done this on a Mac/linux. Not sure how rsync works on windows.
CONCERNS
54. ´
BEYOND FTP |
THANK YOU!
๏ More command line tips for WordPress
๏ Debugging PHP (Sublime Text + Xdebug)
๏ Debugging JS in the Chrome DevTools
๏ Version control with git and SourceTree
๏ Advanced use of the wp-cli
MadeByCaliper.com
MIC DROP
There’s so much more for WordPress developers.
Improve your workflow, understanding of code,
and know how to quickly troubleshoot WP/PHP:
55. Beyond FTP
W O R D C A M P N O L A - A U G U S T 1 3 , 2 0 1 6