Slide 1

Slide 1 text

Drupal  Camp  Taipei  2014 2014.08.29(Fri) Developing  Drupal  Website   with   Vagrant  and  Docker Fun. Creative. Collaboration.

Slide 2

Slide 2 text

染⽥田  貴志 SOMEDA  Takashi @tksmd Nulab  Inc. Tech  Evangelist

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

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/

Slide 6

Slide 6 text

http://backlogtool.com/git-‐‑‒guide/en/ Git  Beginnerʼ’s  Guide  For  Dummies

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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/

Slide 9

Slide 9 text

Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy  Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow

Slide 10

Slide 10 text

https://www.flickr.com/photos/andrec/2893549851/ 1.  Our  First  Drupal  Website

Slide 11

Slide 11 text

developer.nulab-‐‑‒inc.com

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Why  Drupal  ? •  Each  services  has  own  tool  to  generate  documents •  Want  to  reuse  these  tools  as  much  as  possible  

Slide 14

Slide 14 text

Why  Drupal  ? •  Discussion  Forum •  Account  integration  with  original  service

Slide 15

Slide 15 text

Why  Drupal  ? •  Run  sample  code  within  browser •  Tied  with  tutorial  documentation

Slide 16

Slide 16 text

Create  Sample  Modules https://github.com/nulab/drupalcamp-‐‑‒kyoto-‐‑‒2014

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Vagrant http://www.vagrantup.com/

Slide 20

Slide 20 text

Work  with  Various  Tools •  “Provider”  provides  virtual  environment. •  “Provisioner”  configures  given  environment. Provider Provisioner

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

Vagrant  eliminates •  Independent  development  environment •  Share  the  environment  with  others

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

Docker https://www.docker.com/

Slide 27

Slide 27 text

Quick!  Quick!  Quick! •  Container  type  virtualization •  Layer  of  Union  File  System,  AUFS http://docs.docker.com/terms/layer/#union-‐‑‒file-‐‑‒system

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

Build  and  Ship  Image •   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 /drupalcamp:0.1.0 $ docker push /drupalcamp:0.1.0

Slide 30

Slide 30 text

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 / drupalcamp:0.1.0

Slide 31

Slide 31 text

Server  configuration •  Reverse  proxy  to  Apache  running  on  Docker •  Container  is  easily  replacable

Slide 32

Slide 32 text

https://www.flickr.com/photos/mhxbhd/3962410821/ 4.  Overall  Workflow

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Developing  Phase •  All  project  files  managed  under  Git •  Share  “Backup  &  Migrate”  sql  when  restoring  contents VM Files VM Files push  &  pull push  &  pull

Slide 35

Slide 35 text

Production  Update •  For  themes/modules  update,  replacing  container •  API  documentation  updated  by  custom  scripts $ docker pull /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 / drupalcamp:0.1.1

Slide 36

Slide 36 text

Blue-‐‑‒Green  Deployment •  Blug-‐‑‒Green  deployment  within  an  EC2  instance •  Enable  quick  restore  to  previous  version Blue Green Switch upstream  server when  update

Slide 37

Slide 37 text

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  

Slide 38

Slide 38 text

http://www.flickr.com/photos/munaz/2498380666/ Summary

Slide 39

Slide 39 text

Agenda 1.  Our  First  Drupal  Website 2.  Build  and  Destroy  Environment 3.  Deploy  Docker  Container  to  Server 4.  Overall  Workflow

Slide 40

Slide 40 text

Thank  You!! If  you  have  question, feel  free  to  mention  to @tksmd