Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015
-
Upload
corley-srl -
Category
Software
-
view
643 -
download
8
Transcript of Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015
![Page 1: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/1.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/2.jpg)
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
![Page 3: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/3.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/4.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/5.jpg)
Adapting Infrastructures
![Page 6: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/6.jpg)
From single instances point of view
![Page 7: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/7.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/8.jpg)
Money wasters?
![Page 9: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/9.jpg)
With Cloud Providers
![Page 10: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/10.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/11.jpg)
Load balanced web applications
![Page 12: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/12.jpg)
Autoscalable infrastructures
![Page 13: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/13.jpg)
thresholds are used tocreate and remove instances
![Page 14: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/14.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/15.jpg)
Application Deploy
![Page 16: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/16.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/17.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/18.jpg)
Configure PHP detailsfiles: "/etc/php.d/mytimezone.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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/19.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/20.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/21.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/22.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/23.jpg)
Default PHP container configuration
{{ Apache - MOD_PHP }}
![Page 24: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/24.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/25.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/26.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/27.jpg)
Prepare a web serverFROM ubuntu:14.04
RUN aptget update && aptget install y php5 apache2 libapache2modphp5 \ php5apcu php5curl php5mongo php5xsl && 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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/28.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/29.jpg)
docker build -t wdalmut/webserver .docker push
![Page 30: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/30.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/31.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/32.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/33.jpg)
Beanstalk proxieswith nginx
your first exposed port80 -> EXPOSE *****[, ******]
![Page 34: Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/34.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/35.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/36.jpg)
download config files from S3Resources: AWSEBAutoScalingGroup: Type: "AWS::AutoScaling::AutoScalingGroup" Metadata: AWS::CloudFormation::Authentication: S3AccessCred: type: "S3" roleName: "awselasticbeanstalkec2role" buckets: "myappdeploy"
files: "/root/parameters.yml": mode: "000400" owner: root group: root source: https://s3euwest1.amazonaws.com/myappdeploy/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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/37.jpg)
EC2 Role configuration{ "Version": "20121017", "Statement": [ { "Sid": "Stmt1305192283000", "Effect": "Allow", "Action": [ "s3:*" ], "Resource": [ "arn:aws:s3:::appdeploy/", "arn:aws:s3:::appdeploy/*" ] } ]}
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/38.jpg)
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](https://reader031.fdocuments.in/reader031/viewer/2022020208/55aa06871a28abba338b493c/html5/thumbnails/39.jpg)
Thanks for listening