Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordCamp DFW 2018: Deploying WordPress with Git...

Ben Word
November 10, 2018

WordCamp DFW 2018: Deploying WordPress with Git & Continuous Integration

Ben Word

November 10, 2018
Tweet

More Decks by Ben Word

Other Decks in Education

Transcript

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

    but now Colorado Springs is home
  2. 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
  3. 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
  4. 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
  5. 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.
  6. 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
  7. GitHub Actions was announced recently and might make CI services

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

    the box
 • Dependency management with Composer • One-command deploys
 • Zero-downtime deploys
  10. 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
  11. Simple config with less than 30 lines of code On

    git pushes to master, run tests (attempt a theme build) and then deploy
  12. 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
  13. 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
  14. 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
  15. 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