简体   繁体   English

如何使用GitFlow进行推广?

[英]How exactly works build promotion with GitFlow?

I'm having a hard time understanding how exactly the concept of promoting builds (and their artifacts) works together with GitFlow. 我很难理解促销构建(及其工件)的概念与GitFlow一起是如何工作的。 I'm in the process of working out a continuous integration/delivery workflow with Git, Jenkins and (as a new addition) Artifactory. 我正在与Git,Jenkins和(作为新增加的)Artifactory一起制定持续的集成/交付工作流程。 This is what I have worked out so far: 这是我到目前为止所做的:

  • Build artifacts from the develop branch will automatically be pushed to a dev repo (if unit tests etc. pass) and therefore promoted to a dev status. 来自develop分支的构建工件将自动被推送到dev repo(如果单元测试等通过),因此被提升为dev状态。 Further promotions are not possible for these artifacts. 这些工件不可能进一步促销。
  • Artifacts from feature branches don't get pushed or promoted at all. feature分支中的工件根本不会被推送或提升。
  • Artifacts from the release branch can also only be promoted to dev (or should I introduce a release repo?) release分支中的工件也只能提升为dev (或者我应该引入一个release回购?)
  • As soon as release is merged into master , the new commit is tagged and Jenkins runs the full CI/CD pipeline. 一旦将release合并到master ,就会标记新的提交,并且Jenkins会运行完整的CI / CD管道。 After unit tests and metrics (build stages which are run on all branches) the artifact is pushed to a master repo and promoted to master . 单元测试和指标(构建其上的所有分支运行阶段)后的工件被推动到一个master回购和升为master Then the artifact is used for deployment to a staging environment, where final testing can be made (these tests can be automated in a full continuous deployment setup). 然后,工件用于部署到临时环境,在该环境中可以进行最终测试(这些测试可以在完整的连续部署设置中自动完成)。 If all tests are successful, the artifact will be pushed to a prod repo, deployed to production and promoted to prod status. 如果所有测试都成功,则工件将被推送到prod仓库,部署到生产并升级到prod状态。 If any stage until production fails, the tag belongs to a version, that never made it to production. 如果生产失败之前的任何阶段,标签属于从未进入生产的版本。

Is my understanding correct? 我的理解是否正确? I'm mostly confused about the master/release merging. 我对主/发布合并感到困惑。 Intuitively I would have said, that the binaries from release would undergo the most testing. 直觉上我会说, release的二进制文件将经历最多的测试。 However, GitFlow dictates that only commits on master get tagged (and I don't want to tag commits that technically did not produce the binaries which land in production). 但是,GitFlow规定只有master提交被标记(我不想标记技术上没有生成生产中的二进制文件的提交)。 What if problems are found during the build of the commit on master ? 如果在master的构建过程中发现问题怎么办? Is it "wrong" to have tags, which did not make it to production? 标签是否“错误”,而这些标签还没有投入生产? Do I have to revert or undo the tag or even the merge commit? 我是否必须还原或撤消标记甚至合并提交?

It would be nice to hear other peoples approach to this build promotion + GitFlow thing. 听到其他人采用这种构建促销+ GitFlow的方法会很高兴。 Any help is much appreciated. 任何帮助深表感谢。

There are so many different branching models, and so many people with their own takes, that I don't think there is a definitive reference on what "GitFlow" means. 有这么多不同的分支模型,有很多人有自己的需要,我认为没有明确的参考“GitFlow”的含义。 (Please feel free to prove me wrong, I love to debate this sort of thing). (请随意证明我错了,我喜欢辩论这种事情)。

With that being said, I (personally) find these two references to be very helpful, complete, and compelling: 话虽如此,我(个人)发现这两个引用非常有用,完整且引人注目:

  1. Original NVIE blog post 原始NVIE博客文章
  2. DataShift breakdown DataShift细分

So, what? 所以呢?

In my opinion, your first two points are correct and your last two points are wrong. 在我看来,你的前两点是正确的,你的最后两点是错误的。

From a build promotion standpoint, all release and hotfix branches are eligible (and expected) to be deployed to your test / staging environment for final verification. 从构建升级的角度来看,所有releasehotfix分支都符合(并且预期)部署到test / staging环境以进行最终验证。 From DataShift: 来自DataShift:

The code in the release branch is deployed onto a suitable test environment, tested, and any problems are fixed directly in the release branch. 发布分支中的代码部署到合适的测试环境中,进行测试,并且任何问题都直接在发布分支中修复。 This deploy -> test -> fix -> redeploy -> retest cycle continues until you're happy that the release is good enough to release to customers. 此部署 - >测试 - >修复 - >重新部署 - >重新测试周期将继续,直到您对该版本足以发布给客户感到高兴。

Then once everything has been verified and you're ready to release: 一旦所有内容都经过验证并且您已准备好发布:

When the release is finished, the release branch is merged into master and into develop too, to make sure that any changes made in the release branch aren't accidentally lost by new development. 发布完成后,发布分支将合并到master并进行开发,以确保发布分支中所做的任何更改都不会被新开发意外丢失。

Or, to summarize: 或者,总结一下:

The master branch tracks released code only. 主分支仅跟踪已发布的代码。 The only commits to master are merges from release branches and hotfix branches. 唯一提交的提交是从发布分支和修补程序分支合并。

Here is where it gets tricky and different projects have different opinions: where does the prod artifact actually come from? 这是它变得棘手的地方,不同的项目有不同的意见: prod工件实际上来自哪里?

As I see it, you have two choices: 在我看来,你有两个选择:

  1. Re-use the artifact from test / staging that was built from the release / hotfix branch. 重用从release / hotfix分支构建的test / staging中的工件。
  2. Re-build the artifact from the commit in master . master的提交重新构建工件。

From a code only perspective, these are equivalent - the code in master exactly matches the code that was just built and deployed to test / staging . 仅代码的角度来看,这些是等效的 - master中的代码与刚刚构建和部署到test / staging的代码完全匹配。 However, from a build process perspective things might be different - different environment variables, different keys, etc. 但是,从构建过程的角度来看,事情可能会有所不同 - 不同的环境变量,不同的键等。

Furthermore, things can be complicated with how your team views test vs staging . 此外,您的团队如何看待teststaging ,事情可能会变得复杂。


So, what to do? 那么该怎么办?

With the caveat that this is just my opinion and the assumption that staging means "production mirror", I think the following is a sensible process: 需要注意的是,这只是我的意见,并且假设staging意味着“生产镜像”,我认为以下是一个明智的过程:

  • Feature branches are not deployed to a shared environment 功能分支未部署到共享环境
  • The dev environment (if present) is built/deployed from the develop branch develop分支构建/部署dev环境(如果存在)
  • The test environment is built/deployed from a release or hotfix branch releasehotfix分支构建/部署test环境
  • The staging environment is built/deployed from a release or hotfix branch AFTER normal testing/fixing has completed. 在正常测试/修复完成后,从releasehotfix分支构建/部署staging环境。 NOTE: You could indicate this with an RC tag, but that's a team process question. 注意:您可以使用RC标记来指明这一点,但这是一个团队流程问题。
  • After staging verification is complete, the code is merged from release / hotfix to master and tagged with the release version. staging验证完成后,代码将从release / hotfix合并到master并使用发布版本进行标记。
  • The prod environment is deployed with the approved and tested artifact from staging . 使用经过批准和测试的工件从staging部署prod环境。

Final thoughts: 最后的想法:

GitFlow is a great place to start, but you're ultimately going to customize it for your own needs. GitFlow是一个很好的起点,但你最终会根据自己的需要定制它。 Don't be afraid to say "this is what works for our team" and do it your own way - just make sure it's written down so everyone understands how you're doing it. 不要害怕说“这对我们的团队有用”,并按照自己的方式行事 - 只要确保写下来,这样每个人都能理解你是如何做到的。

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

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