How to install a Go app without using go get?

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

How to install a Go app without using go get?

问题

我正在尝试在我的Ubuntu机器上安装特定版本的CockroachDB。我按照网站上的指南进行操作,在下载了大约200MB后,最新版本已经安装完成:

$ go get -d github.com/cockroachdb/cockroach
$ cd $GOPATH/src/github.com/cockroachdb/cockroach
$ git checkout beta-20170330
$ make install

一个问题是/src/github.com/cockroachdb/cockroach的大小为300MB,而如果我从GitHub页面下载最新版本,只有30MB。为什么会这样?

我使用git checkout v0.1-alpha切换到我想要的版本时出现了问题:

warning: unable to rmdir vendor: Directory not empty
Previous HEAD position was f0f5783... Merge pull request #14448 from BramGruneir/vendorsnappy
HEAD is now at 26088f8... Merge pull request #3475 from mrtracy/mtracy/code_review_feedback

但是在运行make install后失败了:

...
cmd github.com/cockroachdb/cockroach/protoc-gen-gogoroach      	[error exit status 2]
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor
...
protoc-gen-gogoroach/main.go:12: undefined: vanity.NotInPackageGoogleProtobuf
go install -tags ''  -ldflags '-X "github.com/cockroachdb/cockroach/util.buildTag=alpha-6447-g26088f8" -X "github.com/cockroachdb/cockroach/util.buildTime=2017/04/03 11:46:56" -X "github.com/cockroachdb/cockroach/util.buildDeps=github.com/cockroachdb/c-lz4:c40aaae2fc50293eb8750b34632bc3efe813e23f github.com/cockroachdb/cockroach:26088f81e5ecfb2fd63f8f15f524102c9a0c1c05 github.com/cockroachdb/cockroach/vendor:17711805119083543d94edac10e423260a597426 github.com/julienschmidt/httprouter:f30ab90cccbd5171771d26b6557d3c2f49e047a6 github.com/peterh/liner:4d47685ab2fd2dbb46c66b831344d558bc4be5b9 gopkg.in/yaml.v1:9f9df34309c04878acc86042b16630b0f696e1de"'
...
cli/sql_util.go:148: table.Append(row) used as value
Makefile:71: recipe for target 'install' failed
make: *** [install] Error 2

我真的很希望能够安装我从GitHub下载的特定版本,因为它的大小更小,结构更清晰。但是它缺少一些文件,如.go-version.bootstrapfatal: Not a git repository (or any of the parent directories): .git

go get会自动插入这些文件吗?我该如何初始化它们?

难道没有更好的方法来做到这一点,而不必每次运行make install时都要下载额外的100MB吗?

英文:

I'm trying to install a specific version of CockroachDB on my ubuntu machine. I followed the guide on the site and after downloading ~200MB, the latest version is installed :

$ go get -d github.com/cockroachdb/cockroach
$ cd $GOPATH/src/github.com/cockroachdb/cockroach
$ git checkout beta-20170330
$ make install

One issue is that /src/github.com/cockroachdb/cockroach is 300MB while if I download last version from the GitHub page it is only 30MB. Why?

I used git checkout v0.1-alpha to switch to the version I want :

warning: unable to rmdir vendor: Directory not empty
Previous HEAD position was f0f5783... Merge pull request #14448 from BramGruneir/vendorsnappy
HEAD is now at 26088f8... Merge pull request #3475 from mrtracy/mtracy/code_review_feedback

But it fails after running make install :

github.com/agtorre/gocolorize                      99fea4bc9517	[checkout f42b554bf7f0]
github.com/biogo/store                             913427a1d5e8	[checkout 3b4c041f52c2]
github.com/cockroachdb/c-lz4                       834d3303c9e8	[checkout c40aaae2fc50]
github.com/cockroachdb/c-protobuf                  323984796a7b	[checkout 6a18bfcdd516]
github.com/cockroachdb/c-rocksdb                   0dd42399d1f0	[checkout bf15ead80bdc]
github.com/cockroachdb/c-snappy                    c0cd3c9ce92f	[checkout 5c6d0932e0ad]
github.com/cockroachdb/yacc                        7c99dfd2164a	[get checkout 443154b1852a]
github.com/coreos/etcd                             38a914973544	[checkout 0eb46eb1457b]
github.com/cpuguy83/go-md2man                      a65d4d2de4d5	[get checkout 71acacd42f85]
github.com/docker/docker                           6311e9fc9d34	[get checkout 5e0283effa73]
github.com/elazarl/go-bindata-assetfs              30f82fa23fd8	[checkout d5cac425555c]
github.com/go-sql-driver/mysql                     9dee4ca50b83	[get checkout d512f204a577]
github.com/gogo/protobuf                           c0656edd0d9e	[checkout 8658879224bd]
github.com/golang/lint                             cb00e5669539	[get checkout 32a87160691b]
github.com/google/btree                            316fb6d3f031	[checkout cc6329d4279e]
github.com/gordonklaus/ineffassign                 f0c5cfc1817d	[get checkout 507e48671a07]
github.com/inconshreveable/mousetrap               76626ae9c91c	[get OK]
github.com/jteeuwen/go-bindata                     a0ff2567cfb7	[get OK]
github.com/julienschmidt/httprouter                6f3f3919c878	[checkout f30ab90cccbd]
github.com/kisielk/errcheck                        23699b7e2cbf	[get checkout 12fd1ab9811e]
github.com/kisielk/gotool                          0de1eaf82fa3	[get checkout 58a7a198f2ec]
github.com/kr/pretty                               cfb55aafdaf3	[get checkout e6ac2fc51e89]
github.com/kr/text                                 7cafcd837844	[get checkout bb797dc4fb83]
github.com/lib/pq                                  2704adc878c2	[checkout 11fc39a580a0]
github.com/mattn/go-runewidth                      14207d285c6c	[checkout d96d1bd051f2]
github.com/mibk/dupl                               3447d9b0cb5a	[get checkout 47b66d6a523f]
github.com/montanaflynn/stats                      f8cd06f93c6c	[checkout 4dd27fe9ac79]
github.com/olekukonko/tablewriter                  febf2d34b54a	[checkout 333c0610de34]
github.com/opennota/check                          11e2eec79ec4	[get checkout 591428223a6a]
github.com/peterh/liner                            88609521dc4b	[checkout 4d47685ab2fd]
github.com/rcrowley/go-metrics                     1f30fe9094a5	[checkout 7839c01b09d2]
github.com/robfig/glock                            39b969c32281	[checkout cb3c3ec56de9]
github.com/russross/blackfriday                    5f33e7b78783	[get checkout d18b67ae0afd]
github.com/samalba/dockerclient                    a30362618471	[get checkout 4656b1bc6cbc]
github.com/shurcooL/sanitized_anchor_name          1dba4b3954bc	[get checkout 10ef21a441db]
github.com/spf13/cobra                             7aeaa2cce6ae	[checkout ee6224d01f6a]
github.com/spf13/pflag                             d16db1e50e33	[checkout 08b1a584251b]
github.com/tebeka/go2xunit                         13c29c7515e6	[get checkout 0519fcc9b45b]
github.com/termie/go-shutil                        bcacb06fecae	[get OK]
golang.org/x/crypto                                88915ccf7aeb	[checkout 7b85b097bf75]
golang.org/x/net                                   ffcf1bedda3b	[checkout 21af302bb527]
golang.org/x/text                                  f4b4367115ec	[checkout 00e205363f74]
golang.org/x/tools                                 620ecdb8d794	[checkout 1cdaff4a02c5]
gopkg.in/yaml.v1                                   9f9df34309c0	[OK]
cmd github.com/cockroachdb/c-protobuf/cmd/protoc               	[built]
cmd github.com/cockroachdb/cockroach/protoc-gen-gogoroach      	[error exit status 2]
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/protoc-gen-gogo/descriptor
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/gogoproto
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/protoc-gen-gogo/plugin
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/vanity
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/protoc-gen-gogo/generator
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/testgen
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/defaultcheck
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/embedcheck
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/enumstringer
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/marshalto
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/oneofcheck
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/populate
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/unmarshal
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/compare
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/description
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/equal
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/face
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/gostring
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/size
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/stringer
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/plugin/union
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/protoc-gen-gogo/grpc
github.com/cockroachdb/cockroach/vendor/github.com/gogo/protobuf/vanity/command
github.com/cockroachdb/cockroach/protoc-gen-gogoroach
# github.com/cockroachdb/cockroach/protoc-gen-gogoroach
protoc-gen-gogoroach/main.go:12: undefined: vanity.NotInPackageGoogleProtobuf
go install -tags ''  -ldflags '-X "github.com/cockroachdb/cockroach/util.buildTag=alpha-6447-g26088f8" -X "github.com/cockroachdb/cockroach/util.buildTime=2017/04/03 11:46:56" -X "github.com/cockroachdb/cockroach/util.buildDeps=github.com/cockroachdb/c-lz4:c40aaae2fc50293eb8750b34632bc3efe813e23f github.com/cockroachdb/cockroach:26088f81e5ecfb2fd63f8f15f524102c9a0c1c05 github.com/cockroachdb/cockroach/vendor:17711805119083543d94edac10e423260a597426 github.com/julienschmidt/httprouter:f30ab90cccbd5171771d26b6557d3c2f49e047a6 github.com/peterh/liner:4d47685ab2fd2dbb46c66b831344d558bc4be5b9 gopkg.in/yaml.v1:9f9df34309c04878acc86042b16630b0f696e1de"'
# github.com/cockroachdb/cockroach/cli
cli/sql_util.go:148: table.Append(row) used as value
Makefile:71: recipe for target 'install' failed
make: *** [install] Error 2

I'd really appreciate if I could install the specific version I downloaded from GitHub because it's smaller in size and it has a cleaner structure. But it's missing some files such as .go-version .bootstrap and fatal: Not a git repository (or any of the parent directories): .git

Does go get insert these files itself? How do I initialize them?

Shouldn't there be a better way to do this, without having to download an extra 100MB everytime I run make install?

答案1

得分: 4

我使用了git checkout v0.1-alpha来切换到我想要的版本。

v0.1-alpha是古老的版本,肯定不是你想要的(我对它无法构建不感到太惊讶;我们自那时以来改进了构建过程的可重复性)。截至目前,最新的版本(截至本文撰写时)是形如beta-YYYYMMDD的版本。

CockroachDB 二进制发布版可以在不使用go get的情况下安装。我们目前正在重新制定安装说明,使用源代码压缩包而不是go getgit clone

英文:

> I used git checkout v0.1-alpha to switch to the version I want

v0.1-alpha is ancient, and surely not what you want (I'm not too surprised that it doesn't build any more; we've improved the repeatability of our build process since then). The most current releases (as of this writing) are the ones of the form beta-YYYYMMDD.

CockroachDB binary releases can be installed without go get. We're currently reworking the installation instructions to use a source tarball instead of go get or git clone.

答案2

得分: 0

使用go get下载cockroachdb时,我得到了一个大小为664MB的$GOPATH/src/github.com/cockroachdb/cockroach文件夹。

然后,我尝试克隆cockroachdb的github仓库,它的大小为304MB,其中大部分是因为.git隐藏文件夹,大小为263MB。

从github界面下载zip文件并解压后,我得到了一个大小为42MB的文件夹。

然而,纯粹的git克隆仓库和zip文件版本都缺少vendor文件夹,你可以在这里了解更多信息。它占用了另外302MB的空间。当使用go get下载仓库时,该文件夹会填充cockroachdb的依赖项(我猜测它会跟随github页面上的cockroach的vendor仓库链接)。

由于我是从主分支进行的操作,所以我的大小与v0.1-alpha版本有些不同。但我猜测造成大小差异的原因可能是类似的。

要使zip文件版本“工作”,你可以尝试将zip文件解压到$GOPATH/src/github.com/cockroachdb/cockroach,然后在该文件夹中运行git init。然后按照README中的说明进行操作,该说明指示您运行make build。然而,我认为您仍然需要获取一些cockroachdb的依赖项,所以最简单的方法可能是按照官方说明进行操作。

我没有尝试过,但您确定每次运行make install都会导致新的下载吗?

英文:

Downloading cockroachdb using go get I get a $GOPATH/src/github.com/cockroachdb/cockroach with a size of 664MB.

I then tried to clone the github repo for cockroachdb it has a size of 304MB most of which is because of the .git hidden folder which is 263MB.

Downloading a zipfile from the github ui and unpacking it I end up with a 42MB folder.

The pure git cloned repo and the zipfile version however lacks the vendor folder which you can read about here. It accounts for another 302MB. The folder is populated with the dependencies of cockroachdb when go get is used to download the repo (I'm guessing that it follows the link to the vendor repo for cockroach that you can see on the github page).

Since I've done this from the master branch my sizes are a bit different from the v0.1-alpha version. But I'm guessing that it has a similar cause for the size difference.

To get it to "work" using the zipfile you could try to extract the zipfile to $GOPATH/src/github.com/cockroachdb/cockroach. Then do a git init in that folder. And then follow the instructions in the README for in that tag which indicate that you should run make build. However, I believe you will still need to get some of cockroachdb's dependencies, so it is probably a lot simpler to just follow the official instructions.

I haven't tried it, but are you certain that make install causes new downloads each time you run it?

huangapple
  • 本文由 发表于 2017年4月3日 20:18:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/43184477.html
匿名

发表评论

匿名网友

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

确定