abiosoft / caddy-docker

Docker container for Caddy
https://hub.docker.com/r/abiosoft/caddy/
MIT License
770 stars 316 forks source link

Can't build container #209

Open thepatrick opened 5 years ago

thepatrick commented 5 years ago

docker build is failing for me today with the error: go: github.com/mholt/caddy@v1.0.1: parsing go.mod: unexpected module path "github.com/caddyserver/caddy"

Full logs below:

$  docker build -t thepatrick/webserver-caddy --build-arg plugins=cloudflare,route53 github.com/abiosoft/caddy-docker.git                                                   1
Sending build context to Docker daemon  109.1kB
Step 1/24 : FROM abiosoft/caddy:builder as builder
 ---> 5e3f22e6d0be
Step 2/24 : ARG version="1.0.1"
 ---> Running in 2f67cc2ebd63
Removing intermediate container 2f67cc2ebd63
 ---> 7244e5b4163a
Step 3/24 : ARG plugins="git,cors,realip,expires,cache,cloudflare"
 ---> Running in 5b144e79dff0
Removing intermediate container 5b144e79dff0
 ---> dde9d244d51f
Step 4/24 : ARG enable_telemetry="true"
 ---> Running in 2c76d5ef505c
Removing intermediate container 2c76d5ef505c
 ---> 6f2d65df036a
Step 5/24 : RUN go get -v github.com/abiosoft/parent
 ---> Running in cb639dfd59b1
github.com/abiosoft/parent (download)
github.com/abiosoft/parent
Removing intermediate container cb639dfd59b1
 ---> 5e34135da33e
Step 6/24 : RUN VERSION=${version} PLUGINS=${plugins} ENABLE_TELEMETRY=${enable_telemetry} /bin/sh /usr/bin/builder.sh
 ---> Running in 6228775928e1

starting stage: fetching caddy source
Cloning into '/go/src/github.com/mholt/caddy'...
Note: checking out 'f6ee100bae9c0de566a2f7ae531113be0a9a0b83'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

Cloning into '/dnsproviders'...
finished stage: fetching caddy source ✓

starting stage: installing plugin helper
go get: warning: modules disabled by GO111MODULE=auto in GOPATH/src;
    ignoring go.mod;
    see 'go help modules'
github.com/abiosoft/caddyplug (download)
github.com/abiosoft/errs (download)
github.com/fatih/color (download)
Fetching https://golang.org/x/sys/unix?go-get=1
Parsing meta tags from https://golang.org/x/sys/unix?go-get=1 (status code 200)
get "golang.org/x/sys/unix": found meta tag get.metaImport{Prefix:"golang.org/x/sys", VCS:"git", RepoRoot:"https://go.googlesource.com/sys"} at https://golang.org/x/sys/unix?go-get=1
get "golang.org/x/sys/unix": verifying non-authoritative meta tag
Fetching https://golang.org/x/sys?go-get=1
Parsing meta tags from https://golang.org/x/sys?go-get=1 (status code 200)
golang.org/x/sys (download)
github.com/abiosoft/errs
github.com/fatih/color/vendor/github.com/mattn/go-isatty
golang.org/x/sys/unix
github.com/abiosoft/caddyplug/internal
github.com/fatih/color/vendor/github.com/mattn/go-colorable
github.com/fatih/color
github.com/abiosoft/caddyplug/caddyplug
finished stage: installing plugin helper ✓

starting stage: generating plugins
finished stage: generating plugins ✓

starting stage: customising plugins and telemetry
go: creating new go.mod: module caddy
go: finding github.com/mholt/caddy v1.0.1
go: github.com/mholt/caddy@v1.0.1: parsing go.mod: unexpected module path "github.com/caddyserver/caddy"
go: error loading module requirements
finished stage: customising plugins and telemetry ✓

starting stage: building caddy
go: finding github.com/go-acme/lego/providers/dns/route53 latest
go: finding github.com/go-acme/lego/providers/dns/cloudflare latest
go: finding github.com/mholt/caddy/caddy/caddymain latest
go: finding github.com/caddyserver/caddy/caddytls latest
go: finding github.com/mholt/caddy/caddy latest
go: downloading github.com/mholt/caddy v1.0.1
go: extracting github.com/mholt/caddy v1.0.1
go: finding github.com/caddyserver/caddy v1.0.1
go: finding github.com/go-acme/lego/providers/dns latest
go: finding github.com/go-acme/lego/providers latest
go: downloading github.com/caddyserver/caddy v1.0.1
go: extracting github.com/caddyserver/caddy v1.0.1
go: finding github.com/go-acme/lego v2.6.0+incompatible
go: downloading github.com/go-acme/lego v2.6.0+incompatible
go: extracting github.com/go-acme/lego v2.6.0+incompatible
go: github.com/mholt/caddy@v1.0.1: parsing go.mod: unexpected module path "github.com/caddyserver/caddy"
go: error loading module requirements
error at 'building caddy'
abiosoft commented 5 years ago

Run docker pull abiosoft/caddy:builder and try again.

philippgille commented 5 years ago

It's either still or again broken. In my case with a different, but similar error, related to import / module paths.

The image is the newest, see:

$ docker pull abiosoft/caddy:builder

builder: Pulling from abiosoft/caddy
Digest: sha256:81531392fb405b064c95f13cfb59e8340e6380fe0febc73d340ade7b43101b83
Status: Image is up to date for abiosoft/caddy:builder

Then I want to build an image with the proxy plugin:

$ docker build --build-arg plugins=proxy -t local/caddy github.com/abiosoft/caddy-docker.git

[...]
github.com/miekg/dns
github.com/go-acme/lego/challenge/dns01
github.com/go-acme/lego/challenge/resolver
github.com/go-acme/lego/lego
github.com/mholt/certmagic
github.com/caddyserver/caddy
package caddy:
proxy.go:2:10: invalid import path: ""
finished stage: customising plugins and telemetry ✓

starting stage: building caddy
go: downloading gopkg.in/natefinch/lumberjack.v2 v2.0.0
go: downloading github.com/gorilla/websocket v1.4.0
[...]
go: extracting gopkg.in/natefinch/lumberjack.v2 v2.0.0
can't load package: package caddy:
proxy.go:2:10: invalid import path: ""
error at 'building caddy'
The command '/bin/sh -c VERSION=${version} PLUGINS=${plugins} ENABLE_TELEMETRY=${enable_telemetry} /bin/sh /usr/bin/builder.sh' returned a non-zero code: 1
philippgille commented 5 years ago

Ah my bad I think. proxy is an invalid plugin name if I'm not mistaken, as it's already part of Caddy.

Building with an empty plugin list plugins="" works fine.

Maybe the error message can be improved. For exmple when building with plugins=foo, there should be an early check if foo is a valid plugin at all and then the build should exit with an appropriate error and a clear message to the user. foo.go:2:10: invalid import path: "" instead looks like some error in a Go file (well, it probably is and the file is generated during build time, but this makes it hard to understand what the real issue is).

abiosoft commented 5 years ago

@philippgille yeah, the message can be better. You can open a separate issue to address that.

ThinkChaos commented 4 years ago

I'm having the same issue but with the default plugin list.

I added some debug to builder.sh, and I believe the error is now caused by caddyplug not using the Caddy version as requested by the image.

Here's the interesting part of the log:

starting stage: generating plugins
+ tr , ' '
+ echo git,cors,realip,expires,cache,cloudflare
+ get_package git
+ true
+ '[' -f /dnsproviders/git/git.go ]
+ GO111MODULE=off GOOS=linux GOARCH=amd64 caddyplug package git
fetching missing dependencies: caddy, dnsproviders, hook.pluginloader
[...]
github.com/caddyserver/caddy
Cloning into '/root/lib/caddy/gopath/src/github.com/caddyserver/dnsproviders'...
github.com/abiosoft/caddyplug (download)
github.com/abiosoft/caddyplug/internal
github.com/abiosoft/caddyplug
# github.com/abiosoft/caddyplug
/root/lib/caddy/gopath/src/github.com/abiosoft/caddyplug/caddyplug.go:18:2: undefined: caddy.RegisterEventHook
/root/lib/caddy/gopath/src/github.com/abiosoft/caddyplug/caddyplug.go:21:10: undefined: caddy.EventHook
/root/lib/caddy/gopath/src/github.com/abiosoft/caddyplug/caddyplug.go:21:39: undefined: caddy.EventName
/root/lib/caddy/gopath/src/github.com/abiosoft/caddyplug/caddyplug.go:23:7: undefined: caddy.StartupEvent
exit status 2
+ import_package=
+ '[' -z  ]
+ echo 'Could not determine package for plugin git'
+ return 1
+ end_stage
+ '[' 1 -ne 0 ]
+ echo error at ''"'"'generating' 'plugins'"'"
error at 'generating plugins'
+ exit 1

My intuition is the undefined errors are due to caddyplug now using Caddy 2 instead of the one specified in $VERSION.

I'm willing to spend some time fixing this, but need your guidance. Do you think I'm right about the cause? How should I go about and fix this?