Skip to content

git hooks (validation, chainpush, forbid extension, deploy, ...)

Notifications You must be signed in to change notification settings

simonschiele/git-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

These are a few of my git-hooks.
If you have nice hooks that might be helpful, please write a mail ([email protected])

To activate serverside hooks:  
    1) adjust "hooks_path" in "custom_hook"-loader script
    2) rename existing hooks with dot-scheme (e.g. update -> update.gitosis)
    3) link custom_hook loader as update/pre-receive/... 
    4) activate the wished hooks via repo config (see example below) 

Overview:

    validation
        Description: Validates given filetype
        Type: pre-receive
        Depends: php-cli, xmllint, ...

    extension
        Description: Checks for 'forbidden' extensions
        Type: pre-receive

    chainpush
        Description: Does chainpush to other repos/hosts (e.g. github)
        Type: post-receive

    deploy
        Description: deploy via git 
        Type: post-receive 


Example config for hooks (put this in the repos config):
    
    [hooks]
        validation = xml, php 
        chainpush = [email protected]/simonschiele/awesome.git, [email protected]:awesome.git 
        extension = doc, xls
        deploy = local@/var/www/project2, /etc/keys/[email protected]


####################################
About remote deploying
####################################

The deploy hooks rely on a configured remote host.

The actual deploy script is configures in the authorized_keys of your deploy user - on hook side only "echo -n" gets triggered.
Sadly, you can only bind one deploy to one key, so you will have to create a lot of deploy keys. 
On the plus side, this will enhance seucurity of the deploy model. Anyway, think about clean permissions before start using auto 
deploy.
If you are using git to deploy web projects, be carefull that git directory is blocked by apache or outside of htdocs.

My default setup on remote host:
    * I create a passwordless user named "deploy"
    * give him his home-dir as /var/cache/deploy
    * create a ssh keypair for git pull
    * put private key in /var/cache/deploy/.ssh/
    * add public key with read permissions to gitlolite/gitosis
    * create another key pair for actual deploy
    * put private key on the server that triggers the git-hook
    * add public key to /var/cache/deploy/.ssh/authorized_keys with something like this:
command="cd /srv/www/page1 && echo Deploying to $(pwd) on $(hostname) && git pull",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AA......... deploy@host

About

git hooks (validation, chainpush, forbid extension, deploy, ...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages