laravel forge: hello world to hello production

110
Laravel Forge: From Hello World to Hello Production

Upload: joe-ferguson

Post on 02-Jul-2015

4.158 views

Category:

Technology


2 download

DESCRIPTION

Slides for the talk I gave at the inaugural php[world] conference on November 12th 2014 in Washington, DC

TRANSCRIPT

Page 1: Laravel Forge: Hello World to Hello Production

Laravel Forge:From Hello World to Hello Production

Page 2: Laravel Forge: Hello World to Hello Production

Step One: Hello WorldStep Two: CI, CD, OMG

Step Three: ????Step Four: Hello

Production

Page 3: Laravel Forge: Hello World to Hello Production

Step One: Hello World

Page 4: Laravel Forge: Hello World to Hello Production

Create our projectVia Laravel Installer: laravel new hello-world

Via Composer: composer create-project laravel/laravel hello-world --prefer-dist

Page 5: Laravel Forge: Hello World to Hello Production

Where should our project live?

I prefer to keep things in ~/PhpstormProjects

Page 6: Laravel Forge: Hello World to Hello Production

MAMP, LAMP, WAMP, WAT?

Mac/Linux/Windows Apache MySQL PHP

These are all great tools

Page 7: Laravel Forge: Hello World to Hello Production

Is your server running MAMP?

Page 8: Laravel Forge: Hello World to Hello Production

Why not develop ON the server?

Page 9: Laravel Forge: Hello World to Hello Production

Do not develop ON the server

Page 10: Laravel Forge: Hello World to Hello Production

Develop in the same environment

Page 11: Laravel Forge: Hello World to Hello Production

Servers are expensive

Page 12: Laravel Forge: Hello World to Hello Production

Virtual Machines are cheap

Page 13: Laravel Forge: Hello World to Hello Production

Our Use Case:Duplicate our server environment

in a local virtual machine

Page 14: Laravel Forge: Hello World to Hello Production

Installing an OS takes time

Page 15: Laravel Forge: Hello World to Hello Production

Vagrant!

Page 16: Laravel Forge: Hello World to Hello Production

Vagrant allows you to:• Create a server• Configure a server• Delete a server

…over and over and over..

Page 17: Laravel Forge: Hello World to Hello Production

Which Vagrant?

Page 18: Laravel Forge: Hello World to Hello Production

Homestead“Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine.”

Page 19: Laravel Forge: Hello World to Hello Production

But I need…

Page 20: Laravel Forge: Hello World to Hello Production

What’s in the box:• Ubuntu 14.04• PHP 5.6• HHVM• Nginx• MySQL• Postgres• Redis

• NodeJS• Bower• Grunt• Gulp• Beanstalkd• Memcached• Laravel Envoy

Fabric + HipChat Extension + more!

Page 21: Laravel Forge: Hello World to Hello Production

Getting Homestead

Install the box:vagrant box add laravel/homestead

Clone the Repository:git clone https://github.com/laravel/homestead.git Homestead

Page 22: Laravel Forge: Hello World to Hello Production

Configure HomesteadDefault: Hello World:

Page 23: Laravel Forge: Hello World to Hello Production

Update /etc/hosts*192.168.10.10 hello-world.app

*This step is optional

Page 24: Laravel Forge: Hello World to Hello Production

Ready to vagrant up

Our code will be shared from our host machine

And mapped to the vagrant machine

~/PhpstormProjects/hello-world

/home/vagrant/hello-world

Page 25: Laravel Forge: Hello World to Hello Production

$ vagrant up

Page 26: Laravel Forge: Hello World to Hello Production

What now?

Page 27: Laravel Forge: Hello World to Hello Production

How to access our hello-world.app

These are ports forwarded to homestead

Page 28: Laravel Forge: Hello World to Hello Production

Connect to the Database

Page 29: Laravel Forge: Hello World to Hello Production

Connect via a browser

Page 30: Laravel Forge: Hello World to Hello Production

Or use the hostname*

*If you added the host to your /etc/hosts

Page 31: Laravel Forge: Hello World to Hello Production

Connect via SSHYou could do this:

But this is easier:

Page 32: Laravel Forge: Hello World to Hello Production

Homestead is awesome!We now have a local dev environment we can easily use, break, and restore

without having to reinstall the entire operating system and developer tools.

Break something?

Page 33: Laravel Forge: Hello World to Hello Production

Staking your own Homestead

I like to customize homestead AND

make sure I can easily update from upstream

Page 34: Laravel Forge: Hello World to Hello Production

Fork Homestead

Page 35: Laravel Forge: Hello World to Hello Production

Update your Homestead

Page 36: Laravel Forge: Hello World to Hello Production

Add another provisioner

Page 37: Laravel Forge: Hello World to Hello Production

What could customize.sh do?

Page 38: Laravel Forge: Hello World to Hello Production

You may not need customize.sh

It is important to have a way to easily reproduce your development environment

so that those one off changes you make are documented and two months down the

road you don’t destroy & up your environment to find out you have stuff missing

Page 39: Laravel Forge: Hello World to Hello Production

Step ??? Go make something great

Page 40: Laravel Forge: Hello World to Hello Production

Tests!

You've written tests all along for your app right?

Page 41: Laravel Forge: Hello World to Hello Production

PHPUnit isn’t the only option!

• Behat• phpspec• Codeception

Page 42: Laravel Forge: Hello World to Hello Production

Codeception• Selenium WebDriver integration• Elements matched by name, CSS, XPath• Symfony2, Laravel4, Yii, Phalcon, Zend Framework• PageObjects and StepObjects included• BDD-style readable tests• Powered by PHPUnit• API testing: REST,SOAP,XML-RPC• Facebook API testing• Data Cleanup• HTML, XML, TAP, JSON reports• CodeCoverage and Remote CodeCoverage• Parallel Execution

Page 43: Laravel Forge: Hello World to Hello Production

Basic Acceptance Test

Page 44: Laravel Forge: Hello World to Hello Production

Automate our Testing

Page 45: Laravel Forge: Hello World to Hello Production

TeamCity

Page 46: Laravel Forge: Hello World to Hello Production

Build Steps

Page 47: Laravel Forge: Hello World to Hello Production

All OK? Deploy!

Page 48: Laravel Forge: Hello World to Hello Production

Step Four: Hello Production

Page 49: Laravel Forge: Hello World to Hello Production

Traditional Deployment

Page 50: Laravel Forge: Hello World to Hello Production

Better Deployment

Page 51: Laravel Forge: Hello World to Hello Production

But you still have to…

• Update Dependencies• Run migrations• Update Assets

Page 52: Laravel Forge: Hello World to Hello Production

Continuous Delivery

Production can be updated anytime

Page 53: Laravel Forge: Hello World to Hello Production

Continuous Delivery VS

Continuous Deployment

Page 54: Laravel Forge: Hello World to Hello Production

Continuous Deployment“Deploy my code every time tests pass”

Continuous Delivery“We can deploy whenever we want…but we control when”

Magnus Hedemark: http://puppetlabs.com/blog/continuous-delivery-vs-continuous-deployment-whats-diff

Page 55: Laravel Forge: Hello World to Hello Production

Laravel Forge

“A simple way to deploy your laravel applications onto blazing fast servers”

Page 56: Laravel Forge: Hello World to Hello Production

Forge is Homestead and more in the cloud

Page 57: Laravel Forge: Hello World to Hello Production

Forge is not a server host

Page 58: Laravel Forge: Hello World to Hello Production

Forge uses your servers

Page 59: Laravel Forge: Hello World to Hello Production

Forge uses any* server

*Any Internet accesible Ubuntu 14.04 x64 Server

Page 60: Laravel Forge: Hello World to Hello Production

Adding Servers To Forge

Page 61: Laravel Forge: Hello World to Hello Production

Adding a site to a server

Page 62: Laravel Forge: Hello World to Hello Production

Adding a ssh key to a server

Page 63: Laravel Forge: Hello World to Hello Production

Adding scheduled (cron) jobs

Page 64: Laravel Forge: Hello World to Hello Production

Adding daemons (supervisor)

Page 65: Laravel Forge: Hello World to Hello Production

Creating server networks

Page 66: Laravel Forge: Hello World to Hello Production

Server Monitoring

Page 67: Laravel Forge: Hello World to Hello Production

Update Server Meta Data

Page 68: Laravel Forge: Hello World to Hello Production

Adding our hello-world site

Page 69: Laravel Forge: Hello World to Hello Production

Forge can do more…

Page 70: Laravel Forge: Hello World to Hello Production

Add a WordPress Site

Page 71: Laravel Forge: Hello World to Hello Production

Ready to install

Page 72: Laravel Forge: Hello World to Hello Production

Removing WordPress

Does NOT remove your WordPress Database!

Page 73: Laravel Forge: Hello World to Hello Production

Install Craft CMS

Page 74: Laravel Forge: Hello World to Hello Production

Craft CMS

Page 75: Laravel Forge: Hello World to Hello Production

Uninstall Craft CMS

Does NOT remove your Craft CMS Database!

Page 76: Laravel Forge: Hello World to Hello Production

Install our Git Repository

Page 77: Laravel Forge: Hello World to Hello Production

Configure App Deployment

Page 78: Laravel Forge: Hello World to Hello Production

Deploy!

Page 79: Laravel Forge: Hello World to Hello Production

Deploy!

Continuous Delivery!

Page 80: Laravel Forge: Hello World to Hello Production

Deployment Log

Page 81: Laravel Forge: Hello World to Hello Production

Setting Environment Variables

Page 82: Laravel Forge: Hello World to Hello Production

Queue Workers

Page 83: Laravel Forge: Hello World to Hello Production

Configure / Install SSL

Page 84: Laravel Forge: Hello World to Hello Production

Enable Quick Deploy

Page 85: Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Page 86: Laravel Forge: Hello World to Hello Production

Quick Deploy Branch

Continuous Deployment!

Page 87: Laravel Forge: Hello World to Hello Production

Recipes

Recipes a bash scripts that can be run on any of your Forge servers.

Page 88: Laravel Forge: Hello World to Hello Production

Cooking up Recipes

Think of recipes like our customize.sh in Homestead

Page 89: Laravel Forge: Hello World to Hello Production

All the things!

Page 90: Laravel Forge: Hello World to Hello Production

Not All The Things

Some things we were doing in customize.sh we can do via Forge:

• Queue Workers• Cron Jobs

Page 91: Laravel Forge: Hello World to Hello Production

Create Recipe

Page 92: Laravel Forge: Hello World to Hello Production

Run Install Bower Recipe

Page 93: Laravel Forge: Hello World to Hello Production

Forge Emails You Recipe Report

Page 94: Laravel Forge: Hello World to Hello Production

HipChat Notifications

Page 95: Laravel Forge: Hello World to Hello Production

Slack Notifications

You can use cURL to post to Slack channelscurl -X POST --data-urlencode ‘payload=

{"channel": “#devops", "username": "Forge", "text": “'"$Message"'",

"icon_emoji": ":shipit:"}' https://<You>.slack.com/services/

hooks/incoming-webhook?token=<Your-Slack-Token>

Page 96: Laravel Forge: Hello World to Hello Production

Edit our Deployment Script

Now every deployment will run bower and notify our slack channel that our repo was deployed.

Page 97: Laravel Forge: Hello World to Hello Production

Hey Joe…

Page 98: Laravel Forge: Hello World to Hello Production

Been there, done that

Page 99: Laravel Forge: Hello World to Hello Production

Enable Slack

Page 100: Laravel Forge: Hello World to Hello Production

Add the Integration

Page 101: Laravel Forge: Hello World to Hello Production

Authenticate with Slack

Page 102: Laravel Forge: Hello World to Hello Production

Deploy!

Page 103: Laravel Forge: Hello World to Hello Production

Restarting Services

Edit PHP Configuration

Page 104: Laravel Forge: Hello World to Hello Production

Delete the server

Page 105: Laravel Forge: Hello World to Hello Production

Deleting a site

Page 106: Laravel Forge: Hello World to Hello Production

Forge Circles*

*Forge Plus Feature

Page 107: Laravel Forge: Hello World to Hello Production

Forge Circles*

*Forge Plus Feature

Page 108: Laravel Forge: Hello World to Hello Production

Forge VS Forge Plus

• Manage 5 Servers • Unlimited Servers• Forge Circles

Page 109: Laravel Forge: Hello World to Hello Production

Recap

Local Development: Use Homestead

Remote Deployment: Use Forge

Automate build tests and configure Continuous Deployment

Practice Continuous Delivery if not Continuous Deployment

Page 110: Laravel Forge: Hello World to Hello Production

Feedback!

https://joind.in/talk/view/11870

Joe FergusonTwitter: @Svpernova09

Email: [email protected]

Contact Info: