gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.4k stars 7.49k forks source link

Hugo docker cannot find Go binary in PATH #12915

Closed Int-Circuit closed 6 days ago

Int-Circuit commented 1 week ago

What version of Hugo are you using (hugo version)?

$ hugo version
0.135 (docker)

Does this issue reproduce with the latest release?

Yes

When using hugo to load the modules from my go.mod file, my CI on GitLab complains that the image hasn't "go" in it's PATH. See log

log.txt

bhavin192 commented 6 days ago

I can see same behavior when building my site which uses Hugo modules. https://gitlab.com/emacs-apac/emacs-apac.gitlab.io/

$ podman run -v $(pwd):/site:z --rm -it --entrypoint "hugo" ghcr.io/gohugoio/hugo:v0.135.0
Total in 2 ms
Error: failed to load modules: failed to download modules: binary with name "go" not found in PATH

I was going through the Dockerfile and saw that we don't install Go in the final stage so this error is expected. https://github.com/gohugoio/hugo/blob/039845804fd545de18a3c4f17f8f7b3ad3bf615b/Dockerfile#L29-L45

I'm assuming Hugo modules are commonly used now a days, so should we include Go installation in the final stage?

Installing Go in alpine image

I tried this with following Dockerfile:

FROM ghcr.io/gohugoio/hugo:v0.135.0
RUN apk add --no-cache go

Impact is the image size, it is increased by ~300MB

$ podman images
REPOSITORY                                 TAG               IMAGE ID      CREATED         SIZE
docker.io/bhavin192/hugo                   v0.135.0-go       63f69e93cf2a  48 seconds ago  453 MB
ghcr.io/gohugoio/hugo                      v0.135.0          dc91d5ca1b66  2 weeks ago     138 MB

Use same image as the build stage?

Other option is to use the same base image we use for the build stage which seems to be smaller than installing Go via apk. But I haven't tried doing that, so don't know what will be size of the final image.

bep commented 6 days ago

Fixed in #12921 ....