Deployments with Git

Why?

Structure

Choosing a Repository Type

Normal Repository

  • Working tree similar to local
  • Need security to protect .git (.htaccess, etc)
  • Don't make changes here (dirty up the tree)!

Bare Repository

  • Has no working tree
  • Usual suggested repository setup
  • Repository cloned to seperate folder
  • Difficult to do local configuration

We'll be working with a normal repository from here on out!

Post-receive hook

Callbacks

deploy/setup

deploy/after_push

Setup

Password-less SSH Authentication

Generating SSH Keys


          |ssh-keygen -t rsa
          |# Creates two files - .ssh/id_rsa and .ssh/id_rsa.pub by default
        

Installing SSH Keys


          |ssh remote-server
          |mkdir .ssh
          |chmod u=rwx,go= .ssh
          |touch .ssh/authorized_keys
          |chmod u=rw,go= .ssh/authorized_keys
          |# Open .ssh/authorized_keys and copy contents of your .ssh/id_rsa.pub into it
        

or use ssh-copy-id if your platform supports it

PROTIP: Can't connect without a password? Check .ssh folder and file permissions!

Git repository (remote)

Create remote repository


          |mkdir docroot
          |cd docroot
          |git init .
        

Allow other branches to be pushed


          |git config receive.denyCurrentBranch ignore
        

Add post-receive hook


          |# Transfer post-receive.sh to .git/hooks/post-receive
          |chmod +x .git/hooks/post-receive
        

Git repository (local)

Add deploy/after_push callback


          |mkdir deploy
          |# Copy after_push.sh to deploy/after_push
          |git add deploy
          |git commit
        

Add remote


          |git remote add production "user@domain.com:/full/path/to-repo"
        

Deploying

Everyday stuff

Push master


          |git push production master
        

Push different branch


          |git push production your-branch:master
        

Rollbacks


          |git push production HEAD~1:master
        

More Information

Demo

Thank You

Github
github.com/adam12
Twitter
@adamrdaniels
Sourcecode
github.com/adam12/deployments-with-git-devtricks-2015

/