replicate / cog

Containers for machine learning
https://cog.run
Apache License 2.0
7.88k stars 549 forks source link

Update CONTRIBUTING (and possibly Makefile) to reflect the new dev installation process #848

Closed zeke closed 1 year ago

zeke commented 1 year ago

https://github.com/replicate/cog/pull/823 made some changes to the build process (to pave the way for brew install cog becoming a thing). The dev env docs slipped through the cracks, and they're now out of date. Let's update them to include the proper invocation for building and installing cog locally.

A few ideas were floated about how to keep the local dev install working:

From @nickstenning:

Perhaps let's add a make install-dev which does the go install this was previously doing?

From @mattt :

we can get the old behavior with make install PREFIX=$GOPATH. What do you think about that convention?

I attempted both of those (with various prependings of sudo) but wasn't able to get either of them working. I figured I should stop and open an issue for guidance before digging any further.

mattt commented 1 year ago

@zeke Can you share the commands you tried and the output you got since https://github.com/replicate/cog/pull/823#issuecomment-1338095078?

Reading through the Go docs again:

The go install command builds and installs the packages named by the paths on the command line. Executables (main packages) are installed to the directory named by the GOBIN environment variable, which defaults to $GOPATH/bin or $HOME/go/bin if the GOPATH environment variable is not set.

What if you try running make install BINDIR=$GOBIN?

zeke commented 1 year ago

The GOPATH attempt

$ go env GOPATH
/Users/z/go

~/git/replicate/cog main*
$ echo $GOPATH

~/git/replicate/cog main*
$ make install PREFIX=$GOPATH
install -m 0755 cog /bin/cog
install: /bin/cog: Operation not permitted
make: *** [install] Error 71

~/git/replicate/cog main*
$ sudo make install PREFIX=$GOPATH
Password:
install -m 0755 cog /bin/cog
install: /bin/cog: Operation not permitted
make: *** [install] Error 71

~/git/replicate/cog main*
$ sudo make install PREFIX=$(go env GOPATH)
install -m 0755 cog /Users/z/go/bin/cog

~/git/replicate/cog main*
$ which cog
/Users/z/go/bin/cog

~/git/replicate/cog main*
$ cog --version
cog version v0.5.1-7-g0bb3ace (built 2022-12-13T09:17:37-0800)

The make install-dev attempt

Added this to the Makefile:

.PHONY: install-dev
install-dev: build-dependencies
    go install $(LDFLAGS) $(MAIN)

Then:

$ make install-dev
make: *** No rule to make target `build-dependencies', needed by `install-dev'.  Stop.

The GOBIN attempt

$ make install BINDIR=$GOBIN     
install -m 0755 cog /cog
install: /cog: Read-only file system
make: *** [install] Error 71

~/git/replicate/cog main*
$ sudo make install BINDIR=$GOBIN
install -m 0755 cog /cog
install: /cog: Read-only file system
make: *** [install] Error 71

~/git/replicate/cog main*
$ which go                       
/opt/homebrew/bin/go

~/git/replicate/cog main*
$ go version
go version go1.19.1 darwin/arm64

~/git/replicate/cog main*
$ echo $GOBIN

~/git/replicate/cog main*
$ go env GOBIN
mattt commented 1 year ago

@zeke Thanks for running through all of that.

It looks like sudo make install PREFIX=$(go env GOPATH) worked as expected. Since that's in your user directory, that should work without sudo, yeah?

sudo or not, that seems like a reasonable solution for dev env setup. (Nice work figuring out to run go env to get the missing env variables!) I opened https://github.com/replicate/cog/pull/851 with that change.