如何将Git用作内容分发网络 [英] How to use Git as content distribution network

查看:141
本文介绍了如何将Git用作内容分发网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git Internal这本书提到了在p50上使用git作为点对点内容分发网络,但没有太多细节。特别是如何有几个分支跟踪不同的文件。示例:

<工作目录>
a00.exe
a01.exe
b00.exe
c00.exe
c01.exe
c02.exe主分支跟踪所有文件,而分支A只跟踪a00.exe和a01.exe,分支B跟踪b00.exe等。下一次提交将更新a00.exe b00.exe c00.exe。如何创建这样的分支?一旦所有分支承诺,我只能从远程获取某个分支?感谢!

解决方案

您需要为您制作各种内容分支的脚本。这样做的基本方法是将内容添加到数据库(在你的情况下,只需将它们提交给主分支),然后在临时索引中读入你想要在每个分支中拥有的所有内容(git read -tree / git update-index),编写这个树(git write-tree),编写一个提交对象(git commit-tree)并更新分支到这个新提交(git update-ref)。这些都是日常操作中不常用的所有管道命令,但允许您在不同时在磁盘上的所有目录中创建快照。



这样做的例子脚本是这样的:



http://github.com/schacon/gitcrazy/blob/master/update_content.rb



这里我定义了许多服务器,每个服务器都有一个或多个角色('memcache','database'或'webserver')。然后,我可以将内容添加到像这样的角色:

  $ update_content.rb / path / to / content file_name memcache 

这会将内容添加到我的git db中,然后更新受影响服务器的分支memcache角色,在这种情况下)。我可以为任何角色的多个文件做到这一点,git会跟踪每个服务器应该具有的内容。然后每个服务器可以获取他们特定的分支('server / s1','server / s2'等)。

我正在考虑做一个快速的屏幕视频演示很快 - 希望示例脚本很有帮助。应该很容易运行,并找出发生了什么。在同一个项目中有一个列表脚本,列出了哪个服务器分支上的内容。


The book 'Git Internal' mentions about using git as peer to peer content distribution network at p50, but doesn't have much detail. Especially how to have several branches which has tracking different files. Example:

(working dir) a00.exe a01.exe b00.exe c00.exe c01.exe c02.exe

Master branch tracks all files, while branch A only tracks a00.exe and a01.exe, branch B tracks b00.exe and so on. The next commit will update a00.exe b00.exe c00.exe. How to create branches like this? Once all branches committed, can I only fetch certain branch from remote? Thanks!

解决方案

You will need to have a script of some sort build the various branches of content for you. The basic way to do this is to add the content to the database (in your case, just by committing them to the master branch), then in a temporary index, reading in all the contents you want to have in each branch (git read-tree/git update-index), writing that tree out (git write-tree), writing a commit object (git commit-tree) and updating the branch to that new commit (git update-ref). These are all plumbing commands that are not normally used in day-to-day operations but allow you to build snapshots without having all the contents in a directory on disk at the same time.

An example script to do something like this is here:

http://github.com/schacon/gitcrazy/blob/master/update_content.rb

Here I define a number of servers that each have one or more roles ('memcache', 'database' or 'webserver'). Then I can add content to a role like this:

$ update_content.rb /path/to/content file_name memcache

That will add the content to my git db, then update the branches for the servers that are affected (that have the memcache role, in this case). I can do that for multiple files for any of the roles and git will keep track of what content each server should have. Then each server can fetch their specific branch ('server/s1', 'server/s2', etc).

I'm thinking of doing a quick screencast demonstrating this soon - hope the example script is helpful. It should be pretty easy to run and figure out what's going on. In the same project there is a 'list' script that lists out what content is on which server branch.

这篇关于如何将Git用作内容分发网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆