Top Banner
Modern PHP Deployments using CI and Laravel Envoy From GitHub to Produc/on John Blackmore - @johnblackmore
29

Automated deployments using envoy by John Blackmore

Jan 10, 2017

Download

Technology

TechExeter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Automated deployments using envoy by John Blackmore

Modern PHP Deployments using CI and Laravel Envoy

From GitHub to Produc/on

John Blackmore - @johnblackmore

Page 2: Automated deployments using envoy by John Blackmore

Overview• Typical Deployment Scenerios

• Propose a New Solu7on

• Implementa7on

• Automa7on

John Blackmore - @johnblackmore

Page 3: Automated deployments using envoy by John Blackmore

Typical Deployment ProcessDeploying Code is Hard

John Blackmore - @johnblackmore

Page 4: Automated deployments using envoy by John Blackmore

Deployment Scenario 1 - FTP• Local files on a shared network folder

• Each new project a cut-paste of core code

• Manual copying of files over FTP

• Shared core files using symlinks

John Blackmore - @johnblackmore

Page 5: Automated deployments using envoy by John Blackmore

Scenario 1 Problems• File Conflicts

• No Revision History

• No Development/Produc;on Parity

• Fragile Core Code

John Blackmore - @johnblackmore

Page 6: Automated deployments using envoy by John Blackmore

Deployment Scenario 2 - Git• SSH into the produc0on server

• cd to the web server root

• git fetch origin (update)

• git reset origin/master --hard (deploy)

• composer install (download dependencies)

John Blackmore - @johnblackmore

Page 7: Automated deployments using envoy by John Blackmore

Scenario 2 Problems• Lots to remember

• Easy to make a mistake

• Down3me while Composer is installing

• Non-trivial rollbacks

John Blackmore - @johnblackmore

Page 8: Automated deployments using envoy by John Blackmore

Propose a New Solu.onDeploying Code Should be Easy

John Blackmore - @johnblackmore

Page 9: Automated deployments using envoy by John Blackmore

Automated Deployment Requirements

• A simple command to run locally

• Same tooling for production and staging

• Define a specific branch or commit to release

• Ability to rollback to the previous release

• Zero-down2me switch between releases

John Blackmore - @johnblackmore

Page 10: Automated deployments using envoy by John Blackmore

Deployment Automa.on Tools• Capistrano - Ruby

• Fabric - Python

• Shunt - PHP (League)

• Laravel Envoy - PHP (& Bash)

• many, many others...1

1 h$p://so*ware.wikia.com/wiki/List_of_build_automa<on_so*ware

John Blackmore - @johnblackmore

Page 11: Automated deployments using envoy by John Blackmore

Choosing Laravel Envoy• PHP-based solu.on

• Blade-style syntax

• Parallel execu.on (Mul.-Server)

• Slack/HipChat no.fica.ons

• Not Laravel dependent

John Blackmore - @johnblackmore

Page 12: Automated deployments using envoy by John Blackmore

Our Envoy Commands

envoy run deploy

Deploys the master branch to all servers.

envoy run deploy --branch=my_branch --target=web

Deploys my_branch to all servers in the web pool.

John Blackmore - @johnblackmore

Page 13: Automated deployments using envoy by John Blackmore

Our Envoy Commands (con1nued)

envoy run rollback

Rollback all servers to the previous release.

envoy run cleanup

Manual cleanup of the releases directory, keeps the last 5.

John Blackmore - @johnblackmore

Page 14: Automated deployments using envoy by John Blackmore

Implementa)onStringing it Together

John Blackmore - @johnblackmore

Page 15: Automated deployments using envoy by John Blackmore

envoy run deploy

• git clone to a new directory in /var/www/releases

• composer self-update and composer install

• Create symlinks to shared folders and config files

• Update symlinks for previous and current releases

• Restart ApacheJohn Blackmore - @johnblackmore

Page 16: Automated deployments using envoy by John Blackmore

envoy run rollback

• Update the current symlink to point to the previous release

• Restart Apache

Note: Only supports automated rollback to previous version.

Manual rollbacks can be performed "on the box" for any of the last 5 releases.

John Blackmore - @johnblackmore

Page 17: Automated deployments using envoy by John Blackmore

Automa'onHello Con(nuous Deployments!

John Blackmore - @johnblackmore

Page 18: Automated deployments using envoy by John Blackmore

Con$nuous Deployments• Deployments enacted by your CI suite

• Only triggered by a merge into the master branch

• Minimal risk when adop<ng GitHub Flow2

2 h$ps://guides.github.com/introduc6on/flow/

John Blackmore - @johnblackmore

Page 19: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 1 - Create a branch

John Blackmore - @johnblackmore

Page 20: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 2 - Add commits

John Blackmore - @johnblackmore

Page 21: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 3 - Open a Pull Request

John Blackmore - @johnblackmore

Page 22: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 4 - Code Review

John Blackmore - @johnblackmore

Page 23: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 5 - Ship It!

John Blackmore - @johnblackmore

Page 24: Automated deployments using envoy by John Blackmore

GitHub Flow Explained

Step 6 - Merge

John Blackmore - @johnblackmore

Page 25: Automated deployments using envoy by John Blackmore

GitHub Flow - Summary

• The master branch is always deployable

• Create a branch for each new feature

• Commit regularly with clear commit messages

• Open a Pull request (Peer Review, CI & ACR)

• Deploy the branch to producEon

• Merge the pull request

John Blackmore - @johnblackmore

Page 26: Automated deployments using envoy by John Blackmore

Deploying the Branch

We deploy the feature branch manually:

envoy run deploy --branch=my_new_branch

A"er merging the Pull Request, SemaphoreCI runs:

envoy run deploy

• This resets produc/on servers back to master

John Blackmore - @johnblackmore

Page 27: Automated deployments using envoy by John Blackmore

Review• Use version control

• Manual processes cause accidents

• Make processes easy, repeatable and reliable

• Use CI to automate tes:ng, code reviews and quality checks

• GitHub Flow reduces risks of deploying

John Blackmore - @johnblackmore

Page 28: Automated deployments using envoy by John Blackmore

Ques%ons?

Twi$er: @johnblackmoreWeb: johnblackmore.com

Email: [email protected]

John Blackmore - @johnblackmore

Page 29: Automated deployments using envoy by John Blackmore

Links and Inspira,on• Enhancing Envoy Deployment

• One Step Symlink Switch

• OpCache and symlink-based deployments

• Deploying with Envoy

• Laravel Envoy Deploy

• An Envoyer-like deployment script using Envoy

John Blackmore - @johnblackmore