Slide 1

Slide 1 text

Deploying WordPress with Git & Continuous Integration Ben Word @retlehs @rootswp roots.io

Slide 2

Slide 2 text

Howdy! I was born and raised in the Dallas area, but now Colorado Springs is home

Slide 3

Slide 3 text

Building open-source WordPress tools since 2011 https://roots.io/ @rootswp

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

How do you make updates to your WordPress sites?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

https://git-scm.com/book https://github.com/k88hudson/git-flight-rules for everything Every developer should be using version control on every project It doesn’t matter how large the project is or how many people will be working on it

Slide 12

Slide 12 text

Manual deploys are unpredictable • Working on a team? No single source of truth • Missing files during an upload can cause errors • Making a mistake during a deployment is likely — 
 did you follow all the steps?
 • Unable to easily rollback changes
 • Users should be able to use the site at all times without being impacted

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

Automated deploys are better • Ship small changes quickly • Never worry about if you copied over the correct files
 • Automated tasks for tests and builds
 • Catch errors before the code makes it onto production
 • Introduce zero-downtime atomic deploys
 • Easy rollbacks
 • Simple Slack integration

Slide 16

Slide 16 text

Continuous Integration (CI) is the practice of testing each commit to your codebase automatically. Continuous Deployment automatically deploys every change if the commits pass all defined tests.

Slide 17

Slide 17 text

Image from https://djangostars.com/blog/continuous-integration-circleci-vs-travisci-vs-jenkins/

Slide 18

Slide 18 text

What can we test in our codebase on every commit before attempting a deploy? • Theme build (linting and/or coding standards) • Plugin build (linting and/or coding standards) • Check for security vulnerabilities in plugins 
 • Smoke testing with WP-CLI
 • Booting a server and loading the home page

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

GitHub Actions was announced recently and might make CI services irrelevant (offering the same features as CI services plus more)

Slide 21

Slide 21 text

Why CircleCI? Easy to understand YAML config Free [for most] cloud application
 (no need to manage hosting for your CI server) Supports GitHub & BitBucket GitLab user? GitLab CI is also great! We’ll go over a GitLab CI config later

Slide 22

Slide 22 text

Example #1: Deploying entire WP site • Git-ready out of the box
 • Dependency management with Composer • One-command deploys
 • Zero-downtime deploys

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

Generate SSH key for CircleCI ssh-keygen -t rsa -b 4096 -C "[email protected]"

Slide 27

Slide 27 text

Add CircleCI SSH key to Trellis 1. Copy circleci.pub to trellis/keys/
 2. Add key to web user in 
 trellis/group_vars/users.yml
 
 - "{{ lookup('file', 'keys/circleci.pub') }}"
 3. Re-provision server

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Simple config with less than 30 lines of code On git pushes to master, run tests (attempt a theme build) and then deploy

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

CircleCI uses Docker containers and allows use of custom images

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

https://hub.docker.com/r/benword/ https://circleci.com/docs/2.0/ circleci-images/ ubuntu:18.04 circleci/php:7.2-node-browsers circleci/node:10.12.0

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Settings > Branches > Branch protection rules

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

From git push to deployed in ~2 minutes with zero-downtime That includes: • Cloning the latest codebase with Git • Running basic tests on the WordPress theme • Installing WordPress, WordPress plugins, and other PHP dependencies with Composer • Building the WordPress theme and transferring compiled assets

Slide 51

Slide 51 text

Example #2: Deploying single theme (or plugin) Git repository only contains the theme Required environment variables: SFTP_HOSTNAME SFTP_USERNAME SFTP_PASSWORD WEB_ROOT THEME_NAME

Slide 52

Slide 52 text

Replace WP Pusher with a free solution & less than 30 lines of code

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Atomic deploys (zero-downtime) without Trellis Requires your web host to provide SSH access • Deploy (and build) the theme in a releases directory
 • Once the theme is ready, a symlink that’s used for serving the webroot is updated to point to the latest release

Slide 56

Slide 56 text

Replace DeployBot or DeployHQ with a free solution

Slide 57

Slide 57 text

Recommended atomic deployment options • Capistrano (Ruby)
 
 https://github.com/roots/bedrock-capistrano
 • Deployer.org (PHP)
 
 Bedrock recipes from Roots Discourse:
 https://goo.gl/4SthmV
 • FlipIt (Bash script)
 
 https://github.com/timacdonald/flipit

Slide 58

Slide 58 text

What about GitLab CI? Slightly different configuration & interface

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Doing more than just the basics

Slide 61

Slide 61 text

Database backup on deploy https://github.com/ItinerisLtd/trellis-backup-during-deploy


Slide 62

Slide 62 text

Use WordPress backup plugin to trigger a backup

Slide 63

Slide 63 text

Scan for security concerns https://github.com/sensiolabs/security-checker


Slide 64

Slide 64 text

Scan for security concerns https://github.com/markri/wp-sec

Slide 65

Slide 65 text

Add visual regression testing http://bbc-news.github.io/wraith/

Slide 66

Slide 66 text

@rootswp @retlehs https://roots.io/ Configs available at:
 https://git.io/fpIQN