一、郵件格式過濾
pre-recieive
rev_type=commit
# Only check the first commit information due to a lot of committer email is incorrect in exist git repo
committer_email=$(git log ${oldrev}..${newrev} --pretty=format:%ce)
for email in ${committer_email};do
email_user="${email%@}"
email_domain=${email##@}
query_sql="select email from users where state = 'active' and email ~* '${email_user}@'"
sql_result=psql -t -h 127.0.0.1 -U autotools -d gitlabhq_production -c "${query_sql}"
break
done
allow_domain_list="domain1 domain2 domain3 "
if [[ "$sql_result" == "" || ! ${allow_domain_list} =~ (^|[[:space:]])${email_domain}($|[[:space:]]) ]];then
echo "--rejected: $email is incorrect committer email,committer email MUST be gitlab account."
exit 1
figit
二、主備庫同步配置
配置在主庫下:
路徑/var/opt/gitlab/git-data/repositories/..hooks
添加新的文件post-receive.mirrorsql
LogName="/var/opt/gitlab/script/logs/post-receive.log"
NowDate=date
GitBackDir="ip"
GitFilePath=pwd
RemoteGitFilePath="${GitFilePath/*repositories//}"
echo "=====Mirror repo $RemoteGitFilePath_bx to address:$GitBackDirat $NowDate=====" >> $LogName
echo "git@ip:${RemoteGitFilePath}" >>$LogName 2>&1
git push --mirror git@${GitBackDir}:${RemoteGitFilePath} || echo "Failed To Push Mirror">>$LogName 2>&1bash
將文件post-receive.mirror引入post-receive文件中
system 'dir=pwd
;$dir/hooks/post-receive.mirror'dom