Should I add "vendor" directory into .gitignore if I am using tools like glide or godep ?

agolangf · · 201 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>They already keep *.lock file with library name and revision commit.</p> <hr/>**评论:**<br/><br/>peterbourgon: <pre><p>There is no right answer. Decide for yourself.</p> <p><a href="" rel="nofollow"></a></p></pre>jerf: <pre><p>If you are programming professionally, I suggest having a copy of all imports in at least one place in house. Having them checked in is a good way to meet that criterion. This prevents against a lot of scenarios that may individually be low probability, but together add up to something that probably will eventually happen if you continue to grow.</p> <p>Note that I&#39;m not advocating directly for &#34;always checking in vendor&#34;... I&#39;m specifically referring to having a copy internally. For instance, if you have an internal library that lives on your local source control system, there&#39;s obviously not much benefit to having more copies of that just hanging out elsewhere in your system.</p> <p>As a rule I also try to strive for &#34;I ought to be able to build all projects from scratch without hitting the internet&#34;. Again, all sorts of low-probability events (internet is down and you need to rebuild something anyhow, someone takes a project down, someone force-pushes and whacks the commit you used to be able to get, you don&#39;t have proper authentication on some internet download and you download malicious code, or someone accidentally set something to &#34;Take latest&#34; version and you get malicious code, etc etc) that are just easier to avoid and deal with if you&#39;ve got the resources internally.</p></pre>hell_0n_wheel: <pre><p>I&#39;ll go a step further than all the good advice in this thread and say <em>you should only build and ship code that&#39;s committed to your own repo</em>, including vendor libraries. Reproducible builds is one benefit, but thinking more broadly, you want your entire develop - build - test - deploy pipeline to be completely self-contained, and firewalled from external changes but at the front end. This way, you have much tighter control over exactly when and how changes are introduced. Makes for a more predictable production environment... most of the time. (Murphy was an optimist!)</p></pre>robvdl: <pre><p>No. The whole point of the vendor directory is &#34;what happens if the dependency I depend on disappears&#34;.</p> <p>Though I did read that the rules are different for libraries vs projects.</p></pre>Maksadbek: <pre><p>Yep, projects=libraries</p></pre>SeerUD: <pre><p>I&#39;ll echo something another person has said. It depends on what you&#39;re building. I have a couple of projects where they are committed, and another where they are not. The ones were they are committed are projects where I want the user to still be able to <em>just</em> run <code>$ go get ...</code> to install it. If that weren&#39;t the case, I&#39;d have to start distributing pre-compiled binaries. In libraries however, I may not choose to commit them... again, it depends. You have to judge it a bit on a case-by-case basis.</p></pre>pinpinbo: <pre><p>I think you should add it to git. Keep your deployments as immutable as possible.</p> <p>During CI process, you may lose internet connectivity, then your deployment would fail.</p></pre>ellotheth: <pre><p><a href="" rel="nofollow">From one of the Glide authors</a>:</p> <blockquote> <p>What we usually suggest is that you add vendor/ to your gitignore. Then the packages aren&#39;t checked into your local project but are instead ignored all together. If someone wants to get the packages they can run glide install and get them. They can even get the versions you specified in your glide.yaml file.</p> </blockquote> <p>Glide was influenced by PHP&#39;s <a href="" rel="nofollow">Composer</a>, which has a similar recommendation.</p></pre>peterbourgon: <pre><p>I don&#39;t think this is good default advice. It means that everybody who wants to build your repo needs to also have glide installed. I don&#39;t think that&#39;s a good assumption. This is a major reason why having dep be part of the standard tool chain is very important, so that we can make assumptions like this, and/or build the dependency management functionality into other parts of the tool.</p></pre>joeyGibson: <pre><p>It&#39;s no different than a Java project assuming you have Maven or Gradle installed. Sometimes, to build something, you have to have a certain tool. </p></pre>peterbourgon: <pre><p>Maven or Gradle are standards in the Java community. There isn&#39;t a standard in the Go community for this stuff.</p></pre>ChristophBerger: <pre><p>...yet.</p></pre>ellotheth: <pre><blockquote> <p>It means that everybody who wants to build your repo needs to also have glide installed. I don&#39;t think that&#39;s a good assumption.</p> </blockquote> <p>It&#39;s not an abnormal assumption across the package management ecosystem. Whether it&#39;s one you want to make/enforce depends on your project and audience.</p></pre>aboukirev: <pre><p>Generally they don&#39;t. <code>go get</code> walks and pulls dependencies as well, just not into vendor subfiolder but onto GOPATH. <code>godep</code> used to rewrite imports, which would break <code>go get</code>. Not anymore.</p></pre>Sphax: <pre><p>I much prefer committing the vendor directory, that way I can be sure that I&#39;ll always have the dependencies available even if the repository is unavailable, removed etc.</p> <p>If it&#39;s committed I can also simply go get the repo.</p></pre>GoTheFuckToBed: <pre><p>You should always have a backup. </p></pre>karma_vacuum123: <pre><p>God vendoring is a mess</p></pre>hell_0n_wheel: <pre><p>All you&#39;re telling us here is that you haven&#39;t spent enough time thinking about the problem to find out why &#34;it&#39;s a mess.&#34;</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:701969077

201 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传