diff options
author | Silvino Silva <silvino@bk.ru> | 2016-10-21 17:06:40 +0100 |
---|---|---|
committer | Silvino Silva <silvino@bk.ru> | 2016-10-25 18:20:52 +0100 |
commit | 29463878401499672150f2a3469bf8e8b9bff17b (patch) | |
tree | 6c557e0fb4d6d093f2ecf715e82a7c3f15f37388 /tools/gitolite.html | |
parent | 5ee07ffcbfa431d4e3d66d53a91927927459a02d (diff) | |
download | doc-29463878401499672150f2a3469bf8e8b9bff17b.tar.gz |
gitolite and gitweb revision
Diffstat (limited to 'tools/gitolite.html')
-rw-r--r-- | tools/gitolite.html | 343 |
1 files changed, 218 insertions, 125 deletions
diff --git a/tools/gitolite.html b/tools/gitolite.html index 52206fd..2beae97 100644 --- a/tools/gitolite.html +++ b/tools/gitolite.html @@ -23,7 +23,7 @@ <pre> # mkdir -p /srv/gitolite - # useradd -U -d /srv/gitolite gitolite + # useradd -r -s /bin/bash -m -d /srv/gitolite gitolite # chown gitolite:gitolite /srv/gitolite </pre> @@ -38,10 +38,20 @@ <p>Copy public key that will be used for authenticating gitolite administrator, read <a href="openssh.html#ssh">ssh</a> how to - create one.</p> + create one, key don't need to have password. + If the server is on remote a remote + machine you can use scp to copy the public key;</p> <pre> - $ sudo install -o gitolite -g gitolite /home/bob/.ssh/gitolite.pub /srv/gitolite/gitolite.pub + $ scp /home/bob/.ssh/gitolite.pub admin@core.privat-network.net:/home/admin/ + bob@core.privat-network.net's password: + gitolite.pub 100% 390 0.4KB/s 00:00 + </pre> + + <p>Then on remote machine;</p> + + <pre> + # cp /home/admin/gitolite.pub /srv/gitolite.pub </pre> <pre> @@ -62,7 +72,7 @@ </pre> <pre> - $ ssh -v -i ~/.ssh/gitulite_rsa gitolite@localhost -p 2222 + $ ssh -v -i ~/.ssh/gitolite gitolite@localhost -p 2222 </pre> <h2 id="admin">3. Gitolite Administration</h2> @@ -72,7 +82,7 @@ Start by cloning gitolite-adimin;</p> <pre> - $ git clone gitolite:gitolite-admin + $ git clone git-admin:gitolite-admin </pre> <h3>3.1. Recover Admin Account</h3> @@ -127,13 +137,15 @@ edit conf/gitolite.conf;</p> <pre> + @guests = gitweb + @interns = clair bob @dev = alice david - @interns = clair - @dev = bob @teamleads = mike @staff = @interns @dev @teamleads - @proj-repos = sysdoc storm atom + + repo gitolite-admin + RW+ = gitolite repo @floss R = @all @@ -141,24 +153,23 @@ repo @proto RW+ = @staff - repo @proj-repos + repo @project RW+ = @teamleads - master = @dev - refs/tags/v[0-9] = @dev RW+ develop/ = @dev - RW+ feature/ = @dev - RW+ hot-fix/ = @dev + RW+ feature/ = @dev @interns + RW+ hot-fix/ = @dev @interns RW = @dev - R = @managers + R = @interns @guests - repo atom sysdoc - option hook.post-receive = deployweb + @project = c9-doc c9-ports + + repo c9-doc c9-ports + option hook.post-receive = hook-deployweb repo testing RW+ = @staff - - repo gitolite-admin - RW+ = mike </pre> <p>Commit and push;</p> @@ -174,13 +185,13 @@ <pre> # cd /srv/gitolite/repositories/ - # mv void.git sysdoc.git + # mv void.git c9-doc.git </pre> <p>On workstation edit conf/gitolite.conf;</p> <pre> - repo sysdoc + repo c9-doc RW+ = bob </pre> @@ -196,7 +207,8 @@ <p>Example from <a href="http://gitolite.com/gitolite/cookbook.html#v3.6-variation-repo-specific-hooks">Cookbook</a> how to apply hooks only to certain repos. Uncomment or add - this line on /srv/gitolite/.gitolite.rc, within the %RC block;</p> + this line on <a href="conf/srv/gitolite/.gitolite.rc">/srv/gitolite/.gitolite.rc</a>, + within the %RC block;</p> <pre> LOCAL_CODE => "$rc{GL_ADMIN_BASE}/local", @@ -206,32 +218,29 @@ or add it to the ENABLE list if it doesn't exist.</p> <pre> - GIT_CONFIG_KEYS => '.*', - </pre> - - <pre> # allow repo-specific hooks to be added 'repo-specific-hooks', </pre> - <p>Put your hooks into your gitolite-admin clone, as follows:</p> + <p>Create directory on gitolite-admin clone;</p> <pre> $ cd ~/gitolite-admin $ mkdir -p local/hooks/repo-specific </pre> - <p>Create the same directory on remote as gitolite;</p> + <p>Now add your hooks to that directory, but instead of using the + git "standard" names (pre-receive, post-receive, post-update), + you use descriptive names (e.g. "deploy", "RSS-post", etc).</p> + + <p>On remote run;</p> <pre> # su - gitolite - $ mkdir local/hooks/repo-specific + $ mkdir .gitolite/local/hooks/repo-specific + $ gitolite setup </pre> - <p>Now add your hooks to that directory, but instead of using the - git "standard" names (pre-receive, post-receive, post-update), - you use descriptive names (e.g. "deploy", "RSS-post", etc).</p> - <h3 id="gtl-deploy">4.1. Deploy Hook</h3> <p>This manual create two users; one gitolite that handle git @@ -244,12 +253,8 @@ calls a script inside project folder with user www. This allows to do post deploy (checkout) tasks such as composer update.</p> - <p>Create <a href="../conf/srv/gitoliteolite/deployweb">deployweb</a> - in gitolite-admin/local/hooks/repo-specific;</p> - - <pre> - $ vim ~/gitolite-admin/local/hooks/repo-specific/deployweb - </pre> + <p>Create + <a href="conf/srv/gitolite/hook-deployweb">gitolite-admin/local/hooks/repo-specific/hook-deployweb</a>;</p> <pre> #!/bin/bash @@ -257,7 +262,7 @@ ###################################################################### # # Put this file in your gitolite-admin; - # ~/gitolite-admin/local/hooks/repo-specific/deployweb + # ~/gitolite-admin/local/hooks/repo-specific/hook-deployweb # while read oldrev newrev refname do @@ -277,19 +282,12 @@ done </pre> - <p>Create deploy directory on remote;</p> - - <pre> - # su - gitolite - $ mkdir deploy - </pre> - <p>Add scripts to the repos you want them to be active in your conf file. For example:</p> <pre> - repo atom @baz - option hook.post-receive = deployweb + repo c9-doc + option hook.post-receive = hook-deployweb </pre> <p>Add, commit, and push the admin repo;</p> @@ -298,6 +296,13 @@ $ git add -u && git commit -m "deploy hook" </pre> + <p>Create deploy directory on remote;</p> + + <pre> + # su - gitolite + $ mkdir deploy + </pre> + <p>On remote run;</p> <pre> @@ -310,117 +315,205 @@ /srv/gitolite/deploy folder for projects that have been updated.</p> - <p>Create <a href="../conf/srv/gitolite/deploy.sh">deploy.sh</a> in - /usr/share/gitolite;</p> + <p>Create <a href="conf/srv/gitolite/deployweb">/usr/share/gitolite/hooks/deployweb</a>;</p> <pre> - $ vim /usr/share/gitolite/deploy.sh + #!/bin/sh + + ###################################################################### + # + # Put this file in; + # /usr/share/gitolite/hooks/deployweb + # + DIR_WWW=/srv/www/ + DEPLOY_BRANCH=master + TARGET_USER=www + + for DP_FILE in /srv/gitolite/deploy/* + do + + if [ ! -f "$DP_FILE" ]; then + # Nothing to do ;) + #echo "Deploy: invalid DP_FILE" + exit 1; + fi + + # Get project name + PROJECT=$(basename "$DP_FILE") + echo "Deploy: PROJECT=${PROJECT}" + + # Get git repository path and verify if exists + DIR_GIT=$(head -n 1 $DP_FILE) + if [ ! -d "$DIR_GIT" ]; then + echo "Deploy: invalid DIR_GIT: ${DIR_GIT}" + exit 2; + fi + echo "Deploy: DIR_GIT=${DIR_GIT}" + + # Get directory to deploy and verify if exists + GIT_WORK_TREE=${DIR_WWW}${PROJECT}/ + if [ ! -d "$GIT_WORK_TREE" ]; then + echo "Deploy: invalid GIT_WORK_TREE: ${GIT_WORK_TREE}" + echo "Deploy: creating directory: $GIT_WORK_TREE}" + mkdir -p $GIT_WORK_TREE + fi + echo "Deploy: GIT_WORK_TREE={$GIT_WORK_TREE}" + + # Deploy (checkout) + echo "Deploy: starting git checkout" + + git --git-dir=$DIR_GIT \ + --work-tree=$GIT_WORK_TREE \ + checkout -f $DEPLOY_BRANCH + + + # Fix ownership and permissions + echo "Deploy: fixing permissions" + + echo "Deploy: setting owner: chown -R ${TARGET_USER}" + chown -R ${TARGET_USER}:${TARGET_USER} $GIT_WORK_TREE + + echo "Deploy: setting directory permissions: chmod 755" + find $GIT_WORK_TREE -type d -print0 | xargs -0 chmod 755 + + echo "Deploy: setting file permissions: chmod 644" + find $GIT_WORK_TREE -type f -print0 | xargs -0 chmod 644 + + # Call project script + if [ -f "${GIT_WORK_TREE}/deploy.sh" ]; then + echo "Deploy: calling ${GIT_WORK_TREE}deploy.sh" + cd ${GIT_WORK_TREE} + sudo -u ${TARGET_USER} sh ${GIT_WORK_TREE}deploy.sh + fi + + # Done with project + echo "Deploy: removing deploy file="$DP_FILE + rm $DP_FILE + + exit 0; + done </pre> - <pre> - #!/bin/sh + <p>Add cron job to call deploy script every minute;</p> - ###################################################################### - # - # Put this file in; - # /usr/share/gitolite/deploy.sh - # - DIR_WWW=/srv/www/ - DEPLOY_BRANCH=master - TARGET_USER=www + <pre> + # crontab -e + </pre> - for DP_FILE in /srv/gitolite/deploy/* - do + <pre> + # + # /etc/crontab: crond(8) configuration + # - if [ ! -f "$DP_FILE" ]; then - # Nothing to do ;) - #echo "Deploy: invalid DP_FILE" - exit 1; - fi + # this way it will log + # * * * * * /usr/share/gitolite/hooks/deployweb + # without log + * * * * * /usr/share/gitolite/hooks/deployweb > /dev/null 2>&1 - # Get project name - PROJECT=$(basename "$DP_FILE") - echo "Deploy: PROJECT=${PROJECT}" + @hourly ID=sys.hourly /usr/sbin/runjobs /etc/cron/hourly + @daily ID=sys.daily /usr/sbin/runjobs /etc/cron/daily + @weekly ID=sys.weekly /usr/sbin/runjobs /etc/cron/weekly + @monthly ID=sys.monthly /usr/sbin/runjobs /etc/cron/monthly - # Get git repository path and verify if exists - DIR_GIT=$(head -n 1 $DP_FILE) - if [ ! -d "$DIR_GIT" ]; then - echo "Deploy: invalid DIR_GIT: ${DIR_GIT}" - exit 2; - fi - echo "Deploy: DIR_GIT=${DIR_GIT}" + # End of file + </pre> - # Get directory to deploy and verify if exists - GIT_WORK_TREE=${DIR_WWW}${PROJECT}/ - if [ ! -d "$GIT_WORK_TREE" ]; then - echo "Deploy: invalid GIT_WORK_TREE: ${GIT_WORK_TREE}" - echo "Deploy: creating directory: $GIT_WORK_TREE}" - mkdir -p $GIT_WORK_TREE - fi - echo "Deploy: GIT_WORK_TREE={$GIT_WORK_TREE}" + <h2 id="gitweb">5. Gitweb</h2> - # Deploy (checkout) - echo "Deploy: starting git checkout" + <pre> + $ prt-get depinst p5-cgi p5-cgi-session libcgi fcgiwrap spawn-fcgi + </pre> - git --git-dir=$DIR_GIT \ - --work-tree=$GIT_WORK_TREE \ - checkout -f $DEPLOY_BRANCH + <h3>5.1. Configure gitweb</h3> + <p>Edit /etc/gitweb.conf</p> - # Fix ownership and permissions - echo "Deploy: fixing permissions" + <pre> + our $git_temp = "/tmp"; - echo "Deploy: setting owner: chown -R ${TARGET_USER}" - chown -R ${TARGET_USER}:${TARGET_USER} $GIT_WORK_TREE + # The directories where your projects are. Must not end with a slash. + our $projectroot = "/srv/gitolite/repositories"; - echo "Deploy: setting directory permissions: chmod 755" - find $GIT_WORK_TREE -type d -print0 | xargs -0 chmod 755 + # Base URLs for links displayed in the web interface. + our @git_base_url_list = qw(git://core.privat-network.com http://git@core.private-network.com); + </pre> - echo "Deploy: setting file permissions: chmod 644" - find $GIT_WORK_TREE -type f -print0 | xargs -0 chmod 644 + <h3>5.2. Configure nginx</h3> - # Call project script - if [ -f "${GIT_WORK_TREE}/deploy.sh" ]; then - echo "Deploy: calling ${GIT_WORK_TREE}deploy.sh" - cd ${GIT_WORK_TREE} - sudo -u ${TARGET_USER} sh ${GIT_WORK_TREE}deploy.sh - fi + <p>Edit /etc/rc.d/fcgiwrap to run as www user;</p> - # Done with project - echo "Deploy: removing deploy file="$DP_FILE - rm $DP_FILE + <pre> + USER=nginx + GROUP=nginx + </pre> - exit 0; - done + <pre> + # usermod -G www,gitolite nginx </pre> - <p>Add cron job to call deploy script every minute;</p> + <p>Create link from gitweb to web server folder;</p> <pre> - # crontab -e + # ln -s /usr/share/gitweb /srv/www </pre> + <p>Add this to default or main + <a href="nginx.html#virtual-host">nginx virtual host</a>;</p> + <pre> - # - # /etc/crontab: crond(8) configuration - # + location /gitweb/gitweb.cgi { + alias /srv/www/gitweb; + include fastcgi_params; + gzip off; + fastcgi_param SCRIPT_FILENAME /srv/www/gitweb/gitweb.cgi; + fastcgi_param GITWEB_CONFIG /etc/gitweb.conf; + fastcgi_pass unix:/var/run/fcgiwrap.sock; + } - # this way it will log - # * * * * * /usr/share/gitolite/deploy.sh - # without log - * * * * * /usr/share/gitolite/deploy.sh > /dev/null 2>&1 + location /gitweb { + alias /srv/www/gitweb; + index gitweb.cgi; + } + </pre> - @hourly ID=sys.hourly /usr/sbin/runjobs /etc/cron/hourly - @daily ID=sys.daily /usr/sbin/runjobs /etc/cron/daily - @weekly ID=sys.weekly /usr/sbin/runjobs /etc/cron/weekly - @monthly ID=sys.monthly /usr/sbin/runjobs /etc/cron/monthly + <h3>5.3. Configure gitolite</h3> - # End of file + <p>Edit + <a href="conf/srv/gitolite/.gitolite.rc">/srv/gitolite/.gitolite.rc</a>, + change UMASK and GIT_CONFIG_KEYS to;</p> + + <pre> + # default umask gives you perms of '0700'; see the rc file docs for + # how/why you might change this + UMASK => 027, + + # look for "git-config" in the documentation + GIT_CONFIG_KEYS => '.*', + </pre> + + <p>Fix permissions;</p> + + <pre> + $ sudo chown -R gitolite:gitolite /srv/gitolite + $ sudo chmod g+rx /srv/gitolite/projects.list + $ sudo chmod -R g+rx /srv/gitolite/repositories/ </pre> - <h3 id="gitweb">5. Gitweb</h3> - <p>Edit the /home/git/.gitolite.rc and change the UMASK value as 0027</p> + <p>Edit gitolite-admin/conf/gitolite.conf;</p> + + <pre> + repo c9-doc + config gitweb.owner = c9 team + config gitweb.description = c9 documentation + config gitweb.category = c9 + + repo c9-ports + config gitweb.owner = c9 team + config gitweb.description = c9 ports + config gitweb.category = c9 + </pre> + <a href="index.html">Tools Index</a> <p>This is part of the c9-doc Manual. Copyright (C) 2016 |