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
Add short script to move vendor folder around #56
Add short script to move vendor folder around #56
Conversation
**What** - Add Dockerfile testp to mov ethe vendor folder up from the function volder to function root. This allows the user to control the vendor folder and avoid collisions/validation errors from Go in modules mode - This new flow allows dynamic downloading of Go modules _or_ disabling Go modules and only using vendor. You can not use vendor _and_ modules at the same time due to how Go will validate that the vendor folder and the go.mod are insync Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
# Add user overrides to the root go.mod, which is the only place "replace" can be used | ||
RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0 | ||
RUN if [ -d ./function/vendor ] && [ "${GO111MODULE}" == "off" ]; then \ |
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.
As a note, I don't think we'll need the GO111MODULE
check in 1.17, when it can't be turned off.
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.
yeah, i removed it in the http template, they aren't in perfect sync yet
This looks good. Do you have any concerns or areas where I can help with testing / validation? |
This change is not 100% backwards compatible. For example, there is no support for vendor and modules at the same time. When modules is enabled, it will always attempt to download the modules. Which could be an issue for things like private modules. These users must use vendoring with I don't know about any other configurations, e.g. existing functions using vendoring and dep, we should test that. I am not sure about any other configurations we want to support |
**What** - Remove the tidy step because it is not needed and does not work as expected Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
**What** - Remove check for modules = off from the middleware template. This isn't needed Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
golang-middleware template:
In Go 1.17, this will fail, because go modules are always forced on, and you cannot build from GOPATH
golang-http template:
|
Couple of suggestions for things to try: 1 - lift the handler/function code up one level and overwrite the go.mod/sum of the main entrypoint |
**What** - Add scripting that handles copying the function's go.mod to the function root. This requires several mutations to handle renaming the module and dealig with local replacements of the function - Add scriptin to handle the vendor/modules.txt. It also handles mutations to deal with the local replacement of the function code Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
@alexellis i have pushed a change that lifts the go.mod/go.sum to the main entrypoint, but only for the http template. With this, i have had successful builds with
This also includes have sub-packages in my handler code, here is the structure of my test function with the vendor folder
It is important to note that this requires a small bit of schenanigens for local development, specifically, if you have sub-packages, then you need to import them relative to This is what the
A side of effect of this approach is that the |
template/golang-http/Dockerfile
Outdated
ARG GOFLAGS="" | ||
|
||
# Add user overrides to the root go.mod, which is the only place "replace" can be used | ||
RUN cat function/GO_REPLACE.txt >> ./go.mod || exit 0 |
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.
Lucas: is this line needed still?
template/golang-http/Dockerfile
Outdated
# remove any local require for the handler/function, this can exist _if_ the | ||
# developer has subpackages in their handler. It is ok to just remove it | ||
# because we will replace it later | ||
grep -v "handler/function" go.mod > gomod2; mv gomod2 go.mod && \ |
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.
Is there an issue with piping this instead? Would ;
work as &&
?
Question for you - could this be a bash script that's copied in from the base template? |
From our call - what does a sub-package look like now with these changes? |
**What** - Extract the vendor and modules cleanup into a separate shell script. This provides more space for documenting each step cleanly. - This scripting also removes the need for the `GO_REPLACE.txt` hack, it will automatically modify any local replacements in the original go.mod file, so that they work as expected. - Update the README to describe how dependencies work in the three supported modes: modules with vendoring, modules without vendoring, and traditional vendoring via dep. Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
@alexellis i have moved the logic to a shell script now. Note, from the commit message, this will automatically handle the GO_REPLACE so that we don't need the extra file anymore:
I would like to also commit a sample function to the repo, what do you think? It would be really helpful to have a test/sample function that we can all reference as a baseline verification that the template compiles, at least for the two module use cases: with and without vendoring. |
**What** - Add check and skip when the funciton folder is not a module Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
129d3e5
to
28697c3
Compare
ping-ity ping ping |
@alexellis can you re-review this and let me know what needs to be done for it to be merged? I feel like it is ready to be merged |
go mod edit -replace=handler/function=./ | ||
``` | ||
|
||
Now if you want to reference the`version` sub-package, import it as |
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.
Nit: needs a space after "the"
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. Let's see how we get on with this.
Will the script work on Alpine Linux's shell (ash) and on Ubuntu's bash shell?
|
||
# Copy the user's go.mod | ||
mv -f ./function/go.mod . | ||
mv -f ./function/go.sum . |
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.
It seems like this fails in case the file is not present, making the docker image construction fail
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.
yes it currently assumes that you have a go.sum if you have a go.mod. Per the recommendations from the Go team, the file should exist and should be committed with your project https://github.com/golang/go/wiki/Modules#should-i-commit-my-gosum-file-as-well-as-my-gomod-file
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.
Ah ok, that I did not know. Thank you very much, I have modified my functions!
@alexellis the script is written and run using |
What
This provides more space for documenting each step cleanly.
GO_REPLACE.txt
hack,it will automatically modify any local replacements in the original
go.mod file, so that they work as expected.
supported modes: modules with vendoring, modules without vendoring,
and traditional vendoring via dep.
Go modules and only using vendor. You can not use vendor and modules
at the same time due to how Go will validate that the vendor folder
and the go.mod are insync
Description
How Has This Been Tested?
You can test this branch of the template using
I manually tested with this handler implementation
How are existing users impacted? What migration steps/scripts do we need?
Users should not notice any change.
Checklist:
I have:
git commit -s