Install Gitolite port first;
$ prt-get depinst gitolite
Create user and home directory;
# useradd -r -s /bin/bash -U -m -d /srv/gitolite gitolite # chown gitolite:gitolite /srv/gitolite
Password is necessary so the user is not locked and can login via ssh. This password will not be used.
# passwd gitolite
Copy public key that will be used for authenticating gitolite administrator, read ssh how to 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;
$ 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
Then on remote machine;
# cp /home/admin/gitolite.pub /srv/gitolite.pub
# su - gitolite $ gitolite setup -pk gitolite.pub Initialized empty Git repository in /srv/gitolite/repositories/gitolite-admin.git/ Initialized empty Git repository in /srv/gitolite/repositories/testing.git/ WARNING: /srv/gitolite/.ssh missing; creating a new one (this is normal on a brand new install) WARNING: /srv/gitolite/.ssh/authorized_keys missing; creating a new one (this is normal on a brand new install) $
$ rm gitolite.pub $ exit
$ ssh -v -i ~/.ssh/gitolite gitolite@localhost -p 2222
Read how to setup ssh identities, gitolite documentation. Start by cloning gitolite-adimin;
$ git clone git-admin:gitolite-admin
First copy the key to remote server, in this example key is on same server;
# install -o gitolite -g gitolite /home/bob/.ssh/gitolite.pub /srv/gitolite/gitolite.pub
Update gitolite key with new key;
# su - gitolite $ gitolite setup -pk gitolite.pub
$ rm gitolite.pub $ exit
Gitolite helps add and remove users from authorized_keys by allowing add or remove keys from keydir directory in clone.
$ mv bob.pub keydir/ $ git add keydir $ git commit -m "Added bob public key" $ git push
$ git rm keydir/bob.pub $ git commit -m "Removed bob public key" $ git push
Add repository atom and user bob to devteam group, edit conf/gitolite.conf;
@guests = gitweb @interns = bob alice @dev = fred mary joe @teamleads = mary @staff = @interns @dev @teamleads repo @secret - = @guests option deny-rules = 1 repo @floss RW+ = @dev @staff R = @all repo @project RW+ = @teamleads - master = @dev - refs/tags/v[0-9] = @dev RW+ develop/ = @dev RW+ feature/ = @dev RW+ hot-fix/ = @dev RW = @dev R = @interns repo gitolite-admin RW+ = gitolite repo c9-doc c9-ports c9-pmwiki config gitweb.owner = "c9 team" config gitweb.category = "c9" repo c9-doc config gitweb.description = "c9 documentation" option hook.post-receive = deploy-web-doc repo c9-ports config gitweb.description = "c9 ports" repo c9-pmwiki config gitweb.description = "c9 wiki" option hook.post-receive = deploy-web-doc repo c9-assistant config gitweb.owner = "c9 team" config gitweb.category = "c9" config gitweb.description = "c9 open assistant" @secret = gitolite-admin @project = c9-doc c9-ports c9-pmwiki c9-assistant
Commit and push;
$ git add -u $ git push
Rename rep void to sysdoc, on remote host;
# cd /srv/gitolite/repositories/ # mv void.git c9-doc.git
On workstation edit conf/gitolite.conf;
repo c9-doc RW+ = bob
Commit and push;
$ git add -u $ git push
# cd /srv/gitolite/repositories/ # rm -rf c9-doc.git
On workstation edit conf/gitolite.conf and remove c9-doc.
This document creates three scripts, one is run when gitolite receives push to a project with hook active, second script is run under root user to allow operations where gitolite user have no rights, third one is project specific.
This example try to have a separate creation of a package and its deployment, in case deploy script is not on the same machine other method can be used to send the package.
A normal package will have a files.tar with all or new files to extract, if necessary a deleted file with the list of files to be removed and a project file with data about the package like new hash commit, or witch script to call to deploy.
Package is created under gitolite /srv/gitolite/deploy/hook.sh script and /srv/gitolite/deploy/deploy.sh, deploy in this example is called called by cron.
Example from Cookbook how to apply hooks only to certain repos. Uncomment or add this line on /srv/gitolite/.gitolite.rc, within the %RC block;
LOCAL_CODE => "$rc{GL_ADMIN_BASE}/local",
Uncomment the 'repo-specific-hooks' line in the rc file or add it to the ENABLE list if it doesn't exist.
# allow repo-specific hooks to be added 'repo-specific-hooks',
Create directory on gitolite-admin clone;
$ cd ~/gitolite-admin $ mkdir -p local/hooks/repo-specific
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).
On remote run;
# su - gitolite $ mkdir .gitolite/local/hooks/repo-specific $ gitolite setup
Create deploy directory on remote, /srv/gitolite/deploy was chosen to have less impact on the package system;
$ sudo -u gitolite mkdir /srv/gitolite/deploy
Script /srv/gitolite/deploy/hook.sh receives call create_package "project-name" "git-dir" "valid oldrev/invalid" "newrev" "script/to/call.sh" from gitolite hook and creates a package.
$ sudo -u gitolite cp conf/srv/gitolite/hook.sh /srv/gitolite/deploy/
Script /srv/gitolite/deploy/deploy.sh loops for each package, extracts, order commit hashes to create final snapshot of files and call script to handle deploy.
$ sudo -u gitolite cp conf/srv/gitolite/deploy.sh /srv/gitolite/deploy/
Project hooks create a package by calling hook.sh script and deploy a package being called by deploy.sh. Deploy script is a simple example that handle multiple web projects.
Create gitolite-admin/local/hooks/repo-specific/deploy-web-doc;
#!/bin/bash ###################################################################### # # Put this file in your gitolite-admin; # ~/gitolite-admin/local/hooks/repo-specific/deploy-web-doc # # set host to empty to create package for each push # or set remote host to create package based on last deployed push # host="https://doc.localhost" host="" # set name of witch branch should be deployed branch_to_deploy="deploy_branch" ###################################################################### url="$host/.last_deploy" source /srv/gitolite/deploy/hook.sh read oldrev newrev refname push_branch=$(git rev-parse --symbolic --abbrev-ref $refname) #SCRIPT_VARS=$(set) #echo "project: $PROJECT" #echo "local dir: $PWD" > /srv/gitolite/deploy/${GL_REPO} #echo "${SCRIPT_VARS}" >> /srv/gitolite/deploy/${GL_REPO} if [[ $push_branch = $branch_to_deploy ]]; then # if host empty we make local tracking if [[ $host = "" ]]; then if [[ $(is_initial ${GL_REPO}) = "true" ]]; then oldrev="initial" fi else if [[ ! $(valid_url $url) = "true" ]]; then echo "Deploy: set $url on remote to start creating packages" exit 1 fi oldrev=$(get_remote_rev $url) fi create_package ${GL_REPO} ${PWD} ${oldrev} ${newrev} "deploy-web.sh" fi
Activate this hook, the idea
#
# /etc/pkgmk.conf: pkgmk(8) configuration
#
# ONLY FOR x86 64 PROCESSORS
CUSTOMVERSION=8
W_CFLAGS="-Wall -Wextra -Wno-inline -Wundef -Wformat=2 -Wformat-security -Wformat-nonliteral -Wlogical-op -Wsign-compare -Wmissing-include-dirs -Wold-style-definition -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wsuggest-attribute=noreturn -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wstrict-aliasing=2 -Wwrite-strings -Wno-long-long -Wno-overlength-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Werror=overflow -Wdate-time -Wnested-externs"
#-ffast-math -fno-common -fdiagnostics-show-option -fno-strict-aliasing -fvisibility=hidden -ffunction-sections -fdata-sections -ffat-lto-objects
H_CFLAGS="-g -O1 -march=x86-64 -pipe -fstack-protector-strong --param=ssp-buffer-size=4 -fno-plt -fstack-check"
CFLAGS="${W_CFLAGS} ${H_CFLAGS} -fPIC -fPIE -pie"
CXXFLAGS="${CFLAGS} -D_FORTIFY_SOURCE=2"
CPPFLAGS="-O1 -Wp,-D_FORTIFY_SOURCE=2"
#--as-needed -Wl,--no-undefined -Wl,--gc-sections -Wl
LDFLAGS="-fPIC -fPIE -pie -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
PIC_CFLAGS="${W_FLAGS} ${H_CFLAGS} -fPIC"
PIC_CXXFLAGS="${PIC_CFLAGS} -D_FORTIFY_SOURCE=2"
PIC_LDFLAGS="-fPIC -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now"
# local compile only
export JOBS=$(nproc)
export MAKEFLAGS="-j $JOBS"
# ccache settings
export PATH="/usr/lib/ccache/:$PATH"
export CCACHE_DIR="/usr/ports/ccache"
export CCACHE_COMPILERCHECK="%compiler% -dumpversion; crux"
# compile using ccache and distcc
export CCACHE_PREFIX="distcc"
#export DISTCC_HOSTS="localhost/4 xborg/4 c11/2"
export DISTCC_HOSTS="ports/4 localhost/2"
## compile using distcc without ccache
#export PATH="/usr/lib/distcc/:$PATH"
#export PUMP_BUILD=yes
# distcc settings
export JOBS=$(/usr/bin/distcc -j 2> /dev/null)
export DISTCC_DIR="/usr/ports/distcc"
export MAKEFLAGS="-j ${JOBS}"
export SCONSFLAGS="$MAKEFLAGS"
case ${name} in
"keyutils")
export CFLAGS=" ${H_CFLAGS} -fPIC -fPIE -pie -g -O1 -march=x86-64 -pipe"
export CXXFLAGS="${CFLAGS} -D_FORTIFY_SOURCE=2"
;;
"grub2")
export CFLAGS="${W_CFLAGS} -g -O1 -march=x86-64 -pipe"
export CXXFLAGS="${CFLAGS} -D_FORTIFY_SOURCE=2"
export LDFLAGS=""
;;
"grub2-efi")
export CFLAGS="${W_CFLAGS} -g -O1 -march=x86-64 -pipe"
export CXXFLAGS="${CFLAGS} -D_FORTIFY_SOURCE=2"
export LDFLAGS=""
;;
"gcc")
export CFLAGS="-g -O2 -march=x86-64 -pipe -fPIC -fstack-protector-strong --param=ssp-buffer-size=4 -fno-plt -fstack-check"
export CXXFLAGS="${CFLAGS}"
export CPPFLAGS="${H_CPPFLAGS}"
export LDFLAGS=&qu