Share
Embed
Self Contained Deployment
Love story between Docker and Packer to transform your configuration management in a self contained application to run like a binary
Rach Belaid
September 19, 2014
Transcript
33 slides
-
About Me • Python developer • Love Ops • Run
the Pyramid Meetup in London • Defender of Postgres, RDMS and SQL • Hack with Haskell, Erlang, Rust in my spare time on twitter : @rachbelaid -
What Self-contained means? • No dependency required to run •
State Less • Simplify shipping code to ship more often • the Holy Grail of deployment Running an application like a binary -
Why Self-Contained? • Easy to deploy. Easy like a binary?
• Easy to test/run • Component base architecture • Continuous delivery • Functional programming of deployment -
Immutable server : pros • Beautiful in theory • Versioned
• Easy rollback -
Immutable server : cons • Hard • Can be slow
(boot and create images) • Require a VPS architecture • Not testable locally -
Is Configuration Management the answer? • Repetitive • No rollback
• Not always deterministic (distro, updates, …) • Tendency to create a monolithic platform • Often too slow Great, but : -
Daily DevOps workflow • vagrant up • Read HackerNews •
20min later, notice that it failed • vagrant provision • Read more HackerNews • Success!! We just want to download and run it -
What is docker The docker project offers higher-level tools, working
together, which are built on top of some Linux kernel features. It’s providing an additional layer of abstraction and automation of operating system–level virtualization on Linux. -
What is docker • Framework / Toolkit to create containers
• Platform to build distributed app and link them together • Build application container which run everywhere • Faster than normal VM and more convenient -
Docker goal The goal is to help developers and system
administrators port applications - with all of their dependencies conjointly - and get them running across systems and machines - headache free. -
Enter Packer • Packer is a tool for creating identical
machine images for multiple platforms from a single source configuration • Packer can help you build Docker containers * • Allow to transition and experiment with docker container • Glue between Configuration management and Docker *not on MacOS / Win -
What’s Packer? Provisioner (shell) Provisioner ( … ) Provisioner (ansible)
Builder (AWS AMI) Builder (Docker container) Builder (Docker container) Post Processor (Vagrant Box) Post Processor (Docker push) -
Environment setup Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64" config.vm.provision "docker"
do |d| end end To get a VM ready to use! vagrant up && vagrant ssh wget https://dl.bintray.com/mitchellh/packer/ packer_0.7.1_linux_amd64.zip ! unzip packer_0.7.1_linux_amd64.zip -d ~/packer export PATH=$PATH:~/packer/ -
Example : structure . ├── ansible │ ├── app.yaml │
└── templates │ ├── app.py │ └── supervisord.conf └── build.json -
Example: Ansible provisioning - hosts: all tasks: - name: Install
application requirements apt: pkg={{ item }} state=latest with_items: - supervisor - build-essential - python - python-pip - python-dev -
Example: Ansible provisioning (part 2) ... - name: Install python
requirement pip: name={{ item }} state=present with_items: - pyramid - uwsgi - name: Supervisor template template: > dest=/etc/supervisor/supervisord.conf src=templates/supervisord.conf - name: add App template: dest=/srv/app.py src=templates/app.py -
Example: Packer file {"provisioners": [ { "type": "shell", "inline": [
"sudo add-apt-repository ppa:rquillo/ansible -y", "apt-get update", "apt-get install -y sudo ansible python-apt" ]}, { "type": "ansible-local", "playbook_dir": "ansible", "playbook_file": "ansible/app.yaml" } ], "builders": [{ "type": "docker", "image": "ubuntu", "export_path": "app.tar" }]} -
Example: Python Web App from pyramid.config import Configurator from pyramid.view
import view_config ! @view_config(route_name='hello', renderer='json') def hello(request): return {'status': 'Hello World'} ! def application(): config = Configurator() config.add_route('hello', '/') config.scan() return config.make_wsgi_app() ! app = application() -
Example : Supervisor File [program:app] command= uwsgi --http :80 --wsgi-file
/srv/app.py --callable app [supervisord] # required by supervisord -
Import it docker import - pyconuk/myapp < app.tar app.tar contains
everything needed to run -
Run it $> docker run -p 8080:80 pyconuk/myapp supervisord --nodaemon
$> curl localhost:8080 {"status": "Hello World"} Success!! -
Who is using/supporting Docker • Google, Microsoft, Amazon, Red Hat,
Digital Ocean, • Real Projects using it : New Relics, Circle Ci, .. • Exciting projects: Panamax, Fig, ClusterHq • Loads of Millions $$$ • Production ready (ish)!! -
What are the benefits • Integrate Easily in CI to
do Continuous Delivery • Move to an archicteture using Microservices / SOA • Access to great tools to build cluster & distributed system : Mesos / CoreOS / Mesosphere • Isolation and Sandboxing • Great to limit CPU / IO / Memory resources (DOS, QOS, PAAS) -
Introducing new tech is hard • Small changes • Iterative
• Real beneficial improvement (solve a real problem) Suggestion: