Slide 1

Slide 1 text

Deploy your application in a box @willemjanz joind.in/talk/73636

Slide 2

Slide 2 text

Willem-Jan Zijderveld @willemjanz github.com/wjzijderveld

Slide 3

Slide 3 text

Don't wait till the last slide with questions

Slide 4

Slide 4 text

Deployment With the usual disclaimer

Slide 5

Slide 5 text

It works So why change it?

Slide 6

Slide 6 text

Can you deploy whenever you want?

Slide 7

Slide 7 text

Are you ever hesitant to deploy?

Slide 8

Slide 8 text

"We can't deploy, Robin is sick today"

Slide 9

Slide 9 text

Do users notice when you deploy?

Slide 10

Slide 10 text

Things break If you like it or not

Slide 11

Slide 11 text

Deployments fail ● Network issues ● Migrations ● Broken configuration

Slide 12

Slide 12 text

Downtime

Slide 13

Slide 13 text

Missed revenue

Slide 14

Slide 14 text

Angry customers

Slide 15

Slide 15 text

Customers losing faith

Slide 16

Slide 16 text

Scared to deploy

Slide 17

Slide 17 text

Deployments get postponed

Slide 18

Slide 18 text

Reserving dedicated time to deploy

Slide 19

Slide 19 text

Deploying outside office hours...

Slide 20

Slide 20 text

So what would be a more optimal method?

Slide 21

Slide 21 text

Less humans

Slide 22

Slide 22 text

No sweat

Slide 23

Slide 23 text

More often

Slide 24

Slide 24 text

0 downtime

Slide 25

Slide 25 text

Repeatable

Slide 26

Slide 26 text

Let's get started

Slide 27

Slide 27 text

Less humans Automate your deploy process to a single step

Slide 28

Slide 28 text

Possible deployment Migrate database Update code on server (FTP, SSH) Update code dependencies (composer,npm,bower) Clear cache Reload webserver

Slide 29

Slide 29 text

> ssh your-server.com > sudo su - > cd /var/www/ > git pull > php composer.phar install > npm install > rm -rf app/cache/* > # Some permission commands > service php-fpm reload Example: before

Slide 30

Slide 30 text

Example: after > ssh [email protected] > ./deploy.sh * Pulling changes * Updating dependencies * Migrating database * Clearing cache * DEPLOYED NEW VERSION

Slide 31

Slide 31 text

No sweat Lose the fear of deploying

Slide 32

Slide 32 text

Testing

Slide 33

Slide 33 text

Seriously, test your code

Slide 34

Slide 34 text

New code should have tests

Slide 35

Slide 35 text

Legacy code? Test the critical parts - Unit tests for important (domain) logic - Functional tests - Monitor production

Slide 36

Slide 36 text

Continuous Integration

Slide 37

Slide 37 text

More often

Slide 38

Slide 38 text

Smaller changes

Slide 39

Slide 39 text

6 month projects Deliver something every day Don't wait with deploying until your feature is ready and approved.

Slide 40

Slide 40 text

Short lived branches ● Allows for rapid deployment ● Prevents huge merge conflicts ● Speeds up overall development

Slide 41

Slide 41 text

Feature toggles

Slide 42

Slide 42 text

Example: recommendations getBasketOfUser($user); $response = ['basket' => $basket->toArray()]; if ($this->featureIsActive('recommendations')) { $response['recommendations'] = $this->getRecommendations($basket); } return new JsonResponse($response); }

Slide 43

Slide 43 text

Example: recommendations getBasketOfUser($user); $response = ['basket' => $basket->toArray()]; if ($this->featureIsActive('recommendations')) { $response['recommendations'] = $this->getRecommendations($basket); } return new JsonResponse($response); }

Slide 44

Slide 44 text

Give some users access

Slide 45

Slide 45 text

Conditional toggle Check the context against the conditions of the toggle

Slide 46

Slide 46 text

Example: Conditional toggle GreaterThan(42)] ); $toggle->active(['user_id' => 21]); // true $toggle->active(['user_id' => 1337]); // false

Slide 47

Slide 47 text

Example: Conditional toggle GreaterThan(42)] ); $toggle->active(['user_id' => 21]); // true $toggle->active(['user_id' => 1337]); // false

Slide 48

Slide 48 text

Example: Conditional toggle GreaterThan(42)] ); $toggle->active(['user_id' => 21]); // true $toggle->active(['user_id' => 1337]); // false

Slide 49

Slide 49 text

Example: Conditional toggle GreaterThan(42)] ); $toggle->active(['user_id' => 21]); // true $toggle->active(['user_id' => 1337]); // false

Slide 50

Slide 50 text

Feature management GUI API Redis http://labs.qandidate.com/blog/2014/08/19/open-sourcing-our-feature-toggle-api-and-ui/

Slide 51

Slide 51 text

More often - Smaller iterations - Don't wait for the whole feature to complete - Make use of feature toggles

Slide 52

Slide 52 text

0 downtime

Slide 53

Slide 53 text

Prepare your deployment

Slide 54

Slide 54 text

Deployment Webserver Application - version 1

Slide 55

Slide 55 text

Deployment Webserver Application - version 1 Application - version 2

Slide 56

Slide 56 text

Deployment Webserver Application - version 1 Application - version 2

Slide 57

Slide 57 text

Deployment Webserver Application - version 1

Slide 58

Slide 58 text

Deployment Webserver Application - version 1 Install code

Slide 59

Slide 59 text

Deployment Webserver Application - version 1 Install code Migrations

Slide 60

Slide 60 text

Deployment Webserver Application - version 1 Install code Migrations Warmup cache

Slide 61

Slide 61 text

Deployment Webserver Application - version 1 Install code Migrations Warmup cache Application - version 2

Slide 62

Slide 62 text

Deployment Webserver Application - version 1 Install code Migrations Warmup cache Application - version 2

Slide 63

Slide 63 text

Example /var /project /releases /20160608-1.0 /20160609-1.1 /current -> /var/project/releases/20160608-1.0

Slide 64

Slide 64 text

0 downtime - Don't touch the current version - Abort when any of the steps fail - Make your migrations backwards compatible

Slide 65

Slide 65 text

Put it in a box

Slide 66

Slide 66 text

Repeatable

Slide 67

Slide 67 text

Environment independent

Slide 68

Slide 68 text

The box In it's simplest form: just a zip

Slide 69

Slide 69 text

Independent

Slide 70

Slide 70 text

Reusable On all environments

Slide 71

Slide 71 text

Some challenges

Slide 72

Slide 72 text

Filesystem

Slide 73

Slide 73 text

/var/www/uploads/

Slide 74

Slide 74 text

Flysystem Abstract the filesystem - Makes it easier to test - Makes your code independent of the filesystem, f.e.: - Production uses S3 - Development uses local files

Slide 75

Slide 75 text

Slide 76

Slide 76 text

# config.yml oneup_flysystem: adapters: private_s3: awss3v2: client: aws_s3_client bucket: %s3_private_files_bucket% filesystem: private: adapter: private_s3

Slide 77

Slide 77 text

filesystem ->writeStream('avatars/' . $filename, $stream); if (is_resource($stream)) { fclose($stream); } }

Slide 78

Slide 78 text

File is now at S3: bucket/avatars/filename. ext

Slide 79

Slide 79 text

Configuration

Slide 80

Slide 80 text

# config_prod.yml imports: - { resource: config.yml } doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: 192.168.1.10 dbname: acme_prod user: acme_prod password: SuperSecure

Slide 81

Slide 81 text

What about staging and acceptance?

Slide 82

Slide 82 text

Give control to the environment

Slide 83

Slide 83 text

# config.yml imports: - { resource: parameters.yml } - { resource: parameters.php } doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: %db.hostname% dbname: %db.name% user: %db.user% password: %db.password%

Slide 84

Slide 84 text

# config.yml imports: - { resource: parameters.yml } - { resource: parameters.php } doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: %db.hostname% dbname: %db.name% user: %db.user% password: %db.password%

Slide 85

Slide 85 text

# config.yml imports: - { resource: parameters.yml } - { resource: parameters.php } doctrine: dbal: default_connection: default connections: default: driver: pdo_mysql host: %db.hostname% dbname: %db.name% user: %db.user% password: %db.password%

Slide 86

Slide 86 text

'MYAPP_S3_PRIVATE_FILES_BUCKET', ]; foreach ($parameterMapping as $parameter => $env) { if (false !== ($value = getenv($env))) { $container->setParameter($parameter, $value); } }

Slide 87

Slide 87 text

$_ENV['SYMFONY__*'] But those values get overwritten by parameters defined in config.yml / parameters.yml

Slide 88

Slide 88 text

PHP dot env https://github.com/vlucas/phpdotenv

Slide 89

Slide 89 text

load(); Load .env # .env MYAPP_S3_PRIVATE_FILES_BUCKET=yourbucket

Slide 90

Slide 90 text

Building the box - Should be reusable - Eliminate hard dependencies on environment - Give control to the environment

Slide 91

Slide 91 text

Summary - Less manual steps, eliminate the humans - Lose the fear: test your stuff - Deploy more often, don't postpone - Deployment shouldn't cause downtime - A deployment should be repeatable

Slide 92

Slide 92 text

Other questions? @willemjanz Please leave some feedback! joind.in/talk/73636