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

Developing Drupal Website with Vagrant and Docker

Developing Drupal Website with Vagrant and Docker

Presentation Slides at Drupal Camp 2014 Taipei http://2014.drupalcamp.tw/


Nulab Inc.

August 29, 2014


  1. Drupal  Camp  Taipei  2014 2014.08.29(Fri) Developing  Drupal  Website   with

      Vagrant  and  Docker Fun. Creative. Collaboration.
  2. 染⽥田  貴志 SOMEDA  Takashi @tksmd Nulab  Inc. Tech  Evangelist

  3. None
  4. None
  5. Backlog  is  a  project  management  tool  that  2,700  clients  use.

    In  addition  to  issue  management  feature,  Backlog  provides •  File  sharing  by  WebDAV •  Git  and  Subversion  repository  hosting. Visit  http://backlogtool.com/
  6. http://backlogtool.com/git-‐‑‒guide/en/ Git  Beginnerʼ’s  Guide  For  Dummies

  7. 1.3M  users  around  the  world  draw  wireframes,  network   diagrams,

     UML,  business  plans  and  so  on. Cacoo  provides  basic  functionality  as  a  draw  tool  and  powerful  collaborative   features  like •  Simultaneous  Editing  on  same  diagram  by  multiple  users •  Integration  with  Google  Services  like  Google  Apps,  Google  Drive  and   Google+  Hangouts
  8. A  new  collaborative  chat  app  has  just  been  out  of

     beta  this  year. •  Integration  with  nulabʼ’s  other  services •  Provide  easy-‐‑‒to-‐‑‒use  API  for  developers http://typetalk.in/
  9. Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy

     Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow
  10. https://www.flickr.com/photos/andrec/2893549851/ 1.  Our  First  Drupal  Website

  11. developer.nulab-‐‑‒inc.com

  12. Design HTML/Theme  Coding Site  Building Server  Setup Module  Development Team

  13. Why  Drupal  ? •  Each  services  has  own  tool  to

     generate  documents •  Want  to  reuse  these  tools  as  much  as  possible  
  14. Why  Drupal  ? •  Discussion  Forum •  Account  integration  with

     original  service
  15. Why  Drupal  ? •  Run  sample  code  within  browser • 

    Tied  with  tutorial  documentation
  16. Create  Sample  Modules https://github.com/nulab/drupalcamp-‐‑‒kyoto-‐‑‒2014

  17. Todayʼ’s  Sample  Code https://github.com/nulab/drupalcamp-‐‑‒taipei-‐‑‒2014

  18. http://www.flickr.com/photos/alexmartin81/5883645329/ 2.  Build  and  Destroy  Environment

  19. Vagrant http://www.vagrantup.com/

  20. Work  with  Various  Tools •  “Provider”  provides  virtual  environment. • 

    “Provisioner”  configures  given  environment. Provider Provisioner
  21. Vagrantfile Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "trusty64" config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/

    current/trusty-server-cloudimg-amd64-vagrant-disk1.box" config.vm.hostname = "drupal" config.vm.network "private_network", ip: "" config.vm.synced_folder ".", "/vagrant", disabled: true config.vm.synced_folder "www/", "/srv/www/", :owner => "www- data", :mount_options => [ "dmode=775", "fmode=774" ] config.vm.synced_folder "provision/", "/srv/provision” config.vm.provision "shell", path: "install_ansible.sh" config.vm.provision "shell", inline: "cd /srv/provision; ansible- playbook -i, -c local main.yml -vvv -e provisioned_env=vagrant" end Provider Synced   Folder Provisioner
  22. Just  Do  “vagrant  up” •  “vagrant  destroy”  to  discard  current

     environment •  Trial-‐‑‒and-‐‑‒Error  support  by  vagrant  sahara  plugin $ git clone https://github.com/nulab/drupalcamp-taipei-2014.git $ cd drupalcamp-taipei-2014.git $ vagrant up
  23. Synced  Folder •  No  need  to  transfer  your  source  files

     to  VM •  Consider  using  NFS  if  all  members  are  using  Mac VM Changes  added  to  the  files   under  certain  directories   synced  automatically
  24. Vagrant  eliminates •  Independent  development  environment •  Share  the  environment

     with  others
  25. https://www.flickr.com/photos/dahlstroms/3144199355 3.  Deploy  Docker  Container  to  Server

  26. Docker https://www.docker.com/

  27. Quick!  Quick!  Quick! •  Container  type  virtualization •  Layer  of

     Union  File  System,  AUFS http://docs.docker.com/terms/layer/#union-‐‑‒file-‐‑‒system
  28. Dockerfile FROM phusion/baseimage:0.9.13 MAINTAINER someda "someda@nulab-inc.com" CMD ["/sbin/my_init"] RUN /usr/sbin/enable_insecure_key

    ADD ./www /srv/www RUN chown -R www-data. /srv/www RUN rm -fr /srv/www/sites/default/settings.php ADD ./provision /srv/provision ADD ./install_ansible.sh /var/tmp/install_ansible.sh RUN /bin/bash /var/tmp/install_ansible.sh RUN cd /srv/provision; ansible-playbook -i, -c local main.yml - vvv -e provisioned_env=docker Base  Image Copy   Drupal  Files Provision
  29. Build  and  Ship  Image •  <your.repo>  is  in-‐‑‒house  docker  registry

    •  docker  registry  is  provided  as  docker  container # Build $ docker build -t drupalcamp-2014-taipei . # Ship $ docker tag drupalcamp-2014-taipei <your.repo>/drupalcamp:0.1.0 $ docker push <your.repo>/drupalcamp:0.1.0
  30. Just  Do  “docker  run” •  Use  settings.php  existing  outside  of

     container •  Mapping  containerʼ’s  port  80  port  to  host  port  8080 $ docker run --name drupalcamp -p 8080:80 –d –v /path_to/ settings.php:/srv/www/sites/default/settings.php <your.repo>/ drupalcamp:0.1.0
  31. Server  configuration •  Reverse  proxy  to  Apache  running  on  Docker

    •  Container  is  easily  replacable
  32. https://www.flickr.com/photos/mhxbhd/3962410821/ 4.  Overall  Workflow

  33. Project  Structure $ tree -L 2 . "## Dockerfile "##

    README.md "## Vagrantfile "## install_ansible.sh "## provision $ "## apache.yml $ "## docker.yml $ "## drupal.yml $ "## files $ "## main.yml $ &## vagrant.yml &## www "## CHANGELOG.txt "## COPYRIGHT.txt "## INSTALL.mysql.txt "## INSTALL.pgsql.txt "## INSTALL.sqlite.txt "## INSTALL.txt | Ansible  Configuration Drupal  Files
  34. Developing  Phase •  All  project  files  managed  under  Git • 

    Share  “Backup  &  Migrate”  sql  when  restoring  contents VM Files VM Files push  &  pull push  &  pull
  35. Production  Update •  For  themes/modules  update,  replacing  container •  API

     documentation  updated  by  custom  scripts $ docker pull <your.repo>/drupalcamp:0.1.1 $ docker stop drupalcamp $ docker rm drupalcamp $ docker run --name drupalcamp -p 8080:80 –d –v /path_to/ settings.php:/srv/www/sites/default/settings.php <your.repo>/ drupalcamp:0.1.1
  36. Blue-‐‑‒Green  Deployment •  Blug-‐‑‒Green  deployment  within  an  EC2  instance • 

    Enable  quick  restore  to  previous  version Blue Green Switch upstream  server when  update
  37. Continuous  Integration •  Creating  and  testing  of  Docker  image  automatically

    •  Reduce  the  risk  of  building  issue  of  Docker  image 1.   Start  Jenkins  Job   when  commit   pushed  to  the   repository 2.   Run  docker  build   to  create  new   image  and  test  it   by  serverspec 3.   If  test  successful,   the  new  image  is   pushed  to  the   docker  registry  
  38. http://www.flickr.com/photos/munaz/2498380666/ Summary

  39. Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy

     Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow
  40. Thank  You!! If  you  have  question, feel  free  to  mention

     to @tksmd