-
Notifications
You must be signed in to change notification settings - Fork 58
Add opt-in support for using Go modules. #24
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
Conversation
ARG GOPROXY="" | ||
|
||
RUN go build --ldflags "-s -w" -a -installsuffix cgo -o handler . | ||
RUN go test ./function/... -cover |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. I have two quick questions:
- Why are we splitting this into two commands?
- Why are we not ignoring the tests in the vendor directory? Are they ignored by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @matipan!
Why are we splitting this into two commands?
That's just for the sake of readability. It doesn't impact the final image size AFAIU (plus this corresponds to the builder image, which is not final).
Why are we not ignoring the tests in the vendor directory? Are they ignored by default?
On the one hand, and according to my understanding, go mod vendor
does not include test files:
$ go help mod vendor
(...)
It does not include test code for vendored packages.
(...)
On the other hand, and also according to my understanding, dep
(and friends?) prunes test files by default:
[prune]
(...)
test-go = true
There may, of course, be flaws in this thinking, so please let me know what your thoughts are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, i think the changes look good, but agree with @matipan 's comment about the build/test command
👍 on this one, started recently with golang and managed to get away from godep and $GOPATH prison into go modules, it'd be great to use that with openfaas. anything I can do to help pushing this? |
Hi @fopina, we have carried out a review and are waiting on @bmcstdio's response. In the interim, would you like to do some testing on this version of the template? Alex |
yes, I am using it (since I posted last time so not for long I’d say :)). |
We have a specific requirement to be backwards compatible with the vendor folder. That's something Bruno suggested. |
I think that makes perfect sense and I haven’t tested with a godep app so I can’t confirm at the moment. |
@fopina cc @alexellis as I've mentioned above, and according to my understanding, |
@bmcstdio hi, this will need a rebase, I can see 3 files conflicting. Thanks, Alex |
Could you do a quick test please? 👍 |
Hi, it looks like it's been 40 days since my last two comments:
Once that's covered, I think this can be merged. Alex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this can't be merged without a rebase.
Just tested everything and it works like a charm. I'd really love to see this merged ❤️ Could u take a look into the rebase needed @bmcstdio? Thanks for the work! |
@jonatasbaldin rebased (cc @alexellis), and bumped to Go 1.13.1 in the meantime. Would you be able to test again, please? I don't have a lot of time at hand at the moment, unfortunately. :( |
My tests using the example form @bmcstdio: dep
go mod
I tried changing the test command to the old one, but them the tests don't run. I also tried changing the build image to the older one, which got me another error:
Could u take a look @bmcstdio? |
Thank you for taking a look at this and doing the additional testing. |
Signed-off-by: Bruno Miguel Custódio <brunomcustodio@gmail.com>
@jonatasbaldin @alexellis I believe the issue is fixed now, could you please re-test on your side? |
Since @jonatasbaldin was testing, I'll await feedback from him @bmcstdio . |
Hey there, it worked! Just making sure (as already stated in the PR):
So, from the examples, everything is working fine ✨ I also tested with this little app I made called Brunchies locally and also worked fine. I think we are good! Thanks a lot @bmcstdio 🎉 |
hey @alexellis, I've tested this and it was working ok, if you could take a look into it :) |
@jonatasbaldin as you seem to be "needing" this merge, you are aware you can easily use the templates from @bmcstdio and skip core ones completely right? |
Thanks @fopina for the tip, but the case is that I want to use it in the public OFC, which doesn't accept custom templates :( |
Ah ok, haven’t tried OFC yet, but sounds like a decent feature request hehe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
@bmcstdio I just noticed the Go version was changed to 1.13 and the Go mod says "go 1.12", do you want to send a follow-up PR to make them the same? I'll merge this now given that @jonatasbaldin gave the all-clear. Thanks so much for working on this and for collaborating with the community on it. |
This is part of a consistency exercise for #33 - the go mod version now matches the Go version in the Dockerfile. This was queried with @bmcstdio, but we got no response on his PR. #24 (comment) Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
Description
As discussed earlier today with @alexellis and other maintainers, this PR aims at allowing function authors to use Go modules in an backwards-compatible, opt-in fashion. It relies on the following observations:
dep
(or any other vendoring tool for that matter). As long as there's a populatedvendor/
directory inside the directory containing the function, things just work.GO111MODULE=on
can be used to turn Go modules on when required (as well as to force Go modules to be enabled when insideGOPATH
).faas build
allows users to set build-time variables, allowingGO111MODULE
to be set as desired.go mod vendor
can be used to create a populatedvendor/
directory before runningfaas build
if that is ever needed.This allows for a "new" workflow to be established:
dep
or some other vendoring tool, no action is required as these changes are backwards-compatible. The user may keep on doing whatever they currently do.This will cause Go modules to kick-in in build-time to fetch the required dependencies. In case this is not desired (such as when some dependencies come from private repositories, for example), the user can use
go mod vendor
to pre-populate thevendor/
directory and simply runfaas build
as usual (hence effectively disabling Go modules in build-time).I am keeping propagation of this change to https://github.com/openfaas/templates and updates to the documentation on hold until we can gather more feedback on this, as I believe that's the best for now.
How Has This Been Tested?
I've tested by executing the workflow described above against two branches in the https://github.com/bmcstdio/golang-http-template-modules-example repository:
dep
.Each branch contains a
Makefile
defining abuild
target that can be used to illustrate and reproduce the behaviour described above.How are existing users impacted? What migration steps/scripts do we need?
As mentioned above, users wanting to retain the current behaviour do not need to perform any action.
Checklist:
I have:
git commit -s