WordCamp DFW 2018: Deploying WordPress with Git & Continuous Integration

218af8b993de870341b4354f609013b8?s=47 Ben Word
November 10, 2018

WordCamp DFW 2018: Deploying WordPress with Git & Continuous Integration

218af8b993de870341b4354f609013b8?s=128

Ben Word

November 10, 2018
Tweet

Transcript

  1. Deploying WordPress with Git & Continuous Integration Ben Word @retlehs

    @rootswp roots.io
  2. Howdy! I was born and raised in the Dallas area,

    but now Colorado Springs is home
  3. Building open-source WordPress tools since 2011 https://roots.io/ @rootswp

  4. None
  5. None
  6. None
  7. None
  8. None
  9. How do you make updates to your WordPress sites?

  10. None
  11. 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
  12. 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
  13. None
  14. None
  15. 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
  16. 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.
  17. Image from https://djangostars.com/blog/continuous-integration-circleci-vs-travisci-vs-jenkins/

  18. 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
  19. None
  20. GitHub Actions was announced recently and might make CI services

    irrelevant (offering the same features as CI services plus more)
  21. 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
  22. Example #1: Deploying entire WP site • Git-ready out of

    the box
 • Dependency management with Composer • One-command deploys
 • Zero-downtime deploys
  23. None
  24. None
  25. None
  26. Generate SSH key for CircleCI ssh-keygen -t rsa -b 4096

    -C "your@email.com"
  27. 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
  28. None
  29. None
  30. None
  31. None
  32. Simple config with less than 30 lines of code On

    git pushes to master, run tests (attempt a theme build) and then deploy
  33. None
  34. CircleCI uses Docker containers and allows use of custom images

  35. None
  36. 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

  37. None
  38. None
  39. None
  40. None
  41. None
  42. None
  43. Settings > Branches > Branch protection rules

  44. None
  45. None
  46. None
  47. None
  48. None
  49. None
  50. 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
  51. 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
  52. Replace WP Pusher with a free solution & less than

    30 lines of code
  53. None
  54. None
  55. 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
  56. Replace DeployBot or DeployHQ with a free solution

  57. 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
  58. What about GitLab CI? Slightly different configuration & interface

  59. None
  60. Doing more than just the basics

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


  62. Use WordPress backup plugin to trigger a backup

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


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

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

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