简体   繁体   English

实时 Sitecore 网站的 Git 源代码控制策略

[英]A Git Source Control strategy for a live Sitecore website

Firstly, I apologise for the sheer size of this question as I'm sure what I am proposing is a "big deal" in terms of implementing and probably could be three or four separate questions in itself.首先,我为这个问题的规模深表歉意,因为我确信我提出的在实施方面是一个“大问题”,并且可能本身可能是三个或四个单独的问题。 I wouldn't ask if I weren't in desperate need of help.我不会问我是否迫切需要帮助。

I have been given the monumental task of revising my company's risk management procedures in regards to our online work.我被赋予了一项艰巨的任务,即针对我们的在线工作修改我公司的风险管理程序。

As we take no backups, nor protect our data I have decided that, like anyone involved in professional programming should already be doing, we were going to protect our work through source control.由于我们不进行备份,也不保护我们的数据,我决定,就像参与专业编程的任何人都应该做的那样,我们将通过源代码控制来保护我们的工作。 I currently do this on a local basis with Git, but others use no source control and ultimately we lose a lot of the benefits that source control offers.我目前在本地使用 Git 执行此操作,但其他人不使用源代码控制,最终我们失去了源代码控制提供的很多好处。 I'd rather us have a system where everyone uses Git and have it enforce the rule that if it's not in source control, it doesn't stay.我宁愿我们有一个系统,每个人都使用 Git 并让它强制执行规则,如果它不在源代码控制中,它就不会保留。 Obviously, we're going to need a backup plan, but as a developer I suppose the first thing to do is to sort out the coding aspect of things before getting a backup solution sorted - obviously, any advice on that too is more than welcome.显然,我们需要一个备份计划,但作为开发人员,我认为首先要做的是在整理备份解决方案之前整理事物的编码方面 - 显然,任何关于此的建议也非常受欢迎.

We run a ASP.NET website with a SQL Server 2005 backend, running Sitecore as our CMS of choice.我们运行一个 ASP.NET 网站和一个 SQL Server 2005 后端,运行 Sitecore 作为我们选择的 CMS。 In an ideal world I would like to have all the changing parts of this CMS site under source control, including the database.在一个理想的世界里,我希望这个 CMS 站点的所有变化部分都处于源代码控制之下,包括数据库。

At the moment, and I know this isn't the greatest idea, I run one solution for ALL sublayouts built in Sitecore.目前,我知道这不是最好的主意,我为 Sitecore 中内置的所有子布局运行一个解决方案。 This is under source control and thanks to Git I've been able to add branches and push new features and fix bugs easily (using Git-flow as my workflow solution).这是在源代码控制下,感谢 Git,我已经能够添加分支并推送新功能并轻松修复错误(使用 Git-flow 作为我的工作流解决方案)。 I'm still quite new to Git though, so I've not managed anything too complex outside of committing, ignoring certain files, etc.不过,我对 Git 还是很陌生,所以除了提交、忽略某些文件等之外,我没有管理任何过于复杂的事情。

On top of this, I would also like to use source control to get the database contents under source control.最重要的是,我还想使用源代码控制来获取源代码控制下的数据库内容。 As I understand it, you can serialise Sitecore content items as a huge tree within the file system (saved as.item files if I remember correctly?).据我了解,您可以将 Sitecore 内容项序列化为文件系统中的一棵巨大的树(如果我没记错的话,另存为 .item 文件?)。 If this is the ideal solution I would also like to add these to source control, although I don't know exactly where they would be saved on the file system.如果这是理想的解决方案,我还想将这些添加到源代码管理中,尽管我不知道它们将保存在文件系统的确切位置。 My file system right now is like this:我现在的文件系统是这样的:

- Data      (Logs, indexes, etc - is this needed to be in source control?)
- Source    (Helper files, although occasionally modified)
- Website   (Containing all the files I edit, and other essential Sitecore stuff)

As mentioned already my current repository is only on my system, and it consists of a single solution folder with a bunch of.ascx, .ascx.cs, .ascx.cs.designer and the odd.aspx file or two.如前所述,我当前的存储库仅在我的系统上,它由一个解决方案文件夹组成,其中包含一堆 .ascx、.ascx.cs、.ascx.cs.designer 和一个或两个奇数.aspx 文件。 This tends to make my life easier when uploading as, like with the上传时,这往往会让我的生活更轻松,就像使用

What I would like input on is an ideal way of managing this for all developers.我想输入的是对所有开发人员进行管理的理想方式。 Despite using a DVCS I would prefer to have the live server viewed as the main repository and for all the other developers to push and pull from it, and each other.尽管使用了 DVCS,但我更愿意将实时服务器视为主存储库,并让所有其他开发人员从中推拉,以及相互推拉。 We'll be using the git-flow workflow solution as it conforms to our way of development nicely.我们将使用git-flow 工作流解决方案,因为它很好地符合我们的开发方式。 What I'm worried about, obviously, is setting this up correctly without destroying what's currently a very expensive, high-traffic site on a server with no backup.显然,我担心的是正确设置它,而不会破坏没有备份的服务器上当前非常昂贵、高流量的站点。

Tips and advice on how much of the data on the server to stick in the repository, guidance on how to handle the serialised data in Sitecore and potentially how to use the source control itself as a way of backing up to a separate repository would be welcomed.关于将服务器上的多少数据保留在存储库中的提示和建议、有关如何在 Sitecore 中处理序列化数据以及可能如何使用源代码控制本身作为备份到单独存储库的一种方式的指导,将受到欢迎. This is the first time I've had to build a source control system/workflow for a live website, so any guidance and advice on what would be the best thing for me to do would be much appreciated.这是我第一次必须为实时网站构建源代码控制系统/工作流程,因此任何关于什么对我来说最好的事情的指导和建议将不胜感激。


EDIT: I am going to put a bounty on this to try and get more guides on how people handle Sitecore with Git.编辑:我将对此给予奖励,以尝试获得更多关于人们如何使用 Git 处理 Sitecore 的指南。

To clarify myself, I am NOT looking for a way to back up my work, rather a way so that a number of developers can work on it and ensure that the code on the website is up to date with a central repository.为了澄清我自己,我不是在寻找一种方法来备份我的工作,而是一种让许多开发人员可以工作并确保网站上的代码与中央存储库保持最新的方法。 For example, I have referenced before that I will be using git-flow to manage my workflow.例如,我之前提到过我将使用 git-flow 来管理我的工作流程。 The origin repo will exist on a shared server (which in time will likely be a test environment), and all developers will have clones of that to work on and to push to.原始存储库将存在于共享服务器上(最终可能会成为测试环境),并且所有开发人员都将拥有该服务器的克隆以进行工作和推送。 From here, I want to be able to push changes from the origin repo on the shared drive to the live server and back again if errors are found.从这里开始,我希望能够将更改从共享驱动器上的原始存储库推送到实时服务器,然后在发现错误时再次返回。 I would also like to include serialised content items in my repo.我还想在我的仓库中包含序列化的内容项。

Check out HedgeHog's Team Development Soultions (3.0 is latest version).It meets many of you needs when used with Visual Studio, Sitecore Rocks, Team City (or other build server).查看 HedgeHog 的 Team Development Soultions(3.0 是最新版本)。它可以满足您与 Visual Studio、Sitecore Rocks、Team City(或其他构建服务器)一起使用时的许多需求。 Visit http://hhogdev.com/ for more details.访问http://hhogdev.com/了解更多详情。

Revised answer after revised question:修改问题后的修改答案:

Ok, let me expand on my original idea now when we have more background information from you.好的,当我们从您那里获得更多背景信息时,让我现在扩展我最初的想法。 Since you say that you only have once license for Sitecore and can't have a separate test server etc, we can always modify this slightly and still achieve the same effect.由于您说您只有一次 Sitecore 许可证,并且不能拥有单独的测试服务器等,我们总是可以稍微修改一下,仍然可以达到相同的效果。

What if you had several repositories on the same server running the live Sitecore?如果您在运行实时 Sitecore 的同一台服务器上有多个存储库会怎样? If it's possible for you to setup Sitecore to use different roots/repositories on the same file system, eg you change the url to http://yoursite.com/blahblah/test to run Sitecore in test mode.如果您可以将 Sitecore 设置为在同一文件系统上使用不同的根/存储库,例如,您将 url 更改为http://yoursite.com/blahblah/test以在测试模式下运行 Sitecore。 This depends on what kind of license you have of course, ie if it's tied to a specific machine.这当然取决于您拥有什么样的许可证,即它是否绑定到特定的机器。 Anyway, this way you could test your site on another branch (eg a develop branch in a test repository) before you merge the stuff into master and let it go live.无论如何,这样您可以在将内容合并到 master 并让它 go 活动之前,在另一个分支(例如测试存储库中的开发分支)上测试您的站点。

So you could have a bare repository on the server, where everyone push and pull from.因此,您可以在服务器上拥有一个裸存储库,每个人都可以从中进行推送和拉取。 And you could have two additional non bare repositories on the same server, one with the master branch checked out and the other with the develop branch checked out.并且您可以在同一台服务器上拥有两个额外的非裸存储库,一个签出主分支,另一个签出开发分支。 By logging in via ssh you can easily run "git pull" in the test repository if you want to test new functionality on the test version of your Sitecore site.通过 ssh 登录,如果您想在 Sitecore 站点的测试版本上测试新功能,您可以轻松地在测试存储库中运行“git pull”。 When you are happy with the changes, merge into master and push to master on your bare repo and update the live repo in the same way.当您对更改感到满意时,合并到 master 并在您的裸仓库上推送到 master 并以相同的方式更新实时仓库。

I think you need to try and find a way to have two versions of your site, so you can test the changes before they go live.我认为您需要尝试找到一种方法来拥有您的网站的两个版本,这样您就可以在 go 上线之前测试这些更改。


Original post:原帖:

I strongly suggest that you have a separation between the live server and what you are currently working on, ie another repository where you push your work too (and pull from) which works as an integration repository.我强烈建议您将实时服务器与您当前正在处理的内容分开,即另一个存储库,您也可以在其中推送您的工作(并从中提取),它作为一个集成存储库工作。 This way you can integrate code and test it locally (local to your organization) before you push it to the live server, so no one accidentally pushes code/databases/whatever directly to the live server.这样,您可以在将代码推送到实时服务器之前集成代码并在本地(您的组织本地)对其进行测试,因此没有人会意外地将代码/数据库/任何内容直接推送到实时服务器。

I'd also recommend that you take backups of the data for the central repository, in other words, git should be used as a version control system, not as a backup system.我还建议您对中央存储库的数据进行备份,换句话说,git 应该用作版本控制系统,而不是用作备份系统。 Even git might fail and cause corrupted repositories, and then you are smoked if you don't have any backups anyway.即使 git 也可能会失败并导致存储库损坏,然后如果您没有任何备份,您就会被熏死。

Also, if its possible, try to separate actual site content from the logic working on the data, ie try to keep a good model/view concept.此外,如果可能,请尝试将实际站点内容与处理数据的逻辑分开,即尝试保持良好的模型/视图概念。 This way you can easily setup a test environment with test databases that is independent of the code, and there is no need to commit databases.通过这种方式,您可以轻松地使用独立于代码的测试数据库设置测试环境,并且无需提交数据库。 Unless you really want to commit them of course:)当然,除非你真的想提交它们:)

When I step back and try to see what you are doing, it is managing the risk of losing business continuity.当我退后一步,试着看看你在做什么时,它正在管理失去业务连续性的风险。 eg If your site goes down, you would ideally want to be able to use your backup to completely and automatically restore the site.例如,如果您的站点出现故障,您最好能够使用备份来完全自动恢复站点。

Data storage is not expensive.数据存储并不昂贵。 Really, it isn't.真的,不是。 Even when you have a huge data set.即使您拥有庞大的数据集。 And therefore, requiring all developers to use git is a good idea.因此,要求所有开发人员使用 git 是一个好主意。 Many organizations set up a single git server, and you just push/pull to that server.许多组织设置了单个 git 服务器,您只需推/拉到该服务器。 If your solution has good and complete tests, you'll know very quickly if code merges have broken the software.如果您的解决方案具有良好且完整的测试,您将很快知道代码合并是否破坏了软件。 If not, you should probably use a central git server for developers to push/pull, and then a separate release integration server which uses "git fetch" to merge & test changes from the central server.如果没有,您可能应该使用中央 git 服务器供开发人员推/拉,然后使用单独的发布集成服务器使用“git fetch”来合并和测试来自中央服务器的更改。

You have outlined a variety of components of your solution, such as backing up code, data, database, CMS entries, et cetera.您已经概述了解决方案的各种组件,例如备份代码、数据、数据库、CMS 条目等。 However, the overall question you should ask is whether you have gathered enough stuff to be able to completely activate your site just from the backup.但是,您应该问的总体问题是您是否收集了足够的东西,以便能够仅从备份中完全激活您的站点。 If you can't do that, you haven't done enough.如果你不能做到这一点,那么你做得还不够。 If you can do that, you have done enough.如果你能做到这一点,你已经做得足够了。

On the licensing issue, you need a better license.在许可问题上,您需要更好的许可。 Ask the owner of Sitecore for a license for a test server, and tell them it is for a test server.向 Sitecore 的所有者索取测试服务器的许可证,并告诉他们这是用于测试服务器的。 A good vendor will realize that if they help you in this way, you are more likely to renew your subscription.一个好的供应商会意识到,如果他们以这种方式帮助您,您更有可能续订订阅。 Or, ask your finance people for another Sitecore license.或者,向您的财务人员索取另一个 Sitecore 许可证。 If your Sitecore-based CMS site is such a great utility for your company, another license won't change that benefit by much.如果您的基于 Sitecore 的 CMS 站点对您的公司来说是一个如此出色的实用程序,那么另一个许可证不会大大改变这一优势。

I spent an hour learning what I could about Sitecore (never heard of it before today, cool tool), and I think I understand what you're trying to do.我花了一个小时来了解有关 Sitecore 的知识(在今天之前从未听说过它,很酷的工具),我想我理解您想要做什么。 Here's how I would do it:这是我的做法:

  1. Setup a blessed bare repo on a Linux box (physical or virtual, shouldn't matter).在 Linux 盒子(物理或虚拟,无关紧要)上设置一个祝福的裸仓库。
  2. Initialize a git repo on the production environment, at the base folder where all source code, configuration files and data can be added to the repo.在生产环境中初始化 git 存储库,位于所有源代码、配置文件和数据都可以添加到存储库的基本文件夹中。 (Remember to set a user.name and user.email that will identify the sysadmin taking care of production updates.) (请记住设置 user.name 和 user.email 来标识负责生产更新的系统管理员。)
  3. Create a SQL Server dump file for each schema, and put all the dumps in a specially marked folder inside the local production repo.为每个模式创建一个 SQL 服务器转储文件,并将所有转储文件放在本地生产 repo 内一个特殊标记的文件夹中。
  4. Stage all files ( git add --all ) and commit with an " Initial commit, version XYZ " comment where the version number is whatever you consider the current deployment to be.暂存所有文件( git add --all )并使用“初始提交,版本 XYZ ”注释提交,其中版本号是您认为当前部署的任何内容。
  5. Push to the blessed repo.推送到有福的回购。
  6. Clone the blessed repo on all dev environments.在所有开发环境中克隆祝福的 repo。 (Again remember to set user.name and user.email for proper identification in commits.) (再次记住设置 user.name 和 user.email 以便在提交中正确识别。)
  7. Start using git-flow.开始使用 git-flow。

Note step 3 where SQL Server dumps are created and added to the repo.请注意步骤 3,其中创建 SQL 服务器转储并将其添加到存储库中。 This will allow you to rollback any future changes to the database(s).这将允许您回滚对数据库的任何未来更改。 Keep in mind you will need to generate new dumps every time you make changes, but only for schemas that actually changed.请记住,每次进行更改时都需要生成新的转储,但仅限于实际更改的模式。 Serialize what you need to serialize, and commit the new serializations along with the schema changes.序列化您需要序列化的内容,并提交新的序列化以及架构更改。 That way, git revert {commit_hash} is all you need to revert those specific changes (without forgetting to restore the database, of course).这样一来, git revert {commit_hash}就是您恢复这些特定更改所需的一切(当然,不要忘记恢复数据库)。

I hope this helps, directly or indirectly.我希望这会直接或间接地有所帮助。

PS: I don't know your database structure; PS:我不知道你的数据库结构; if configurations are stored in the same schema as the user data, it definitely complicates things since you can't just restore a previous dump without losing new (and presumably important) user data.如果配置存储在与用户数据相同的模式中,这肯定会使事情变得复杂,因为您不能只恢复以前的转储而不丢失新的(并且可能很重要的)用户数据。 I'm used to Ruby on Rails where schema revisions are coded for up- and downgrades alike;我习惯于在 Rails 上使用 Ruby,其中架构修订被编码为类似的升级和降级; I hope your framework provides a similar feature.我希望您的框架提供类似的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM