Self Contained Deployment

F0b6891740978c069990b45bc7bfd58a?s=47 Rach Belaid
September 19, 2014

Self Contained Deployment

Love story between Docker and Packer to transform your configuration management in a self contained application to run like a binary

F0b6891740978c069990b45bc7bfd58a?s=128

Rach Belaid

September 19, 2014
Tweet

Transcript

  1. 2.

    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
  2. 3.

    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
  3. 4.

    Why Self-Contained? • Easy to deploy. Easy like a binary?

    • Easy to test/run • Component base architecture • Continuous delivery • Functional programming of deployment
  4. 8.

    Immutable server : cons • Hard • Can be slow

    (boot and create images) • Require a VPS architecture • Not testable locally
  5. 9.

    Is Configuration Management the answer? • Repetitive • No rollback

    • Not always deterministic (distro, updates, …) • Tendency to create a monolithic platform • Often too slow Great, but :
  6. 10.

    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
  7. 12.

    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.
  8. 13.

    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
  9. 14.

    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.
  10. 16.

    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
  11. 17.

    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)
  12. 19.

    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/
  13. 20.

    Example : structure . ├── ansible │ ├── app.yaml │

    └── templates │ ├── app.py │ └── supervisord.conf └── build.json
  14. 21.

    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
  15. 22.

    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
  16. 23.

    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" }]}
  17. 24.

    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()
  18. 25.

    Example : Supervisor File [program:app] command=
 uwsgi --http :80 --wsgi-file

    /srv/app.py --callable app [supervisord] # required by supervisord
  19. 28.

    Run it $> docker run -p 8080:80 pyconuk/myapp supervisord --nodaemon

    $> curl localhost:8080 {"status": "Hello World"} Success!!
  20. 29.

    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)!!
  21. 31.

    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)
  22. 32.

    Introducing new tech is hard • Small changes • Iterative

    • Real beneficial improvement (solve a real problem) Suggestion: