局域网内有多台开发机器,因为网络的原因,从github拉取更新时总是失败,这台成功了那台又不行;还有个原因是网络速度,拉取的工程有81M,网络传输也不快。于是琢磨在本地建个github的镜像库,所有机器都统一clone自这个本地镜像库里,然后由这个镜像库负责与github更新。
cd /storage/mirror_github/
git clone --mirror git://github.com/xxx/yyy.git
这样在本地/storage/mirror_github/yyy
.git建立了github上yyy项目的一个镜像了,这是一个裸版本库(裸版本库一般约定以.git为后缀)。
在工作路径下,都从本地github库克隆:
cd /home/bob/workspace/
git clone file:///storage/mirror_github/yyy.git
......
git commit -m "balabala"
提交工作,然后本地推送更新到本地镜像库。
git push
进入镜像库,然后推送更新到github
cd /storage/mirror_github/yyy.git
git push
当有人在外地开发并将代码提交到github后,我们在本地镜像库中更新github
cd /storage/mirror_github/yyy.git
git fetch
注意这里必须用git
fetch拉取更新镜像库。
然后所有局域网内开发机就可以从镜像库中同步了
这样局域网内就以本地镜像为中转与github间更新了。
对于rebar的依赖管理会有点麻烦,我们得再写个本地deps的rebar.mirror.config,每次rebar get-deps时指定这个配置文件
rebar -C rebar.mirror.config
但是对依赖的依赖比较麻烦,写了个rebar的插件解决这一问题。
主要想法是抢在在git clone运行之前通过sed将所以github.com换成本地的git镜像库地址。sed命令如下:
sed -E 's/(git|https):\/\/github.com/ssh:\/\/file:\/\/\/storage\/github-repos/g'
rebar先获取项目根目录下所有的依赖项目,然后进入每个依赖项目,获取每个依赖的依赖。
这个替换操作在每次rebar get-dep执行之后执行
'post_get-deps'(_Config, _AppFile) ->
BaseDir = rebar_config:get_global(base_dir, undefined),
RelDir = filename:join(BaseDir, "rel"),
DepsDir = rebar_config:get_global(deps_dir, "deps"),
CD = rebar_utils:get_cwd(),
rebar_log:log(debug, "pWD: ~p, Base_Dir: ~s, Deps_Dir: ~s~n", [CD, BaseDir, DepsDir]),
case lists:prefix(RelDir, CD) of
true ->
ok;
false ->
[ update_rebar_cfg_by_sed(Dep) || Dep <- rebar_config:get_local(Config, deps, [])],
ok
end.
update_rebar_cfg_by_sed(Dep) ->
rebar_log:log(debug, "dEp: ~p~n", [Dep]),
Da = erlang:element(1, Dep),
BaseDir = rebar_config:get_global(base_dir, undefined),
DepsDir = rebar_config:get_global(deps_dir, "deps"),
CD = rebar_utils:get_cwd(),
RC = filename:join([BaseDir, DepsDir, Da]),
rebar_log:log(debug, "pwd: ~p, base_dir: ~s, deps_dir: ~s, RC = ~s~n", [CD, BaseDir, DepsDir, RC]),
rebar_utils:sh("sed -E -f " ++ ?LAN_SED(BaseDir) ++ " " ++ filename:join(RC, "rebar.config") ++ " > /tmp/rebar.config", []),
rebar_utils:sh("mv /tmp/rebar.config " ++ RC, []).
有个比较特殊的依赖(eleveldb)是通过脚本build_deps.sh获取其依赖的。需要将脚本中的github地址替换成本地。而且要在这个依赖的脚本执行之前将地址替换掉:
'pre_get-deps'(_Config, _AppFile) ->
BaseDir = rebar_config:get_global(base_dir, undefined),
DepsDir = rebar_config:get_global(deps_dir, "deps"),
CD = rebar_utils:get_cwd(),
case lists:prefix(filename:join([BaseDir, DepsDir, eleveldb]), CD) of
true ->
rebar_utils:sh("sed -E -f " ++ ?LAN_SED(BaseDir) ++ " c_src/build_deps.sh > /tmp/build_deps.sh", []),
rebar_utils:sh("chmod +x /tmp/build_deps.sh", []),
rebar_utils:sh("mv /tmp/build_deps.sh " ++ filename:join(CD, c_src), []);
false ->
skip
end,
ok.
此外,需要在根项目的rebar.config文件中指定插件:
echo '{plugin_dir, "lan"}.' >> rebar.config
echo '{plugins, [lan_deps_plugin]}.' >> rebar.config
参考:
rebar插件指南
分享到:
相关推荐
c++写的一个github快速下载器,clone速度可达10M/s c++写的一个github快速下载器,clone速度可达10M/s c++写的一个github快速下载器,clone速度可达10M/s c++写的一个github快速下载器,clone速度可达10M/s c++...
Windows系统本地git与github相连 如果没有git搭建环境,可以看我这篇文章https://blog.csdn.net/w1416520110/article/details/106012568 如果没有注册账号,可以去 https://github.com注册账号,并建立仓库,输入...
github上传本地文件方法,附带百度网盘git安装包和git安装过程截图教程Word文档,借鉴了网上资源整理而成,希望对广大网友有所帮助!
我在GitHub上创建的本地仓库代码
本地git统计信息包括类似GitHub的贡献日历
本文档通过文字加图片的形式详细介绍了如何将本地代码提交到GitHub上面,每一步都有详细的说明,以及对应的图片
如何用git将本地项目push到GitHub上?如何用git将本地项目push到GitHub上?
表格中的几个网站是github的同步镜像网站,均从网络搜集。下面是镜像网站的优点: 一:速度快,能节省打开github网页的时间和下载程序资源的时间。 二:同步性高,提供几乎和github官网一样的内容。 三:部分网站已...
如何快速将本地idea项目上传到github仓库
从Github建remote远程项目
5个好玩的github游戏区开源项目,包含c++,java,javascript,rust。
GitHub Android App源码
最新的Git与Github巨作课程,课程内容主旨分成了Git&Github极速入门与攻坚实战课程两部分,可以理解为一个是课程的详细教学篇,和一个精华缩减的集合。Git与Github教程详细介绍了Git的工作机制,Git命令行的基础学习...
github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程github使用教程...
详细介绍如何上传GitHub项目! 1. 先到github 个人网页上建立新的 ...3. 这个时候,就建立本地 git 链接文件了(红框标记),这个文件可以理解为github与本地链接点。然后把所有要上传的文件拖进去。
github的详细使用及其相关介绍 包括探索github 加入github 项目托管 工作协同 付费服务等
微信小程序的一个练手项目以及作为一个github重度使用者,使用[github api](https://developer.github.com/v3/)结合微信小程序来开发.使用方法 没有小程序的内测资格,自然也就无法上传,只能使用git clone下来...
微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信小程序demo:github博客(源代码+截图)微信...
里面包含github shell、github desktop、github