Trying to build caddy from source to test 2.5.0-beta with plugins

I’m confusing myself when attempting to build caddy from source with plugins for specific testing and following the directions from the Caddy readme.md. As a non go programmer I’m going in circles here so I’m going to stop and ask. The readme.md for caddy states the following:

With version information and/or plugins

Using our builder tool, xcaddy>>> YEP got xcaddy installed on system, OK I’m ready for next step and… ok this looks too simple?

$ xcaddy build

This part fails for me, I’m assuming I can NOT use go 1.18 here and should fall back to go 1.16 to get past this error (I’m wanting to confirm this)?

2022/03/16 21:42:28 [INFO] exec (timeout=0s): /usr/bin/go build -o /home/agrajag/caddy -ldflags -w -s -trimpath 
# github.com/lucas-clemente/quic-go/internal/qtls
/home/agrajag/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.23.0/internal/qtls/go118.go:5:13: cannot use "quic-go doesn't build on Go 1.18 yet." (untyped string constant) as int value in variable declaration
2022/03/16 21:44:38 [INFO] Cleaning up temporary folder: /tmp/buildenv_2022-03-16-2141.215925827
2022/03/16 21:44:38 [FATAL] exit status 2

…the following steps are automated: >>> This is where I get completely lost as I’m trying to add plugins and the steps fall apart logically for me?

  1. Create a new folder: mkdir caddy
  2. Change into it: cd caddy << Ok I understand these first two steps…
  3. Copy Caddy’s main.go into the empty folder. Add imports for any custom plugins you want to add. <<< Ok on grabbing the file, but I’m starting to get lost here
  4. Initialize a Go module: go mod init caddy <<< not sure what this is doing, but "OK"
  5. (Optional) Pin Caddy version: go get github.com/caddyserver/caddy/v2@version replacing version with a git tag, commit, or branch name. <<< so I think this would be something like:
go get github.com/caddyserver/caddy/v2@v2.5.0-beta.1
  1. (Optional) Add plugins by adding their import: _ "import/path/here" <<< this is not clear as to what to provide for this step… Do I use a a git clone of the plugin and provide the path of it, replacing the whole import/path/here to provide it? Am I editing something to add the import: assertion that seems to be indicated, for example:
import:_/home/agrajag/someplugin-git-clone-path

OR is it

import:_ "/home/agrajag/someplugin-git-clone-path"

or some other variant not obvious to the non go enthusiast?

  1. Compile: go build

With this last step, again I’m assuming this will fail as long as I attempt to use 1.18…

Thanks in advance for any clarifying pointers (or longer example pointer to what I could not locate…)

1 Like

Ah, yeah, the beta was tagged just a little before Go 1.18 was released. Unfortunate. There’s one dependency that is not forwards-compatible with Go versions, believe it or not. It’s the HTTP/3 lib.

You could specify the v0.25.0 version when you build Caddy:

--with github.com/lucas-clemente/quic-go@v0.25.0

And I think that should make it build for you.

We’ve already updated this dep on master so the next release of 2.5 will be built on Go 1.18:

2 Likes

Yeah as Matt explained, none of the tagged builds of Caddy build with Go 1.18 yet, you’d need the latest commit on the master branch to do so (we had to make a fix as soon as 1.18 came out to make it work).

You can use Go 1.16 or 1.17 for now, if you don’t want to do that version replacement of quic-go.

This command will build with the latest stable version of Caddy, i.e v2.4.6. If you want to build the beta, you need to specify the version:

$ xcaddy build v2.5.0-beta.1

If you want to add plugins, you specify each plugin with the --with flag.

You don’t need to do any of those manual steps. With go get etc.

1 Like

Ok thanks!

This topic was automatically closed after 60 days. New replies are no longer allowed.