deploy and scale your php app with aws elasticbeanstalk and docker- phptour luxembourg 2015

39
Deploy and Scale your PHP App using Docker containers and AWS Beanstalk Walter Dal Mut @walterdalmut - github.com/wdalmut

Upload: corley-srl

Post on 18-Jul-2015

641 views

Category:

Software


8 download

TRANSCRIPT

Page 1: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Deploy and Scale your PHP App usingDocker containers and AWS Beanstalk

Walter Dal Mut

@walterdalmut - github.com/wdalmut

Page 2: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

I'm co-founder of @CorleyCloudapplication development

infrastructure and application migration on cloud

I'm also a co-founder of @UpClooU.K. based startup: powering related content across the web

[email protected]

Page 3: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

First of all we have to agree onwhat scaling is for this talk

Page 4: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

scalability is not high availabilityScalability is the ability of a system to handle a growing amount of work in capable manner or the ability to be

enlarged to accomodate that growth (from wikipedia)

Page 5: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Adapting Infrastructures

Page 6: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

From single instances point of view

Page 7: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

It is also meaning that with fixed hardware

we have to provide the highest computing capacity

Page 8: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Money wasters?

Page 9: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

With Cloud Providers

Page 10: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

About ElasticBeanstalkLoad Balanced web applications

Single instance web applications

Queue daemons (SQS)

Page 11: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Load balanced web applications

Page 12: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Autoscalable infrastructures

Page 13: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

thresholds are used tocreate and remove instances

Page 14: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

with (auto)scalable infrastructuresHow to manage application upgradesHow to monitor serversHow to handle servers configurationsHow to handle instances logs...

ElasticBeanstalk help us with this things

Page 15: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Application Deploy

Page 16: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Mainly Beanstalk takes a ZIP artifact (the PHP application)

and unpack it into the environmentUses YML definitions in order to setup the environment

Page 17: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

The deploy cycle take care of:1. Packages2. Users & Groups3. Files4. Commands

before the application and web server are set up5. Services6. Container_commands

just before the application version is deployed

Page 18: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Configure PHP detailsfiles:  "/etc/php.d/my­timezone.ini" :    mode: "000644"    owner: root    group: root    content: |      date.timezone = Europe/Rome

You can also use beanstalk options

Page 19: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

extract your application logscommands:    21_application_logs:        command: echo "/var/app/current/app/logs/*.log" > app.conf        cwd: /opt/elasticbeanstalk/tasks/bundlelogs.d    22_application_logs:        command: echo "/var/app/current/app/logs/*.log" > app.conf        cwd: /opt/elasticbeanstalk/tasks/systemtaillogs.d    23_application_logs:        command: echo "/var/app/current/app/logs/*.log" > app.conf        cwd: /opt/elasticbeanstalk/tasks/taillogs.d    24_application_logs:        command: echo "/var/app/current/app/logs/*.log" > app.conf        cwd: /opt/elasticbeanstalk/tasks/publishlogs.d

And check them directly from the web console

Page 20: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Beanstalk works with differentapplication containers

PHP, Node.js, Tomcat, Python, Ruby

and...

Docker & Multicontainer DockerMulticontainer Docker is connected to ElasticContainer Service

Page 21: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Why docker is interesting forElasticBeanstalk?

When there is a default PHP container withdifferent available versions: 5.3, 5.4, 5.5, 5.6

Page 22: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Instances are Amazon LinuxDifficult to configure a different distro: ubuntu, debian ...

Even packages: supervisors, agents etc.

Difficult to replicate the env locally (dev).

Page 23: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Default PHP container configuration

{{ Apache - MOD_PHP }}

Page 24: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

The application path changeafter the deploy cycle

/var/app/ondeck -> /var/app/current

Symfony2 cache warmup problems...

Page 25: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

With Docker we can create a morededicated setup

{{ Nginx - PHP-FPM }}

Page 26: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

The docker environment is more stableand testable than the default one

Thanks to the docker isolation nature

File are uncompressed into: /var/app/current

Page 27: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Prepare a web serverFROM ubuntu:14.04

RUN apt­get update && apt­get install ­y php5 apache2 libapache2­mod­php5 \    php5­apcu php5­curl php5­mongo php5­xsl && rm ­rf /var/lib/apt/lists/*

RUN a2enmod rewrite deflate expires headers

EXPOSE 80

CMD ["/usr/sbin/apache2ctl", "­D", "FOREGROUND"]

prepare your Dockerfile

Page 28: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

You can build the container during thedeploy cycle

Just let the `Dockerfile` in the root folder of your project

Page 29: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

docker build -t wdalmut/webserver .docker push

Page 30: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Docker containers are engaged with:https://registry.hub.docker.com/

+ automated builds! (keep container up to date automatically)

Already provisioned containers

Page 31: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

You can use itfor your development

docker pull wdalmut/webserver

docker run   -p 8080:80   -v ̀pwd̀:/var/www/html   -d wdalmut/webserver

Use Vagrant docker provisioner for your dev environments

Page 32: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Same environment in ElasticBeanstalkDockerrun.aws.json

{  "AWSEBDockerrunVersion": "1",  "Image": {    "Name": "wdalmut/webserver",    "Update": "true"  },  "Ports": [    {      "ContainerPort": "80"    }  ],  "Volumes": [    {      "HostDirectory": "/var/app/current",      "ContainerDirectory": "/var/www/html"    }  ],  "Logging": "/var/log/app"}

Page 33: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Beanstalk proxieswith nginx

your first exposed port80 -> EXPOSE *****[, ******]

Page 34: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Ok, we have the infrastructure

And about the application setup?

Page 35: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

App tuning with environment variables

<?php $env = getenv("SYMFONY__ENV");

Page 36: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

download config files from S3Resources:    AWSEBAutoScalingGroup:        Type: "AWS::AutoScaling::AutoScalingGroup"        Metadata:            AWS::CloudFormation::Authentication:                S3AccessCred:                    type: "S3"                    roleName: "aws­elasticbeanstalk­ec2­role"                    buckets: "myapp­deploy"

files:    "/root/parameters.yml":        mode: "000400"        owner: root        group: root        source: https://s3­eu­west­1.amazonaws.com/myapp­deploy/parameters.yml

container_commands:     01_copy_configuration:         command: cp /root/parameters.yml app/config/parameters.yml

remember that EC2 IAM roles should be configured correctly

Page 37: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

EC2 Role configuration{    "Version": "2012­10­17",    "Statement": [        {            "Sid": "Stmt1305192283000",            "Effect": "Allow",            "Action": [                "s3:*"            ],            "Resource": [                "arn:aws:s3:::app­deploy/",                "arn:aws:s3:::app­deploy/*"            ]        }    ]}

Could be more detailed and restricted than this example

Page 38: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

You cannot use PHP from the host (it is in the docker container)...

You have to pass commands via docker containers

docker run   --rm -i -t   -v /var/app/current:/var/www/html   wdalmut/webserver   app/console ca:cl -e=prod

Page 39: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

Thanks for listening