Skip to content
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

Default Dockerfile build fails #9261

Closed
lud0v1c opened this issue Dec 8, 2021 · 8 comments · Fixed by #9279
Closed

Default Dockerfile build fails #9261

lud0v1c opened this issue Dec 8, 2021 · 8 comments · Fixed by #9279

Comments

@lud0v1c
Copy link

lud0v1c commented Dec 8, 2021

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

$ hugo version
hugo v0.90.0+extended linux/amd64 BuildDate=unknown

Additionally running Ubuntu 20.04 and:

$ docker -v
Docker version 20.10.11, build dea9396

Does this issue reproduce with the latest release?

Yes.

I was trying to build a container with the default Dockerfile but it fails:

$ docker build . -t "blog:latest"
Sending build context to Docker daemon  4.608kB
Step 1/18 : FROM golang:1.16-alpine AS build
 ---> 065ac3b1a78f
Step 2/18 : ARG HUGO_BUILD_TAGS
 ---> Using cache
 ---> f2a1a3223538
Step 3/18 : ARG CGO=1
 ---> Using cache
 ---> c5177e52161a
Step 4/18 : ENV CGO_ENABLED=${CGO}
 ---> Using cache
 ---> 18d59cd25815
Step 5/18 : ENV GOOS=linux
 ---> Using cache
 ---> 42cc9ac26b55
Step 6/18 : ENV GO111MODULE=on
 ---> Using cache
 ---> 0a009892b82b
Step 7/18 : WORKDIR /go/src/github.com/gohugoio/hugo
 ---> Using cache
 ---> 094dd233d0eb
Step 8/18 : COPY . /go/src/github.com/gohugoio/hugo/
 ---> Using cache
 ---> 9f35404bfc46
Step 9/18 : RUN apk update &&     apk add --no-cache gcc g++ musl-dev &&     go get github.com/magefile/mage
 ---> Using cache
 ---> 5ecf6ff3c45c
Step 10/18 : RUN mage hugo && mage install
 ---> Running in 7c2eca1ff455
Error determining list of magefiles: failed to list non-mage gofiles: exit status 1: go: go.mod file not found in current directory or any parent directory; see 'go help modules'

The command '/bin/sh -c mage hugo && mage install' returned a non-zero code: 1

I did a little research, and if in the Dockerfile I change ENV GO111MODULE=on to =auto or =off, this step no longer fails. However, more issues arise in the next step:

$ ...
 ---> 6970691a5b6c
Step 8/18 : COPY . /go/src/github.com/gohugoio/hugo/
 ---> 54fece8bafc0
Step 9/18 : RUN apk update &&     apk add --no-cache gcc g++ musl-dev &&     go get github.com/magefile/mage
 ---> Running in bfc5fb4b59f3
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
v3.15.0-77-g1679b91b90 [https://dl-cdn.alpinelinux.org/alpine/v3.15/main]
v3.15.0-81-g6a24246a6c [https://dl-cdn.alpinelinux.org/alpine/v3.15/community]
OK: 15832 distinct packages available
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/14) Installing libgcc (10.3.1_git20211027-r0)
(2/14) Installing libstdc++ (10.3.1_git20211027-r0)
(3/14) Installing binutils (2.37-r3)
(4/14) Installing libgomp (10.3.1_git20211027-r0)
(5/14) Installing libatomic (10.3.1_git20211027-r0)
(6/14) Installing libgphobos (10.3.1_git20211027-r0)
(7/14) Installing gmp (6.2.1-r0)
(8/14) Installing isl22 (0.22-r0)
(9/14) Installing mpfr4 (4.1.0-r0)
(10/14) Installing mpc1 (1.2.1-r0)
(11/14) Installing gcc (10.3.1_git20211027-r0)
(12/14) Installing musl-dev (1.2.2-r7)
(13/14) Installing libc-dev (0.7.2-r3)
(14/14) Installing g++ (10.3.1_git20211027-r0)
Executing busybox-1.34.1-r3.trigger
OK: 189 MiB in 29 packages
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/magefile/mage: exec: "git": executable file not found in $PATH
The command '/bin/sh -c apk update &&     apk add --no-cache gcc g++ musl-dev &&     go get github.com/magefile/mage' returned a non-zero code: 1

Even if I add git to the package installation, it will still fail running mage:

(17/20) Installing libcurl (7.80.0-r0)
(18/20) Installing expat (2.4.1-r0)
(19/20) Installing pcre2 (10.39-r0)
(20/20) Installing git (2.34.1-r0)
Executing busybox-1.34.1-r3.trigger
OK: 202 MiB in 35 packages
Removing intermediate container 0de74c9a2c1f
 ---> 560e82d2962a
Step 10/18 : RUN mage hugo && mage install
 ---> Running in bb488ea0761a
No .go files marked with the mage build tag in this directory.
The command '/bin/sh -c mage hugo && mage install' returned a non-zero code: 1
@lud0v1c lud0v1c changed the title Default Dockerfile fails Default Dockerfile build fails Dec 8, 2021
@bep bep added the Bug label Dec 9, 2021
@bep bep added this to the v0.91.0 milestone Dec 9, 2021
@hitzhangjie
Copy link
Contributor

I have same problem. +1

@bep bep closed this as completed in #9279 Dec 12, 2021
bep pushed a commit that referenced this issue Dec 12, 2021
Mage uses git, so we should install git before run mage.

Closes #9261
@lud0v1c
Copy link
Author

lud0v1c commented Dec 12, 2021

@bep @hitzhangjie The git install helps but the build still doesn't finish:

Sending build context to Docker daemon  3.072kB
Step 1/18 : FROM golang:1.16-alpine AS build
 ---> 065ac3b1a78f
Step 2/18 : ARG HUGO_BUILD_TAGS
 ---> Using cache
 ---> f2a1a3223538
Step 3/18 : ARG CGO=1
 ---> Using cache
 ---> c5177e52161a
Step 4/18 : ENV CGO_ENABLED=${CGO}
 ---> Using cache
 ---> 18d59cd25815
Step 5/18 : ENV GOOS=linux
 ---> Using cache
 ---> 42cc9ac26b55
Step 6/18 : ENV GO111MODULE=on
 ---> Using cache
 ---> 0a009892b82b
Step 7/18 : WORKDIR /go/src/github.com/gohugoio/hugo
 ---> Using cache
 ---> 094dd233d0eb
Step 8/18 : COPY . /go/src/github.com/gohugoio/hugo/
 ---> 9c4a7906a4b2
Step 9/18 : RUN apk update &&     apk add --no-cache gcc g++ musl-dev git &&     go get github.com/magefile/mage
 ---> Running in 0a1246dc8631
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
v3.15.0-83-gd925f25ff4 [https://dl-cdn.alpinelinux.org/alpine/v3.15/main]
v3.15.0-87-g1b1984fd63 [https://dl-cdn.alpinelinux.org/alpine/v3.15/community]
OK: 15832 distinct packages available
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/20) Installing libgcc (10.3.1_git20211027-r0)
(2/20) Installing libstdc++ (10.3.1_git20211027-r0)
(3/20) Installing binutils (2.37-r3)
(4/20) Installing libgomp (10.3.1_git20211027-r0)
(5/20) Installing libatomic (10.3.1_git20211027-r0)
(6/20) Installing libgphobos (10.3.1_git20211027-r0)
(7/20) Installing gmp (6.2.1-r0)
(8/20) Installing isl22 (0.22-r0)
(9/20) Installing mpfr4 (4.1.0-r0)
(10/20) Installing mpc1 (1.2.1-r0)
(11/20) Installing gcc (10.3.1_git20211027-r0)
(12/20) Installing musl-dev (1.2.2-r7)
(13/20) Installing libc-dev (0.7.2-r3)
(14/20) Installing g++ (10.3.1_git20211027-r0)
(15/20) Installing brotli-libs (1.0.9-r5)
(16/20) Installing nghttp2-libs (1.46.0-r0)
(17/20) Installing libcurl (7.80.0-r0)
(18/20) Installing expat (2.4.1-r0)
(19/20) Installing pcre2 (10.39-r0)
(20/20) Installing git (2.34.1-r0)
Executing busybox-1.34.1-r3.trigger
OK: 202 MiB in 35 packages
go: downloading github.com/magefile/mage v1.11.0
Removing intermediate container 0a1246dc8631
 ---> 479c121b4c21
Step 10/18 : RUN mage hugo && mage install
 ---> Running in ae89d9c18a72
Error determining list of magefiles: failed to list non-mage gofiles: exit status 1: go: go.mod file not found in current directory or any parent directory; see 'go help modules'

The command '/bin/sh -c mage hugo && mage install' returned a non-zero code: 1
Time: 0h:00m:25s 

@ZhaoUncle
Copy link

@lud0v1c don't git clone the repo?

@lud0v1c
Copy link
Author

lud0v1c commented Dec 23, 2021

@ZhaoUncle no, you can see it in the output. git is just installed. I think it's related with the WORKDIR set in the beginning, but running the Dockerfile as-is will just fail.

@lud0v1c
Copy link
Author

lud0v1c commented Dec 27, 2021

I don't get why this issue was closed, the build is still failing @bep. Anyone can try and build it to see the outcome.

@ZhaoUncle
Copy link

You need to clone the code to your local to execute docker build instead of copying dockerfile directly, otherwise this error will appear, please carefully read the instructions and dockerfile commands.

@lud0v1c
Copy link
Author

lud0v1c commented Jan 3, 2022

@ZhaoUncle 🤦 I was running this in a separate environment from the repository.. Sorry about that. Yes things run fine now, it was just the git install missing!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants