Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Workshop - Building a Baby PaaS with Vagrant, D...

Daniel Gomes
September 29, 2013

Workshop - Building a Baby PaaS with Vagrant, Docker.io and Node.js @ LXJS 2013

In this workshop you will build a baby PaaS from scratch. Starting with your development environment using Vagrant and ending with some Docker.io and Node.js magic.

When you are building a project that needs development time and constant care across all stack, for example devops tools or PaaS related software, the complexity of your development environment will quickly increase.

You will learn how to use Vagrant in order to leverage this task saving you precious time. Using this new development environment you will fiddle with Docker.io using Node.js while building a step­by­step basic PaaS using containers running on top of a Vagrant Virtual Machine. With your new ninja Docker skills, you will develop all container logic and control using Docker’s Remote API, implement container abstraction, scalable workers and balancer.

Daniel Gomes

September 29, 2013
Tweet

More Decks by Daniel Gomes

Other Decks in Programming

Transcript

  1. 1 Building with Docker.io, Vagrant and Node.js a baby PaaS

    Pedro Dias @pedromdias workshop Daniel Gomes @danielcsgomes September 29, 2013
  2. AGENDA • What is Vagrant • What is Docker •

    Let's get our hands dirty! :) 2
  3. 4 ABOUT PEDRO DIAS • Full Stack Engineer @ PTisp

    • Lecturer @ Polytechnic Institute of Tomar • Father, petrolhead and hiker • @pedromdias • apocas
  4. • Manage virtual machines (such as Virtual Box, VMware, AWS)

    • Define the configuration in code using a single file • Can use Shell scripts, Puppet, Chef and other tools to provisioning the Virtual Machines • Written in Ruby 6
  5. Workflow of vagrant up 13 Vagrantfile Provisioning manifest has provisioning

    manifest? yes start provisioning the VM VM is running vagrant up downloads the box if needed and loads vagrant configurations (share folders, port forwarding, etc) and starts the VM
  6. vagrant init vagrant up vagrant halt vagrant reload vagrant provision

    vagrant ssh vagrant suspend vagrant resume vagrant destroy 14 vagrant commands
  7. • Use (D)VCS (Git, SVN, Mercurial, etc.) • Add the

    Vagrantfile and provisioning files (puppet, chef, shell scripts, etc) to your repository • Add .vagrant folder to your repository ignore file or your global ignore file. 18
  8. • Sharing your dev environment saves you time and makes

    your life easier and everyone happy • Vagrant manages the Virtual Machines using a configuration file • Default provider is Virtual Box, but VMware and AWS are available too • Vagrant can provision the VM using Puppet, Chef, Shell scripts or other tools Wrap Up 19
  9. DOCKERFILE INSTRUCTIONS • FROM image:tag • MAINTAINER name • RUN

    command • EXPOSE port • ENTRYPOINT [‘cmd’, ‘arg’, ...] • USER user • ADD src dest • CMD [‘cmd’, ‘arg’, ...] 25
  10. DOCKERFILE 26 # Build the image of ubuntu 12.04 LTS

    from ubuntu:precise run apt-get -y wget # Install node.js run wget -O - http://nodejs.org/dist/v0.10.19/node-v0.10.19-linux- x64.tar.gz | tar -C /usr/local/ --strip-components=1 -zxv # Expose port 80 to the host machine expose 80
  11. CONTAINERS • attach • run • start • stop •

    diff 28 • kill • rm • logs • cp • export • ps
  12. FAMOUS RUN COMMAND 29 Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND]

    [ARG...] Run a command in a new container -a=map[]: Attach to stdin, stdout or stderr. -c=0: CPU shares (relative weight) -cidfile="": Write the container ID to the file -d=false: Detached mode: Run container in the background, print new container id -e=[]: Set environment variables -h="": Container host name -i=false: Keep stdin open even if not attached -privileged=false: Give extended privileges to this container -m=0: Memory limit (in bytes) -n=true: Enable networking for this container -p=[]: Map a network port to the container -t=false: Allocate a pseudo-tty -u="": Username or UID -dns=[]: Set custom dns servers for the container -v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "host-dir" is missing, then docker creates a new volume. -volumes-from="": Mount all volumes from the given container. -entrypoint="": Overwrite the default entrypoint set by the image. -w="": Working directory inside the container -lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"
  13. IMAGE REGISTRY • Registry != Index • Git’ish like behavior

    • pull • push • diff • search 31
  14. LOCAL SHARING • docker export 1aba8bfac7d5 > poc.tgz • cat

    poc.tgz | sudo docker import - poc • sudo docker run poc uptime 33
  15. CONNECTING • Using hostname:port pair. • 127.0.0.1:4243 • Using unix

    socket. (default since Remote API v1.3) • unix:///var/run/docker.sock 35
  16. NODE CLIENT • dockerode • https://npmjs.org/package/dockerode • API feature 100%

    implemented and tested. • Leverage streams when possible (a lot :-)) • Container and image abstraction. 36
  17. SPECIFICATION • Deployment using Git repos • Support apps from

    multiple languages • Hipache based proxy • Continuous stream 38
  18. ARCHITECTURE 39 VM1 Drone Docker OS VM2 Drone Docker OS

    Balancer CLI client ... CLI client ... Hipache
  19. DEV ENVIROMNENT • Set your name servers to: 192.241.191.162 •

    https://github.com/apocas/lxjs-dns • Answers *.lxjs.dev to10.0.5.50 (Vagrant VM IP) the rest is forwarded to 8.8.8.8 • [app_name].lxjs.dev • helloworldphp.lxjs.dev • sdf67asks9.lxjs.dev • ... 40