1、邮件格式过滤
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
fi
2、主备库同步配置
配置在主库下:
路径/var/opt/gitlab/git-data/repositories/..hooks
添加新的文件post-receive.mirror
!/bin/bash
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>&1
将文件post-receive.mirror引入post-receive文件中
system 'dir=pwd
;$dir/hooks/post-receive.mirror'