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

Developing Drupal Website with Vagrant and Do...

Developing Drupal Website with Vagrant and Docker

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

株式会社ヌーラボ

August 29, 2014
Tweet

More Decks by 株式会社ヌーラボ

Other Decks in Technology

Transcript

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

      Vagrant  and  Docker Fun. Creative. Collaboration.
  2. 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/
  3. 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
  4. 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/
  5. Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy

     Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow
  6. Why  Drupal  ? •  Each  services  has  own  tool  to

     generate  documents •  Want  to  reuse  these  tools  as  much  as  possible  
  7. Work  with  Various  Tools •  “Provider”  provides  virtual  environment. • 

    “Provisioner”  configures  given  environment. Provider Provisioner
  8. 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: "172.28.128.4" 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 127.0.0.1, -c local main.yml -vvv -e provisioned_env=vagrant" end Provider Synced   Folder Provisioner
  9. 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
  10. 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
  11. Quick!  Quick!  Quick! •  Container  type  virtualization •  Layer  of

     Union  File  System,  AUFS http://docs.docker.com/terms/layer/#union-‐‑‒file-‐‑‒system
  12. Dockerfile FROM phusion/baseimage:0.9.13 MAINTAINER someda "[email protected]" 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 127.0.0.1, -c local main.yml - vvv -e provisioned_env=docker Base  Image Copy   Drupal  Files Provision
  13. 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
  14. 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
  15. 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
  16. Developing  Phase •  All  project  files  managed  under  Git • 

    Share  “Backup  &  Migrate”  sql  when  restoring  contents VM Files VM Files push  &  pull push  &  pull
  17. 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
  18. Blue-‐‑‒Green  Deployment •  Blug-‐‑‒Green  deployment  within  an  EC2  instance • 

    Enable  quick  restore  to  previous  version Blue Green Switch upstream  server when  update
  19. 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  
  20. Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy

     Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow