SlideShare uma empresa Scribd logo
1 de 15
Baixar para ler offline
Git hooks
for staging and production
Priit Tamboom
LRUG meetup
November 2010
Outline
What are hooks?
Scope of using hooks for deployment
Simple scenario of using git hooks
Improved scenario of using git hooks
Everyday tips
... and live demo
What are hooks?
Git hooks are just plain scripts what will be fired off
when certain action occurs.
Hooks are located at your repo .git/hooks directory.
About hooks
There are quite many hooks such as:
pre-commit, prepare-commit-msg, applypatch-msg,
pre-rebase, pre-receive etc
Today we use only one hook script:
post-update
By the way, hooks are not shared between different repos.
As far as I know, git does not provide feature to share or
ability to push hooks between repos.
Scope
IDEAL FOR:
small projects (such as one staging and production server)
keeping overhead and dependency low
for learning and exploring
PROBABLY NOT IDEAL FOR:
managing popular app with huge cluster of servers
and putting lot of logic into hooks, probably better fit should
be using Shef* or Puppet instead.
* Hint-hint: I'm looking forward to Shef talk, any blave here?
Simple scenario
As a ruby coder
you got an amazing app to maintain
and you have one production server.
Let's use git for deployment in order to keep overhead down.
Simple: Setting server side up
# using ssh alias 'myserver'
ssh myserver
mkdir example && cd example
git init
git config receive.denycurrentbranch ignore
# Now your repo is ready to receive new code, nice!
Simple: Adding a script to server repo
# make it executable
cp .git/hooks/post-update.sample .git/hooks/post-update
chmod +x .git/hooks/post-update
# edit .git/hooks/post-update
#!/bin/sh
cd ..
unset GIT_DIR
git reset --hard HEAD
# Now repo HEAD will be on latest commit
Simple: Restart app server
# edit again .git/hooks/post-update and add
pkill -HUP unicorn_rails # or whatever server you use
# in demo I'll use StaticMatic, so I added:
staticmatic build .
# That's it for our server side!
Simple: Client side setup
# add remote repo where 'myserver' is ssh alias
git remote add deploy myserver:/home/user/example
# first time pushing up submit also branch, such as master
git push deploy master
# second time you can omit master or make alias
git push deploy
# and here you go, enjoy!
Tips
Don't mess to much with server repo, so it's HEAD should
be clean aka 'git status' should be clean.
Keep your .gitignore file updated, so your status is clear
Our current project setup
STAGING:
Scope: We do push into staging multiple times a day.
We push new shiny code to github
Github fires up our cijoe integration server
Cijoe fires '.git/hooks/after-reset' hook
what pulls new code to cijoe and staging repo
Cijoe fires '.git/hooks/build-worked',
what sends emails out and now involved people can
checkout new stuff on staging.
Our current project setup
Scope: We do push into production once or twice a week
PRODUCTION without new gems:
Quite close to Simple Senario setup
PRODUCTION with new gems:
Quite close to Simple Senario setup,
but I went back to install new gems manually aka
'bundle install' way.
References
Using Git to manage a web site
http://toroid.org/ams/git-website-howto
Pro Git: Git Hooks
http://progit.org/book/ch7-3.html
Live demo
Aka eat your own dog food :-)

Mais conteúdo relacionado

Mais procurados

Speeding up your team with GitOps
Speeding up your team with GitOpsSpeeding up your team with GitOps
Speeding up your team with GitOpsBrice Fernandes
 
GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)Weaveworks
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners HubSpot
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub ActionsBo-Yi Wu
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPCGuo Jing
 
WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?Weaveworks
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.skJuraj Hantak
 
Extending HashiCorp Nomad with Plugins
Extending HashiCorp Nomad with PluginsExtending HashiCorp Nomad with Plugins
Extending HashiCorp Nomad with PluginsMitchell Pronschinske
 
Intro to GitOps & Flux.pdf
Intro to GitOps & Flux.pdfIntro to GitOps & Flux.pdf
Intro to GitOps & Flux.pdfWeaveworks
 
GitHub 실습 교육
GitHub 실습 교육GitHub 실습 교육
GitHub 실습 교육승엽 신
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CIColCh
 
Infrastructure as Code with Ansible
Infrastructure as Code with AnsibleInfrastructure as Code with Ansible
Infrastructure as Code with AnsibleDaniel Bezerra
 

Mais procurados (20)

Speeding up your team with GitOps
Speeding up your team with GitOpsSpeeding up your team with GitOps
Speeding up your team with GitOps
 
GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)GitOps Toolkit (Cloud Native Nordics Tech Talk)
GitOps Toolkit (Cloud Native Nordics Tech Talk)
 
Gitlab CI/CD
Gitlab CI/CDGitlab CI/CD
Gitlab CI/CD
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Meetup 23 - 03 - Application Delivery on K8S with GitOps
Meetup 23 - 03 - Application Delivery on K8S with GitOpsMeetup 23 - 03 - Application Delivery on K8S with GitOps
Meetup 23 - 03 - Application Delivery on K8S with GitOps
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub Actions
 
Rxjs ngvikings
Rxjs ngvikingsRxjs ngvikings
Rxjs ngvikings
 
HTTP2 and gRPC
HTTP2 and gRPCHTTP2 and gRPC
HTTP2 and gRPC
 
WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.sk
 
Extending HashiCorp Nomad with Plugins
Extending HashiCorp Nomad with PluginsExtending HashiCorp Nomad with Plugins
Extending HashiCorp Nomad with Plugins
 
Intro to GitOps & Flux.pdf
Intro to GitOps & Flux.pdfIntro to GitOps & Flux.pdf
Intro to GitOps & Flux.pdf
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
GitHub 실습 교육
GitHub 실습 교육GitHub 실습 교육
GitHub 실습 교육
 
"DevOps > CI+CD "
"DevOps > CI+CD ""DevOps > CI+CD "
"DevOps > CI+CD "
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
GraalVM
GraalVMGraalVM
GraalVM
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
 
Github copilot
Github copilotGithub copilot
Github copilot
 
Infrastructure as Code with Ansible
Infrastructure as Code with AnsibleInfrastructure as Code with Ansible
Infrastructure as Code with Ansible
 

Destaque

CSCMP 2014: Voice of the Industry
CSCMP 2014: Voice of the IndustryCSCMP 2014: Voice of the Industry
CSCMP 2014: Voice of the IndustryBrady Totten
 
The Value of Working with an Event Management Company
The Value of Working with an Event Management CompanyThe Value of Working with an Event Management Company
The Value of Working with an Event Management Companyapplesncookie
 
DPS, Inc. Corporate Event Services - Company Overview
DPS, Inc. Corporate Event Services - Company OverviewDPS, Inc. Corporate Event Services - Company Overview
DPS, Inc. Corporate Event Services - Company OverviewStuartKopple
 
AVTC Designs Sales Presentation
AVTC Designs Sales PresentationAVTC Designs Sales Presentation
AVTC Designs Sales PresentationMike Lichen
 
Connected Productions - Experience Design and Event Production - Brochure 2010
Connected Productions - Experience Design and Event Production - Brochure 2010Connected Productions - Experience Design and Event Production - Brochure 2010
Connected Productions - Experience Design and Event Production - Brochure 2010Connected Productions
 
Services Marketing Chapter 4 Planning and Producing the Service Performance
Services Marketing Chapter 4 Planning and Producing the Service PerformanceServices Marketing Chapter 4 Planning and Producing the Service Performance
Services Marketing Chapter 4 Planning and Producing the Service PerformanceDr. John V. Padua
 
Becoming a Perfect Event Manager
Becoming a Perfect Event ManagerBecoming a Perfect Event Manager
Becoming a Perfect Event ManagerEden Smith
 
Emerging trends & challenges in event industry
Emerging  trends  & challenges in event industryEmerging  trends  & challenges in event industry
Emerging trends & challenges in event industryCreation Amit
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging ChallengesAaron Irizarry
 

Destaque (9)

CSCMP 2014: Voice of the Industry
CSCMP 2014: Voice of the IndustryCSCMP 2014: Voice of the Industry
CSCMP 2014: Voice of the Industry
 
The Value of Working with an Event Management Company
The Value of Working with an Event Management CompanyThe Value of Working with an Event Management Company
The Value of Working with an Event Management Company
 
DPS, Inc. Corporate Event Services - Company Overview
DPS, Inc. Corporate Event Services - Company OverviewDPS, Inc. Corporate Event Services - Company Overview
DPS, Inc. Corporate Event Services - Company Overview
 
AVTC Designs Sales Presentation
AVTC Designs Sales PresentationAVTC Designs Sales Presentation
AVTC Designs Sales Presentation
 
Connected Productions - Experience Design and Event Production - Brochure 2010
Connected Productions - Experience Design and Event Production - Brochure 2010Connected Productions - Experience Design and Event Production - Brochure 2010
Connected Productions - Experience Design and Event Production - Brochure 2010
 
Services Marketing Chapter 4 Planning and Producing the Service Performance
Services Marketing Chapter 4 Planning and Producing the Service PerformanceServices Marketing Chapter 4 Planning and Producing the Service Performance
Services Marketing Chapter 4 Planning and Producing the Service Performance
 
Becoming a Perfect Event Manager
Becoming a Perfect Event ManagerBecoming a Perfect Event Manager
Becoming a Perfect Event Manager
 
Emerging trends & challenges in event industry
Emerging  trends  & challenges in event industryEmerging  trends  & challenges in event industry
Emerging trends & challenges in event industry
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 

Semelhante a Git hooks

FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CIOlinData
 
How To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneHow To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneVEXXHOST Private Cloud
 
La importancia de versionar el código: GitHub, portafolio y recursos para est...
La importancia de versionar el código: GitHub, portafolio y recursos para est...La importancia de versionar el código: GitHub, portafolio y recursos para est...
La importancia de versionar el código: GitHub, portafolio y recursos para est...CloudNativeElSalvado
 
Apigee deploy grunt plugin.1.0
Apigee deploy grunt plugin.1.0Apigee deploy grunt plugin.1.0
Apigee deploy grunt plugin.1.0Diego Zuluaga
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IOded Sagir
 
DevOps - Interview Question.pdf
DevOps - Interview Question.pdfDevOps - Interview Question.pdf
DevOps - Interview Question.pdfMinhTrnNht7
 
Open up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHubOpen up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHubScott Graham
 
Git for a newbie
Git for a newbieGit for a newbie
Git for a newbieAnuj Sharma
 
Nina Zakharenko - Introduction to Git - Start SLC 2015
Nina Zakharenko - Introduction to Git - Start SLC 2015Nina Zakharenko - Introduction to Git - Start SLC 2015
Nina Zakharenko - Introduction to Git - Start SLC 2015Nina Zakharenko
 
Git lab installation guide
Git lab installation guideGit lab installation guide
Git lab installation guideRaiful Hasan
 
Intro to Github Actions @likecoin
Intro to Github Actions @likecoinIntro to Github Actions @likecoin
Intro to Github Actions @likecoinWilliam Chong
 
Gitlab installation
Gitlab installationGitlab installation
Gitlab installationRaiful Hasan
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryJames Wickett
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsGR8Conf
 
Using a Private Git Server for Packaging Software
Using a Private Git Server for Packaging SoftwareUsing a Private Git Server for Packaging Software
Using a Private Git Server for Packaging SoftwareChris Jean
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturasparkfabrik
 

Semelhante a Git hooks (20)

FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CI
 
How To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub CloneHow To Install GitLab As Your Private GitHub Clone
How To Install GitLab As Your Private GitHub Clone
 
DevOps Workshop Part 1
DevOps Workshop Part 1DevOps Workshop Part 1
DevOps Workshop Part 1
 
La importancia de versionar el código: GitHub, portafolio y recursos para est...
La importancia de versionar el código: GitHub, portafolio y recursos para est...La importancia de versionar el código: GitHub, portafolio y recursos para est...
La importancia de versionar el código: GitHub, portafolio y recursos para est...
 
Apigee deploy grunt plugin.1.0
Apigee deploy grunt plugin.1.0Apigee deploy grunt plugin.1.0
Apigee deploy grunt plugin.1.0
 
The Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session IThe Secrets of The FullStack Ninja - Part A - Session I
The Secrets of The FullStack Ninja - Part A - Session I
 
DevOps - Interview Question.pdf
DevOps - Interview Question.pdfDevOps - Interview Question.pdf
DevOps - Interview Question.pdf
 
Open up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHubOpen up your platform with Open Source and GitHub
Open up your platform with Open Source and GitHub
 
Git for a newbie
Git for a newbieGit for a newbie
Git for a newbie
 
Nina Zakharenko - Introduction to Git - Start SLC 2015
Nina Zakharenko - Introduction to Git - Start SLC 2015Nina Zakharenko - Introduction to Git - Start SLC 2015
Nina Zakharenko - Introduction to Git - Start SLC 2015
 
Git lab installation guide
Git lab installation guideGit lab installation guide
Git lab installation guide
 
Git
GitGit
Git
 
Intro to Github Actions @likecoin
Intro to Github Actions @likecoinIntro to Github Actions @likecoin
Intro to Github Actions @likecoin
 
Gitlab installation
Gitlab installationGitlab installation
Gitlab installation
 
Attacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous DeliveryAttacking Pipelines--Security meets Continuous Delivery
Attacking Pipelines--Security meets Continuous Delivery
 
Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010Matt Gauger - Git & Github web414 December 2010
Matt Gauger - Git & Github web414 December 2010
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
 
Using a Private Git Server for Packaging Software
Using a Private Git Server for Packaging SoftwareUsing a Private Git Server for Packaging Software
Using a Private Git Server for Packaging Software
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
 
Continuous Deploy
Continuous DeployContinuous Deploy
Continuous Deploy
 

Mais de Skills Matter

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard LawrenceSkills Matter
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmSkills Matter
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimSkills Matter
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Skills Matter
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlSkills Matter
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsSkills Matter
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Skills Matter
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Skills Matter
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldSkills Matter
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Skills Matter
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Skills Matter
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingSkills Matter
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveSkills Matter
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tSkills Matter
 

Mais de Skills Matter (20)

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
 
Serendipity-neo4j
Serendipity-neo4jSerendipity-neo4j
Serendipity-neo4j
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Plug 20110217
Plug   20110217Plug   20110217
Plug 20110217
 
Lug presentation
Lug presentationLug presentation
Lug presentation
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
 
Plug saiku
Plug   saikuPlug   saiku
Plug saiku
 

Git hooks

  • 1. Git hooks for staging and production Priit Tamboom LRUG meetup November 2010
  • 2. Outline What are hooks? Scope of using hooks for deployment Simple scenario of using git hooks Improved scenario of using git hooks Everyday tips ... and live demo
  • 3. What are hooks? Git hooks are just plain scripts what will be fired off when certain action occurs. Hooks are located at your repo .git/hooks directory.
  • 4. About hooks There are quite many hooks such as: pre-commit, prepare-commit-msg, applypatch-msg, pre-rebase, pre-receive etc Today we use only one hook script: post-update By the way, hooks are not shared between different repos. As far as I know, git does not provide feature to share or ability to push hooks between repos.
  • 5. Scope IDEAL FOR: small projects (such as one staging and production server) keeping overhead and dependency low for learning and exploring PROBABLY NOT IDEAL FOR: managing popular app with huge cluster of servers and putting lot of logic into hooks, probably better fit should be using Shef* or Puppet instead. * Hint-hint: I'm looking forward to Shef talk, any blave here?
  • 6. Simple scenario As a ruby coder you got an amazing app to maintain and you have one production server. Let's use git for deployment in order to keep overhead down.
  • 7. Simple: Setting server side up # using ssh alias 'myserver' ssh myserver mkdir example && cd example git init git config receive.denycurrentbranch ignore # Now your repo is ready to receive new code, nice!
  • 8. Simple: Adding a script to server repo # make it executable cp .git/hooks/post-update.sample .git/hooks/post-update chmod +x .git/hooks/post-update # edit .git/hooks/post-update #!/bin/sh cd .. unset GIT_DIR git reset --hard HEAD # Now repo HEAD will be on latest commit
  • 9. Simple: Restart app server # edit again .git/hooks/post-update and add pkill -HUP unicorn_rails # or whatever server you use # in demo I'll use StaticMatic, so I added: staticmatic build . # That's it for our server side!
  • 10. Simple: Client side setup # add remote repo where 'myserver' is ssh alias git remote add deploy myserver:/home/user/example # first time pushing up submit also branch, such as master git push deploy master # second time you can omit master or make alias git push deploy # and here you go, enjoy!
  • 11. Tips Don't mess to much with server repo, so it's HEAD should be clean aka 'git status' should be clean. Keep your .gitignore file updated, so your status is clear
  • 12. Our current project setup STAGING: Scope: We do push into staging multiple times a day. We push new shiny code to github Github fires up our cijoe integration server Cijoe fires '.git/hooks/after-reset' hook what pulls new code to cijoe and staging repo Cijoe fires '.git/hooks/build-worked', what sends emails out and now involved people can checkout new stuff on staging.
  • 13. Our current project setup Scope: We do push into production once or twice a week PRODUCTION without new gems: Quite close to Simple Senario setup PRODUCTION with new gems: Quite close to Simple Senario setup, but I went back to install new gems manually aka 'bundle install' way.
  • 14. References Using Git to manage a web site http://toroid.org/ams/git-website-howto Pro Git: Git Hooks http://progit.org/book/ch7-3.html
  • 15. Live demo Aka eat your own dog food :-)