Package: gitdh
The Git Deployment Handler is a tool for automatic deployment of git
commits from local or remote repositories into (local) directories.Some advanced features require a database; SQlite, MongoDb and MySQL are
the supported database backends. The Git Deployment Handler uses
post-receive hooks and cron jobs (services in future) to automatically
deploy commits.Requirementspython3git (command line tool)For some features eithersqlite3mysql and PyMySQLmongodb and pymongoInstallationThe easiest way to installgitdhis to use thePython
Package Index:# # It is necessary to use python3, so instead of pip, pip3 or pip-3.2, ... might have to be used
# pip install gitdhOr manually install from source:# python3 setup.py installGetting StartedIn this example themasterbranch of a local repository (hosted
using gitolite) is deployed to a webserver directory using a
post-receive hook.gitdh requires a configuration using INI syntax file for every
repository whose branches are to be deployed. The path to the repository
has to be in theRepositoryPathoption of theGitsection. The
branch to be deployed must have its own section in the configuration
file with aPathoption being the directory the branch is to be
deployed to.So to deploy the/var/lib/gitolite/repositories/website.gitrepository to/home/www/website, the following is put into/var/lib/gitolite/gitdh-website.conf:[Git]
RepositoryPath = /var/lib/gitolite/repositories/website.git

[master]
Path = /home/www/websiteThe post-receive hooks is installed using the following command, it is
also necessary to give thegitoliteuser write access to the
deployment directory.# mkdir -p /home/www/website
# chown gitolite:www-data /home/www/website
# chmod g+rx /home/www/website
# git-dh install postreceive /var/lib/gitolite/gitdh-website.confFrom now on gitdh will deploy all new commits pushed to thewebsiterepository to the/home/www/websitedirectory.Also check thedocs/(Github)
directory for sample configuration files.Configurationgitdh is configured using a config file in INI syntax.It can either be stored somewhere on the file system or in a file namedgitdh.confin agitdhbranch of a git repository. This file or
such a git repository is referred to astargetwithin gitdh. Some
sample config files can be found in thedocs/directory.TheGitsection of the file contains all file-wide settings; The
most important one is theRepositoryPathof the git repository to be
deployed. This setting can be omitted when the config file is placed in
a git repository (namedgitdh.confin agitdhbranch).[Git]
RepositoryPath = /var/lib/gitolite/repositories/webapp.gitAdditional Options:External-TrueorFalse, whether the Source is an
external (i.e. remote) repository; (requires a database); defaultFalseIdentityFile- May contain the path of an IdentityFile (as in
.ssh/config) when External is used and Source is a SSH URL; defaultNoneBranchesFor every branch which should be deployed, a section named like the
branch has to be created. ThePathsetting specifies the path to be
deployed to:[master]
Path = /srv/www/webapp.com/Additional Options:RmGitIntFiles-TrueorFalse, whether internal git files
should be deleted (.git/,.gitignore,.gitmodules);
defaultTrueRecursive-TrueorFalse, whether a clone should berecursive, i.e. submodules should be cloned out as well; defaultTrueDatabaseLog-TrueorFalse, whether every commit should
be logged to the database; (requires a database); defaultFalseCronDeployment-TrueorFalse, whether every commit
should be inserted into the database and deployed by cron job instead
of being deploying directly; (requires a database); defaultFalseApproval-TrueorFalse, whether every commit has to be
first approved in the database and is then deployed by cron job;
(requires a database); defaultFalsePreprocessing- space separated list of commands to be performed
before deploying any commits; default `` (empty)Postprocessing- space separated list of commands to be performed
after deploying all commits; default `` (empty)DatabaseTo be able to utilise a database, aDatabasesection is required.
TheEnginesetting in theDatabasesection specified the
database backend (must besqlite,mongodbormysql). Each
database backend has its own further options:# MySQL
# Database and table have to be setup, see docs/commits.sql
[Database]
Engine = mysql
Host = localhost
Port = 3306
User = gitdh
Password = ###randompassword###
Database = gitdh
Table = commits

# MongoDb
# Database and collection are created when needed
[Database]
Engine = mongodb
Host = localhost
Port = 27017
Database = gitdh
Collection = commits

# SQLite
# Is created when needed; DatabaseFile must be writable
[Database]
Engine = sqlite
DatabaseFile = /var/lib/gitolite/data.sqlite
Table = commitsCommandsCommands used forPreprocessingandPostprocessingare stored in
additional sections in the config file. The section name is the name of
the command with trailing-command.[crunch-command]
Mode = file
RegExp = \.php$
Command = eff_php_crunch ${f}

[customscript-command]
Mode = once
Command = ${f}/custom.shModecan either befileoronce. TheCommanddefines the
command which is executed. In theCommandstring${f}is
substituted with a file path:IfModeequalsfile, the command is performed once for every
file in the repository matching the regular expression in the
optionalRegExpoption. The file path is the path of the
individual file in this case.IfModeequalsonce, the command is performed once for the
deployed repository, the file path in this case is the path of the
deployed repository.Additional Options:Shell-TrueorFalse, whether a shell should be used to
execute the command; defaultFalseSuppressOutput-TrueorFalse, whether output from the
command should be surpressed, whether ; defaultTrueSetupIn order to deploy commits automatically, gitdh has to be installed as a
git post-receive hook and / or a cron job. Post-receive hooks require a
local “git server” (e.g.gitolite) commits
are pushed to. Cron Jobs have to be created to use advanced features,
e.g. deploy commits fromExternalrepositories or theApprovalorCronDeploymentfeatures.Thegit-dhinstallcommand helps creating these files.postreceiveSetupThegit-dhinstall postreceivecommand will assist on creating git
post-receive hooks.The following command will attempt to create a post-receive hook for
everytarget(being a config file or a repository):# git-dh install postreceive <target>[ <target>[ <target> ...]]The command will try to fetch all required information from thetarget. It will also attempt to recognise and use the current
virtualenv. The command by default doesn’t overwrite any files, aborts
on error and prints all files written to.Additional arguments:--printOnly- Only print the file content, don’t write any files--force- Overwrite existing files--quiet- Only print errors--mode- The mode of the created file; default 755For more information seegit-dhinstall postreceive--help.A sample post-receive file can be found indocs/post-receive.samplecronSetupThegit-dhinstall croncommand will assist on creating cron job
files in/etc/cron.d/.The following command will attempt to create a cron jobnamein/etc/cron.d/containing commands to query everytarget(being a
config file or a repository):# git-dh install cron <name> <target>[ <target>[ <target> ...]]The command will try to fetch all required information from thetarget. It will also attempt to recognise and use the current
virtualenv. The command by default doesn’t overwrite any files, aborts
on error and prints all files written to.Additional arguments:--user- The user to execute gitdh under in the cron job;
default: the current user--interval- The interval with which the cron job is to be
executed; default*/5 * * * *--unixPath- ThePATHto be written to the cron job file;
default: the current path--mailto- TheMAILTOto be written to the cron job file;
default root--printOnly- Only print the file content, don’t write any files--force- Overwrite existing files--quiet- Only print errors--mode- The mode of the created cron job file; default 644For more information seegit-dhinstall cron--help.A sample cron job file can be found indocs/cronjob.sampleIssues / ContributingPlease use theGit-Deployment-Handler Github
Repositoryto
submit issues or contribute.