可复现的Go依赖包发布

huangapple go评论69阅读模式
英文:

Reproducible releases with go dependent packages

问题

我正在阅读《如何编写Go代码》教程,我不禁想知道如何建立一个稳定的工作流程。

当然,我的代码会放在源代码控制下,比如Git。现在我想要能够做到以下几点:

  • 构建我的项目的可执行文件,并确保对于给定的Git版本,可执行文件将会构建相同。
  • 在每次提交时运行我的项目的持续构建。我需要确保无论持续构建做了什么,都可以在我的工作站上重现。
  • 创建我的项目的发布版本。我需要知道如果我再次从相同的git代码版本创建发布版本,它可以被重新创建。

Go提供了“go get”工具来实现这一点 - 但这就是我困惑的地方。这个工具应该支持这一点,“go get”设置了依赖包的源代码控制库。这给我带来了以下问题:

  1. 我不能将依赖包放在我的源代码控制下。这意味着如果我和我的合作者之间,或者我和我的持续构建系统之间存在任何环境差异,我们将很难找出这些差异。
  2. 如果网络断开,我将无法从头开始构建我的代码。或者换句话说,我的持续构建系统每次构建发布版本时都必须访问所有这些外部服务器。这可能是脆弱的,甚至不是我愿意让外界知道的事情。
  3. Go定义了一个将包版本与基础语言版本同步的约定,但不能保证包作者会遵循这个约定。如果他们不遵循,一个干净的工作空间将会选择一个任意的可能是损坏的发布版本。
  4. 如果我依赖的项目被放弃,我可能会失去构建我的程序的能力。

我可以通过手动导入依赖项目的代码并完全不使用“go get”来解决这些问题 - 但是,这样我就避开了语言专门设计和推广的工具。

有什么建议吗?我有什么遗漏的地方吗?

英文:

I'm reading the "How to Write Go Code" tutorial, and I can't help wondering how can set up a stable workflow.

Naturally, my code would sit under source control, say Git. Now I want to be able to do the following:

  • Build the executables of my project - and being sure that for a given Git version, the executables will build the same.
  • Run a continuous build for my project to be activated on every commit. I need to be sure that whatever the continuous build does is reproducible on my workstation.
  • Create releases of my project. I need to know that a release can be recreated if I do it again from the same git version of my code.

Go provides the "go get" tool for it - but here's where I get confused. The tool that should support this, "go get", sets up the dependent packages' source control repo. Which gives me the following problems:

  1. I cannot put the dependent packages under my own source control. Which means that if there are any environment differences between me and my collaborators, or me and my continuous build system, we will have a tough time figuring out those differences.
  2. If the network is down, I won't be able to build my code from scratch. Or, to put it in a different way, my continuous build system would have to hit all those external servers every time it builds a release. This might be fragile, or even not something I'd be willing to let the outside world know.
  3. Go defines a convention of synchronizing package versions with those of the base language, but there's no guarantee the package authors will follow that convention. And if they don't, a clean workspace will pick up an arbitrary release which might be broken.
  4. If a project I depend on is abandoned, I can lose the ability to build my program.

I can work around those by importing the code for dependent projects manually and not using "go get" at all - but then, I'm avoiding a tool the language specifically designed and promoted for that use.

Any suggestions? Am I missing something?

答案1

得分: 1

go get只使用分布式版本控制系统的源代码库。它将使用本地副本库。我将在这里尝试解决您的每个问题。

  1. 如果您希望,您当然可以在本地库中进行修改并在那里提交它们。
  2. go get首先使用它构建的本地存储库,除非您明确告诉它更新。
  3. go get不会删除存储库,它仍然会存在。由于go get理解的所有源代码控制系统都是分布式源代码控制系统,所以您完全可以自己维护该项目的分支。
英文:

go get just uses the distributed version control system the source repo's use. It will use the local copy of the repo. I'll try to address each of your concerns here.

  1. You are certainly able to make modifications in the local repo and commit them there if you
    want.
  2. go get uses the local repository it built first unless you tell it to update explicitly.
  3. go get doesn't blow away the repository it will still be there. And since all the source
    control systems understood by go get are distributed source control systems there is no
    reason you can't keep a fork of the project going yourself.

huangapple
  • 本文由 发表于 2012年4月8日 01:15:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/10056582.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定