Skip to content

Go module support #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed

Go module support #2294

wants to merge 19 commits into from

Conversation

ehazlett
Copy link

First of all, sorry for the patch bomb. Here is a cute picture to lighten the mood :)

Hug

1. What does this change do, exactly?

Migrates from gvt to Go modules.

2. Please link to the relevant issues.

3. Which documentation changes (if any) need to be made because of this PR?

  • Updated readme with new build instructions
  • Updated CONTRIBUTING.md with to reference Go modules

4. Checklist

  • I have written tests and verified that they fail without my change
    No new tests required. There are a couple failing but look unrelated:
ok      github.com/mholt/caddy/caddyhttp/browse 0.017s
--- FAIL: TestVisibleErrorWithPanic (0.00s)
    errors_test.go:157: Expected response body to contain error log line, but it didn't:
        15/Sep/2018:22:54:45 -0400 [PANIC /] src/github.com/mholt/caddy/caddyhttp/errors/errors_test.go:135 - I'm a panic

        goroutine 8 [running]:
        github.com/mholt/caddy/caddyhttp/errors.ErrorHandler.recovery(0xb05280, 0xa87318, 0x0, 0x0, 0xc000116cf0, 0x0, 0x1, 0xb0a2a0, 0xc00013e100, 0xc000106600)
                /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/errors.go:155 +0x4d4
        panic(0x982420, 0xb01390)
                /usr/local/go/src/runtime/panic.go:513 +0x1b9
        github.com/mholt/caddy/caddyhttp/errors.TestVisibleErrorWithPanic.func1(0xb0a2a0, 0xc00013e100, 0xc000106600, 0xc000055cd8, 0x50, 0xc000055cd0)
                /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/errors_test.go:135 +0x39
        github.com/mholt/caddy/caddyhttp/httpserver.HandlerFunc.ServeHTTP(0xa87318, 0xb0a2a0, 0xc00013e100, 0xc000106600, 0x0, 0x0, 0xc000116cf0)
                /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/httpserver/middleware.go:92 +0x44
        github.com/mholt/caddy/caddyhttp/errors.ErrorHandler.ServeHTTP(0xb05280, 0xa87318, 0x0, 0x0, 0xc000116cf0, 0x0, 0x1, 0xb0a2a0, 0xc00013e100, 0xc000106600, ...)
                /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/errors.go:50 +0x105
        github.com/mholt/caddy/caddyhttp/errors.TestVisibleErrorWithPanic(0xc000106500)
                /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/errors_test.go:145 +0x1f9
        testing.tRunner(0xc000106500, 0xa87320)
                /usr/local/go/src/testing/testing.go:827 +0xbf
        created by testing.(*T).Run
                /usr/local/go/src/testing/testing.go:878 +0x353
2018/09/15 22:54:45 [WARNING] Unable to open error page '404.html': open 404.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '500.html': open 500.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '404.html': open 404.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '503.html': open 503.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page 'generic_error.html': open generic_error.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '404.html': open 404.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '503.html': open 503.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '/home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/404.html': open /home/hatter/go/caddy/src/github.com/mholt/caddy/caddyhttp/errors/404.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '503.html': open 503.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page '503.html': open 503.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page 'generic_error.html': open generic_error.html: no such file or directory
2018/09/15 22:54:45 [WARNING] Unable to open error page 'generic_error.html': open generic_error.html: no such file or directory
  • I have squashed any insignificant commits
    I will squash commits once reviewed. Due to the large patch I wanted to keep the code changes separate from the vendor update.

  • This change has comments for package types, values, functions, and non-obvious lines of code

  • I am willing to help maintain this change if there are issues with it later

Steps (using Go 1.11):

  • cloned repo
  • ran go get to get the specific versions for xenolf/lego and russross/blackfriday
  • updated import paths to use latest xenolf/lego "acmev2" branch
  • ran go mod vendor to vendor the deps using go mod
  • updated docs

I've tested on two separate machines and go run build.go works on both with a fresh clone to a non GOPATH dir (if you are in GOPATH you must set export GO111MODULE=on). That being said, if you don't want this huge change feel free to close :) I won't be offended ❤️

@CLAassistant
Copy link

CLAassistant commented Sep 16, 2018

CLA assistant check
All committers have signed the CLA.

@francislavoie
Copy link
Member

I know @elcore was working on this in parallel, so tagging him on this.

@elcore
Copy link
Collaborator

elcore commented Sep 16, 2018

There are a lot of unnecessary imports (go mod tidy), and there has to be some changes to our Travis configuration. Furthermore, updating Lego should be a separate PR.

@francislavoie
Copy link
Member

@mholt I think you'd prefer to un-vendor, right? I don't think it's necessary to keep things vendored anymore now that there's a proper lock file with go mod.

@ehazlett interested in fixing up those things @elcore mentioned?

@ehazlett
Copy link
Author

@francislavoie it's still recommended to keep a vendored copy for now

I'll work on tidying and checking the travis config. thanks!

.travis.yml Outdated
@@ -5,9 +5,12 @@ addons:
- quic.clemente.io

go:
- 1.x
- 1.11.x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't change this

.travis.yml Outdated

script:
- gometalinter --install
- gometalinter --disable-all -E vet -E gofmt -E misspell -E ineffassign -E goimports -E deadcode --tests --vendor ./...
- vendorcheck ./...
- go test -race ./...
- go test -mod=vendor -race ./...

Copy link
Collaborator

@elcore elcore Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add go test -mod=readonly -race ./... before go test -mod=vendor -race ./...

.travis.yml Outdated
- go get -t ./...
- go get github.com/golang/lint/golint
- go get github.com/FiloSottile/vendorcheck
- go get github.com/alecthomas/gometalinter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep:

go get github.com/golang/lint/golint
go get github.com/alecthomas/gometalinter

@elcore
Copy link
Collaborator

elcore commented Sep 20, 2018

Please reinitialize vendor, remove the whole folder and run go mod vendor to create a new one.

Copy link
Collaborator

@elcore elcore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we need to fix Travis

@elcore
Copy link
Collaborator

elcore commented Sep 20, 2018

Maybe we should add

- go get github.com/golang/lint/golint
- go get github.com/alecthomas/gometalinter
- gometalinter --install

to before_install with GO111MODULE=off

@elcore
Copy link
Collaborator

elcore commented Sep 20, 2018

I have done some research, it looks like gometalinter is not compatible with modules. (alecthomas/gometalinter#521), we could replace it with https://github.com/golangci/golangci-lint (seems to be compatible with modules)

@mholt What do you think?

@elcore elcore added the discussion 💬 The right solution needs to be found label Sep 20, 2018
@mholt
Copy link
Member

mholt commented Sep 21, 2018

@elcore Yes, let's try switching to golangci-lint and see how it goes. :)

Lego is also making the switch: go-acme/lego#644

@ehazlett ehazlett force-pushed the go-mod branch 2 times, most recently from 771a80a to d5661ca Compare September 24, 2018 20:07
.travis.yml Outdated
env: GO111MODULE=auto
- language: go
go: tip
env: GO111MODULE=auto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just need 1.x and tip with GO111MODULE=on

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure. I believe travis will clone this to an old GOPATH style directory in which case it will use the old way of vendor (https://github.com/golang/go/wiki/Modules#when-do-i-get-old-behavior-vs-new-module-based-behavior).

.travis.yml Outdated

before_install:
# Decrypts a script that installs an authenticated cookie
# for git to use when cloning from googlesource.com.
# Bypasses "bandwidth limit exceeded" errors.
# See github.com/golang/go/issues/12933
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_3df18f9af81d_key -iv $encrypted_3df18f9af81d_iv -in dist/gitcookie.sh.enc -out dist/gitcookie.sh -d; fi
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_3df18f9af81d_key -iv $encrypted_3df18f9af81d_iv -in dist/gitcookie.sh.enc -out dist/gitcookie.sh -d; fi
- go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how I had it originally but the everything else was go get so I switched it. I'll update it to that. Thx.

.travis.yml Outdated
after_script:
- golint ./...
- golangci-lint run --deadline=10m --disable-all -E golint -E gofmt -E misspell -E ineffassign -E goimports -E deadcode ./...
- go test $TEST_ARGS -race ./...
Copy link
Collaborator

@elcore elcore Sep 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be two tests, one with -mod=readonly and one with -mod=vendor. Currently, it's only running once (probably with -mod=vendor, you don't know which one is running)

.travis.yml Outdated

after_script:
- golint ./...
- golangci-lint run --deadline=10m --disable-all -E golint -E gofmt -E misspell -E ineffassign -E goimports -E deadcode ./...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10m sounds very long...

What do you think?

Copy link

@bubbajr bubbajr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@francislavoie
Copy link
Member

Just wondering, what's the status on this @ehazlett?

@ehazlett
Copy link
Author

ehazlett commented Nov 1, 2018

@francislavoie sorry for the delay. i'll try to get it rebased and travis working.

@segfault16
Copy link

Any updates on this?

Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
Signed-off-by: Evan Hazlett <[email protected]>
@mholt
Copy link
Member

mholt commented Dec 3, 2018

This is the direction I want to take our dependency management, but I need to see how this will affect the build server and everyone's third-party plugins who may or may not use modules. Basically I'll have to take some time and do some local testing.

I haven't looked in depth yet; but why does the change lose about 70K lines of code? Are the dependencies still vendored so that we don't have to depend on third-party repos?

@ehazlett
Copy link
Author

ehazlett commented Dec 3, 2018

In my experience, go mod vendor doesn't capture everything (i.e. GRPC proto tooling - I've had to add the deps in Go files to make sure they are vendored - https://github.com/ehazlett/stellar/blob/master/proto.go#L6) so my guess is that's it. There is little code change beyond that. I'm happy to close if this bomb it too big and another approach is wanted.

@elcore
Copy link
Collaborator

elcore commented Dec 3, 2018

In my experience, go mod vendor doesn't capture everything

go mod vendor captures everything that is required to satisfy a build (if you have run go mod tidy beforehand to "reflect the dependency requirements for all possible combinations of OS, architecture, and build tags" [https://github.com/golang/go/wiki/Modules])

@ehazlett
Copy link
Author

ehazlett commented Dec 3, 2018

go mod vendor captures everything that is required to satisfy a build

correct, i didn't explain the best :). Go mod vendor will only capture that as far as I can tell. In my example, we had vendored in those files as they were needed to generate from the protos however, they are not required to build specifically so Go modules removed it. It looks like the same is happening here (as well as cleaning up some duplicates, i.e. vendor/github.com/lucas-clemente/quic-go/vendor/github.com/bifurcation/mint/syntax/tags.go).

@mholt to answer your question, a quick run through of the -191k looks like almost all vendor related. I definitely don't want to cause any issues with third party plugins, etc. To save the headache and time from the maintainers I'm going to close this for now until Go modules come out of experimental. Thanks for the reviews and sorry it was a time sink.

@ehazlett ehazlett closed this Dec 3, 2018
@francislavoie francislavoie mentioned this pull request Mar 5, 2019
@mholt
Copy link
Member

mholt commented Mar 30, 2019

Thank you for all the work done on this. Thanks to the help in this thread and in #2504, we have completed the move to Go modules.

Not 100% sure it's correct, but we'll need to iron that out next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion 💬 The right solution needs to be found
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants