-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Migrate to gomods #2504
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
Migrate to gomods #2504
Conversation
Just to clarify, how does it differ from #2294? |
Currently checking the effect and where pain points would lay. We are migrating a plugin to gomod and recently migrated CoreDNS, which is based on Caddy to gomods. But also happy to close this as Matt seems to still investigate things. |
Moving to modules is one of the last things we need to do before a 1.0. Feel free to experiment here -- although there is already another PR open to do this. Updating our build server to support modules is another major task I need to do before we can make the move to modules. |
Move to go mod + vendor and CI working (appveyor just doesn't use g1.12 yet even so it's defined in the stack 🤔 ) Building Caddy with the vendored mods:
Building plugins is currently being tested, but should be as simple as:
|
Cool! So building plugins is basically unchanged. (Yeah, AppVeyor is being slow, or something: appveyor/ci#2875 -- you'll unfortunately have to ignore those results for now.) Is the reason that we still have a vendor folder because some projects don't support modules? |
The vendor folder is there for vendoring. The build should also work with removing I kept or readded vendoring due to the usual concerns of third parties going away. |
Also on the plugins yes. As long as they are mentioned within caddy's run.go file they should be fine. |
I'm actually really OK with getting rid of the vendor folder entirely, as long as we can pin dependencies with modules instead. (I plan on having a separate origin/repo that consists of basically a GOPATH just for Caddy, so that if a third party dependency disappears, we can restore a fork of it to somewhere and then use that. I don't expect that to happen too often, but this way we'll have a public backup.) |
Also public backups of modules could be easily produced by setting a module proxy, which stores all used modules. Example: Athens. Will remove vendor. Also will write up a way for external plugin authors to use gomods to build their plugin into caddy. Still researching the best way. |
Thanks for your effort on this! It's kinda weird/tricky too because Caddy is both a command and a library -- AFAIK, libraries aren't supposed to use modules, are they? Or does that rule only apply for vendor folders. |
Modules should make this a bit easier being a command and a library. For example CoreDNS moved to go modules and has the same problem, but uses caddy as a dependency. Afaik the vendor folder is only taken into account on the specific project not from dependencies. |
Wow. |
Example makefile to let a plugin test/build with caddy. This should be seen as a PoC idea not production ready.
It basically pulls in a caddy copy, write the plugin into go.run and plugins.go adds a replace statement to go.mod so that the caddy-copy uses local source code instead of pulling outside versions. Current downside. The plugin is not easily go gettable and needs a makefile. Additionally the version of caddy isn't pinned down (could be done in code by checking out a specific tag so). So if anyone has a better solution to make this more go module native, I'm all ears. |
Woah, that's complicated. So modules won't "just work" with Caddy plugins? AFAIK there shouldn't be cyclic dependencies, as Go programs won't build if the imports cycle. |
Most of the complication comes from adding in the plugin and from building within a plugin. I can take another stab at simplifying this end of month probably. |
It seems I still have a lot to learn about modules then. Currently, "adding" a plugin simply means adding an import statement in |
From a plugin perspective: Non module way (manual):
Non module way (automatic):
Module way (manual):
Module way (automatic):
So in my mind not that more complicated. That's also where the cyclic dependency comes from.
Maybe I'm missing some essential simplifications and happy to take another look as I said. For now the makefile enables a plugin to not mess with any local caddy environment and run a full build self-contained during CI. |
I don't see an issue here, adding a plugin and compiling works fine for me. I used the git plugin as a test. Am I missing something? Edit: I successfully implemented modules into caddy-git, I just had to pull your branch into the local module storage (as your branch is not in master). Everything was working fine, nevertheless it's kind of hacky. I think this will be resolved after this PR is merged. Feel free to correct me. |
@elcore can you elaborate, which specific steps you took and how/if they were different than from before. Just want to make sure I get the context on your lgtm. |
Also in terms of tooling there is another non makefile way, which is using a tools.go file and go:generate to call the tools. This isn't so much about CI, but about build tools. More info as it's mostly just to provide more context into go modules: |
Here is what I wrote to Matt.
|
I've been working on this today. I got the build server modified in my dev machine by adding But this is really hard to test fully in a dev environment, from a fork, on a branch. I think I want to merge this, tag a |
Well we're gonna need to do this sooner or later, might as well do it sooner and figure out exactly what will need to be fixed as soon as possible. I pushed a change that fixes the merge conflict. Will merge this in a few minutes, and pray I don't regret it. 🙏 😅 |
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.
No description provided.