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

Using Git to Manage Deployments

David Kinzer
September 12, 2014

Using Git to Manage Deployments

When it comes to the strategies surrounding updates of a Drupal site there are many options to choose from; some are heavy duty, like pushing changes using Chef or Puppet and some less so, like manually logging necessary changes. But there are also strategies that lie in between these extremes.

We all know that the git command is a veritable swiss army knife of development goodies. So it should not come as a surprise that git itself can be used to manage deployments and updates. In fact, git is used internally by the likes of OpenShift and Heroku to manage the deployments of their services.

In this session I will walk you through setting up a git server that deploys changes via a git post-update hook script. Such servers are an easy way to get into continous integration without having to learn any new DSLs, and the technique can be applied to any project not just a Drupal project, whether it's hosted on your own servers or on the likes of GoDaddy or an AWS instance (etc.).

A repository related to this presentation is available for forking on Github (https://github.com/dkinzer/dkicker).

A link to better credits: https://gist.github.com/dkinzer/53816d501bd531aba586

David Kinzer

September 12, 2014
Tweet

More Decks by David Kinzer

Other Decks in Programming

Transcript

  1. • General overview of deployment. • Some Drupal specific considerations.

    • Walk through 2 part demo of technique. • Some summary statements. • Answer questions (but feel free to interrupt). Introduction
  2. Some basic terms: Git - we all love this wonderful

    little tool. Commits - Are the way to save changes. Push/Pull - Is how we share commits. Deploy - In a second... Drupal - Is a PHP CMS/Framework for building web apps.
  3. Here’s one way... > cd project > touch project.tgz &&

    tar -czvf project.tgz . > scp project.tgz somehost.com:~/project.tgz > ssh somehost.com ‘tar xvf project.tgz -C www \ && rm project.tgz && chmod 755 -R www’
  4. Makefile ---------------- deploy: bash bin/deploy.sh A little bit better might

    be... bin/deploy.sh ------------------ #!/bin/bash tar… scp … ssh ...
  5. > git pull origin master? … Sure this can move

    our files, but what about any Drupal specific consideration? But what about plain old git pull?
  6. What’s Drupal Specific Here... • Any database changes… • Enabling

    disabling modules… • Configuration changes… • Caches...
  7. Makefile ---------------- deploy: bash bin/deploy.sh Another approach might be... bin/deploy.sh

    ------------------ #!/bin/bash cd project git pull… # plus some drush magic.. drush updb drush cc all
  8. Git Supports Hooks. .git/hooks ├── applypatch-msg ├── commit-msg ├── post-update

    ├── pre-applypatch ├── pre-commit ├── prepare-commit-msg ├── pre-rebase └── update
  9. First way… > git clone --bare project > cd project.git/hooks/

    > vi post-update > cd - > git clone project.git dev > cd dev && “make changes” > git push Prepare the repos... Second Way… > git clone live dev > cd project/.git/hooks > vi post-update… (caveat) > cd ../.. > git config \ receive.denycurrentbranch false > ...
  10. To Bare or not to Bare... NOT bare is better

    IMHO because you can version control repo preparation and deployment script with the project….
  11. Photos/Illustrations Credits... • "Man Fig Miniature Wave Sit Rest Relax

    Friendly", by Anja Osenberg, CC0 1.0 • "36100 Bangladesh Air Force MIG-29 Landing with the Drogue Parachute Deployed", by Fisal Akram, CC BY-SA 2.0 • "Parachutist Skydiver Skydiving Sky Parachute", by Lynn Greyling, CC0 1.0 • "Grow Blossom Time Lapse Sequence Amaryllis Flower", by Stefan Schweihofer, CC0 1.0 • "Puzzle Cube Wood Block Toys Wooden Toys Build", by Hans Braxmeier, CC0 1.0 • "Magic", by Bart Cayusa, CC BY-SA 2.0 • "Simple Drupal Wallpaper", by Matt Farina, CC BY-SA 2.0 • "Problem Shield Note Street Sign Road Sign Sky", by Gerd Altmann, CC0 1.0 • "Drush Logo", by Dan Morrison, GPL V2 • "An Illustration to the Markandeya Purana: The Gods invoke Devi Estimate", by Unknown, Public Domain • "Livarna", by Viktorija Rozman, CC BY-SA 3.0 • "Bare Feet Foot Tanned Brown Hair Water", by Public Domain Pictures, CC0 1.0 • "Cattleman NM55 Revolver Sketch", by Don Stewart, CC BY-SA 2.0 • "Control!", by Faramarz Hashemi, CC BY-SA 2.0 • "Flight Controls", by Bryan Burke, CC BY-NC-ND 2.0
  12. More Credits... • "Canon 550d - Snail on Fork", Doug

    Wheller (@Doug88888), CC BY-SA 2.0 • "P as in pull", by Kristina Alexanderson (@cclones), CC BY-SA 2.0