drupalcon prague 2013: automate drupal deployments with linux containers, docker and vagrant

43
Automate Drupal deployments with Linux Containers, Vagrant and Docker An overview of deployment strategies @ricardoamaro

Upload: drupalcon

Post on 30-Nov-2015

4.609 views

Category:

Documents


1 download

DESCRIPTION

The problem(s) of Full virtual servers:- Consume another layer of system memory.- IO is slower than the actual real system and makes Drupal sluggish to respond.- Are very complex to configure.- Drupal needs faster automated deployments solutions.- Costumers need full shell access, with services admin.The proposed solution:- Linux containers with vagrant & docker automatic deployments.https://github.com/ricardoamaro/drupal-lxc-vagrant-dockerhttps://github.com/ricardoamaro/docker-drupalLXC is a lightweight virtualization method that provides operating system-level virtualization optional to an heavy full virtual machine. It relies on the Linux kernel cgroups functionality that became available in version 2.6.24, It provides a virtual environment that has its own process and network space. This option makes the perfect option for deploying several contained Drupal dev environments independent of the distribution.Docker is a solution from dotCloud, which simplifies and improves the process of creating and managing Linux containers.Vagrant 1.1+ lxc plugin allows it to control and provision Linux Containers as an alternative to the built in (and heavy) Vagrant VirtualBox provider for Linux hosts.

TRANSCRIPT

Page 1: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Automate Drupal deployments with Linux Containers, Vagrant and Docker

An overview of deployment strategies@ricardoamaro

Page 2: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Free/Opensource software loverSenior Cloud Engineer @AcquiaDrupal.org infrastructure/devopsDrupalist & Linux enthusiast

Father, artist, community facilitator

@ricardoamaro

About me

Page 3: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Vicente e Dália

About us

Page 4: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

1. The sad VirtualMachine story

2. Containers and non-containers

3. Drupal on LXC

4. How to Puppetize a container

5. Docker & LXC

6. Shipping containers with Drupal

today’s agenda

Page 5: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Hardware virtualization or platform virtualization refers to the creation of a virtual machine that acts like a real computer with an operating system.

Software executed on these virtual machines is separated from the underlying hardware resources.

What is virtualization?

Page 6: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Cloud infrastructure providers like Amazon Web Service sell virtual machines. EC2 revenue is expected to surpass $1B in revenue this year. That's a lot of VMs…

Why should i care?Increase

+ efficiency+ availability+ security

Reduce

- costs- hardware- energy

Page 7: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Virtual Machine platforms

Page 8: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

➢ We are also paying for lot of avoidable overhead.

➢ The Virtual Machine is a full-blown operating system image.

➢ This is a heavyweight solution to run applications in the cloud.

The sad Virtual Machine story...

Page 9: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

What is the solution?

Page 10: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Containers used to be terrible, but not anymoreContainers used to be terrible, but not anymore

A new concept, a new hope

Page 11: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Because LXC is ready to roll!

Page 12: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

On any recent Linux Kernel near you!

Page 13: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Source : http://www.linuxjournal.com/content/containers%E2%80%94not-virtual-machines%E2%80%94are-future-cloud

Virtual Machines vs Containers

Virtualization and paravirtualization require a full operating system image for each instance.

Page 14: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Source : http://www.linuxjournal.com/content/containers%E2%80%94not-virtual-machines%E2%80%94are-future-cloud

Virtual Machines vs Containers

Containers can share a single Linux Kernel and, optionally, other binary and library resources.

Page 15: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

The time to provision

Source : http://www.linuxjournal.com/content/containers%E2%80%94not-virtual-machines%E2%80%94are-future-cloud

Page 16: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

mount /dev/sda /targetchroot /target

but that had no resource and security isolation goals for multi-tenant designs...

From the simple concept of “chroot”

source: http://openvz.org

Page 17: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

CpuDevicesProcessesMemoryDisk spaceNetwork

Wha

t if y

ou co

uld

cont

rol..

.

Page 18: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Openvz & LXC

Needcontrol over specifichost resources

cgroupsControl Groups provide a mechanism for aggregating/partitioning sets of tasks, and all their future children, into hierarchical groups with specialized behaviour.

~$ ls /sys/fs/cgroupblkio cpu cpuacct cpuset devices freezer hugetlb memory perf_event

example:

lxc-cgroup -n foo cpuset.cpus "0,3"

Containers & Cgroups

https://www.kernel.org/doc/Documentation/cgroups/cgroups.txt

Page 19: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

ricardo@ricardo-box:~$ sudo lxc-checkconfig Kernel configuration not found at /proc/config.gz; searching...Kernel configuration found at /boot/config-3.8.0-26-generic--- Namespaces ---Namespaces: enabledUtsname namespace: enabledIpc namespace: enabledPid namespace: enabledUser namespace: missingNetwork namespace: enabledMultiple /dev/pts instances: enabled

--- Control groups ---Cgroup: enabledCgroup clone_children flag: enabledCgroup device: enabledCgroup sched: enabledCgroup cpu account: enabledCgroup memory controller: enabledCgroup cpuset: enabled

--- Misc ---Veth pair device: enabledMacvlan: enabledVlan: enabledFile capabilities: enabled

Note : Before booting a new kernel, you can check its configurationusage : CONFIG=/path/to/config /usr/bin/lxc-checkconfig

LXC on Ubuntu

Page 20: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Since Ubuntu 12.04, containers are constrained by apparmor by default

- /usr/bin/lxc-start is automatically transitioned to its own profile, where it is only allowed to mount into the

container’s tree.

- The default policy attempts to protect the host from accidental container abuses – such as writing to /proc/sysrq-

trigger and /proc/mem,

- Each container configuration can specify a custom profile.

On Ubuntu 13.04 - We are able to exploit user namespaces and support stacked apparmor profiles

- Apport hooks for better debug support,

- Greater scriptability by providing a liblxc api.

By 14.04User namespace should support container use by unprivileged users.

Other resources:

http://www.ibm.com/developerworks/linux/library/l-lxc-security/index.html

https://wiki.ubuntu.com/LxcSecurity

http://wiki.ubuntu.com/UserNamespace

LXC Security with Apparmor

Page 21: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Wait…I don’t have to use heavy virtualboxes?

Let’s start with Vagrant and puppetize it!

You just need that guy

Page 22: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

You will get:

1. Drupal (latest version)

2. Nginx

3. Php + php-fpm

4. Mysql

5. Phpmyadmin

6. xhprof

7. xdebug

8. composer

https://github.com/ricardoamaro/drupal-lxc-vagrant-docker

My contribution to Drupal Containers

Page 23: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Install latest Vagrant from: http://downloads.vagrantup.com/tags/v1.2.7 or later.

Install lxc + redir.

sudo dpkg -i vagrant_1.2.7_x86_64.deb

sudo apt-get install lxc redir

Vagrant LXC (demo) - Install

Page 24: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Get the code from:https://github.com/ricardoamaro/drupal-lxc-vagrant-docker

git clone [email protected]:ricardoamaro/drupal-lxc-vagrant-docker.

git

cd ~/drupal-lxc-vagrant-docker

1 - Clone the code

Page 25: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

vagrant plugin install vagrant-lxc

vagrant up --provider=lxc

sudo lxc-ls --fancy

# redirect port 80 to the host

sudo redir --lport=80 --cport=80 --caddr={container ip} &

# and/or edit the /etc/hosts file with:

${IP} drupal phpmyadmin xhprof

2 - Get the plugin & deploy

Page 26: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Now…

I have to

build this

every time?

Page 27: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT
Page 28: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

use Docker

Page 29: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Docker Who??

Page 30: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

this Docker

and ship them has containers

Page 31: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Ship containers? Build Once, Run Anywhere

Page 32: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Install docker:

sudo apt-get -y install dockercurl get.docker.io | sudo sh -x

Import container to docker:

sudo tar -C /var/lib/lxc/{container name}/rootfs/ -c . | sudo docker import - dev/drupal

Start docker:

sudo docker run -i -t -p :80 dev/drupal /bin/bash

The image is already pushed to https://index.docker.io, and can be pulled using:

sudo docker pull ricardoamaro/drupal

You can ship your image into a Docker container

Page 33: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

https://github.com/ricardoamaro/docker-drupal

https://github.com/ricardoamaro/docker-drupal-nginx

Or... build it the Docker way:

Page 35: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

the Commands: attach Attach to a running container

commit Create a new image from a container's changes

diff Inspect changes on a container's filesystem

export Stream the contents of a container as a tar archive

history Show the history of an image

images List images

import Create a new filesystem image from the contents of a tarball

info Display system-wide information

inspect Return low-level information on a container

kill Kill a running container

login Register or Login to the docker registry server

logs Fetch the logs of a container

port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT

ps List containers

pull Pull an image or a repository to the docker registry server

push Push an image or a repository to the docker registry server

restart Restart a running container

rm Remove a container

rmi Remove an image

run Run a command in a new container

start Start a stopped container

stop Stop a running container

tag Tag an image into a repository

version Show the docker version information

wait Block until a container stops, then print its exit code

The docker is awesome!

the Apihttp://docs.docker.io/en/latest/api/registry_index_spec/

the Registryhttp://docs.docker.io/en/latest/api/index_api/

Page 36: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Docker on Docker (v0.6)

Page 37: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Container layers to be used for hosting applications

Continuous Deployments & Development

Page 38: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Changes to the container can be committed to the central index or rolled back

Just commit the good apples

Page 40: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

“Nova is intended to be modular and easy to extend and adapt. It supports manydifferent hypervisors (KVM and Xen to name a few), different database backends(SQLite, MySQL, and PostgreSQL, for instance), different types of userdatabases (LDAP or SQL), etc.”

And it supports Docker containers!

This project is open-source and available at: https://github.com/dotcloud/openstack-docker.

...with the Nova driver

Page 41: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

Develop the box in layersUse only one Linux KernelDeploy quicklyBuild Once, Run Anywhere

Awesomeness!

Page 42: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

@ricardoamaro

Questions?

Locate this session at the DrupalCon Prague website:https://prague2013.drupal.org/node/388

Click the “Take the survey” link

Page 43: DrupalCon Prague 2013: AUTOMATE DRUPAL DEPLOYMENTS WITH LINUX CONTAINERS, DOCKER AND VAGRANT

THANK YOU!

@ricardoamaro

Locate this session at the DrupalCon Prague website:https://prague2013.drupal.org/node/388

Click the “Take the survey” link