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. 2.

    Howdy! I was born and raised in the Dallas area,

    but now Colorado Springs is home
  2. 4.
  3. 5.
  4. 6.
  5. 7.
  6. 8.
  7. 10.
  8. 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
  9. 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
  10. 13.
  11. 14.
  12. 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
  13. 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.
  14. 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
  15. 19.
  16. 20.

    GitHub Actions was announced recently and might make CI services

    irrelevant (offering the same features as CI services plus more)
  17. 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
  18. 22.

    Example #1: Deploying entire WP site • Git-ready out of

    the box
 • Dependency management with Composer • One-command deploys
 • Zero-downtime deploys
  19. 23.
  20. 24.
  21. 25.
  22. 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
  23. 28.
  24. 29.
  25. 30.
  26. 31.
  27. 32.

    Simple config with less than 30 lines of code On

    git pushes to master, run tests (attempt a theme build) and then deploy
  28. 33.
  29. 35.
  30. 37.
  31. 38.
  32. 39.
  33. 40.
  34. 41.
  35. 42.
  36. 44.
  37. 45.
  38. 46.
  39. 47.
  40. 48.
  41. 49.
  42. 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
  43. 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
  44. 53.
  45. 54.
  46. 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
  47. 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
  48. 59.