Error building Docker image in Go install

  • What Grafana version and what operating system are you using?

  • Grafana 9.4.7 , Mac OS Ventura (Mac M1)

  • What are you trying to achieve?
    Build a Docker image of Grafana

  • What happened?
    Executor failed running – issue with go-builder

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

Logs:

#25 0.742 go: downloading github.com/bwplotka/bingo v0.8.0                                                                                                                                                                                                                    
#25 1.094 go: downloading github.com/efficientgo/core v1.0.0-rc.0                                                                                                                                                                                                             
#25 1.194 go: downloading golang.org/x/mod v0.5.1                                                                                                                                                                                                                             
#25 1.298 go: downloading mvdan.cc/sh/v3 v3.4.3                                                                                                                                                                                                                               
#25 1.344 go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1                                                                                                                                                                                             
#25 1.477 go: downloading golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f                                                                                                                                                                                                 
#25 1.477 go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c                                                                                                                                                                                                
#25 1.477 go: downloading golang.org/x/term v0.0.0-20210927222741-03fcf44c2211                                                                                                                                                                                                
#25 6.565 getting target github.com/unknwon/bra@v0.0.0-20200517080246-1e3013ecaff8 (module github.com/unknwon/bra )                                                                                                                                                           
#25 7.386 exec 'go list -modfile=/tmp/grafana/.bingo/bra.tmp.mod -mod=mod -f={{.Name}} github.com/unknwon/bra'                                                                                                                                                                
#25 8.348 exec 'go get -modfile=/tmp/grafana/.bingo/bra.tmp.mod -d github.com/unknwon/bra@v0.0.0-20200517080246-1e3013ecaff8'
#25 8.352 exec 'go env GOBIN'
#25 8.356 exec 'go env GOPATH'
#25 12.85 exec 'go build -modfile=/tmp/grafana/.bingo/bra.tmp.mod -o=/go/bin/bra-v0.0.0-20200517080246-1e3013ecaff8 github.com/unknwon/bra'
#25 12.85 getting target cuelang.org/go/cmd/cue@v0.5.0 (module cuelang.org/go )
#25 14.54 exec 'go list -modfile=/tmp/grafana/.bingo/cue.tmp.mod -mod=mod -f={{.Name}} cuelang.org/go/cmd/cue'
#25 16.64 exec 'go get -modfile=/tmp/grafana/.bingo/cue.tmp.mod -d cuelang.org/go/cmd/cue@v0.5.0'
#25 16.64 exec 'go env GOBIN'
#25 16.65 exec 'go env GOPATH'
#25 23.96 exec 'go build -modfile=/tmp/grafana/.bingo/cue.tmp.mod -o=/go/bin/cue-v0.5.0 cuelang.org/go/cmd/cue'
#25 23.96 getting target github.com/drone/drone-cli/drone@v1.5.0 (module github.com/drone/drone-cli )
#25 29.88 exec 'go list -modfile=/tmp/grafana/.bingo/drone.tmp.mod -mod=mod -f={{.Name}} github.com/drone/drone-cli/drone'
#25 33.27 exec 'go get -modfile=/tmp/grafana/.bingo/drone.tmp.mod -d github.com/drone/drone-cli/drone@v1.5.0'
#25 33.27 exec 'go env GOBIN'
#25 33.28 exec 'go env GOPATH'
#25 42.90 exec 'go build -modfile=/tmp/grafana/.bingo/drone.tmp.mod -o=/go/bin/drone-v1.5.0 github.com/drone/drone-cli/drone'
#25 42.90 getting target github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 (module github.com/golangci/golangci-lint )
#25 55.64 exec 'go list -modfile=/tmp/grafana/.bingo/golangci-lint.tmp.mod -mod=mod -f={{.Name}} github.com/golangci/golangci-lint/cmd/golangci-lint'
#25 83.61 exec 'go get -modfile=/tmp/grafana/.bingo/golangci-lint.tmp.mod -d github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2'
#25 83.62 exec 'go env GOBIN'
#25 83.63 exec 'go env GOPATH'
#25 113.4 Error: get command failed
#25 113.4 > main.main	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/main.go:223
#25 113.4 > runtime.main	/usr/local/go/src/runtime/proc.go:250
#25 113.4 > runtime.goexit	/usr/local/go/src/runtime/asm_arm64.s:1172
#25 113.4 get
#25 113.4 > main.main.func2	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/main.go:147
#25 113.4 > main.main.func5	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/main.go:215
#25 113.4 > github.com/oklog/run.(*Group).Run.func1	/go/pkg/mod/github.com/oklog/run@v1.1.0/group.go:38
#25 113.4 > runtime.goexit	/usr/local/go/src/runtime/asm_arm64.s:1172
#25 113.4 0: getting github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
#25 113.4 > main.getAll	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/get.go:119
#25 113.4 > main.get	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/get.go:154
#25 113.4 > main.main.func2	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/main.go:146
#25 113.4 > main.main.func5	/go/pkg/mod/github.com/bwplotka/bingo@v0.8.0/main.go:215
#25 113.4 > github.com/oklog/run.(*Group).Run.func1	/go/pkg/mod/github.com/oklog/run@v1.1.0/group.go:38
#25 113.4 > runtime.goexit	/usr/local/go/src/runtime/asm_arm64.s:1172
#25 113.4 install: build versioned: # github.com/golangci/golangci-lint/cmd/golangci-lint
#25 113.4 /usr/local/go/pkg/tool/linux_arm64/link: running gcc failed: exit status 1
#25 113.4 collect2: fatal error: cannot find 'ld'
#25 113.4 compilation terminated.
#25 113.4 
#25 113.4 : error while running command 'go build -modfile=/tmp/grafana/.bingo/golangci-lint.tmp.mod -o=/go/bin/golangci-lint-v1.51.2 github.com/golangci/golangci-lint/cmd/golangci-lint'; err: exit status 1
------
executor failed running [/bin/sh -c if [[ "$BINGO" = "true" ]]; then       go install github.com/bwplotka/bingo@latest &&       bingo get -v;     fi]: exit code: 1

I have set-up a local repository by cloning the git repository and am using

docker build -t grafana-custom .

I am not too well-versed in Docker, so any help would be great. Thanks!

Hi :slightly_smiling_face:

This might be due to Docker making some assumptions based on your host platform what kind of platform you want to build. Sadly, that sometimes leads to some annoying issues and so we’re currently investigating easier ways to build Docker images (or binaries in general) for whatever platform you might want to use.

In your case, if you can live with a linux/amd64 image (as opposed to the linux/arm64 image your Docker setup wants to create by default), then you can run following command when using the main branch:

make build-docker-full

This will call docker buildx build under the hood with some additional flags :slightly_smiling_face:

For older versions (e.g. using the v9.4.x branch) you might need to do something like this:

DOCKER_BUILDKIT=1 docker build --platform linux/amd64 grafana-custom .

Is there any particular reason why you want to build your own image instead of using the image listed on Download Grafana | Grafana Labs ? :slightly_smiling_face:

Checking the logs, it seems using

make build-docker-full

has resolved my previous issue (in addition to installing rosetta2).

However, I am not getting the following build error:

 => ERROR [js-builder 12/12] RUN yarn build                                                                                                                                                      500.7s< => [go-builder  7/19] RUN if [[ "false" = "true" ]]; then       go install github.com/bwplotka/bingo@latest &&       bingo get -v;     fi                                                         1.3sc => [go-builder  8/19] COPY embed.go Makefile build.go package.json ./                                                                                                                             0.0ss => [go-builder  9/19] COPY cue.mod cue.mod                                                                                                                                                        0.0s
 => [go-builder 10/19] COPY kinds kinds                                                                                                                                                            0.0s< => [go-builder 11/19] COPY local local                                                                                                                                                            0.0sc => [go-builder 12/19] COPY packages/grafana-schema packages/grafana-schema                                                                                                                        0.0s
 => [go-builder 13/19] COPY public/app/plugins public/app/plugins                                                                                                                                  0.4s
 => [go-builder 14/19] COPY public/api-merged.json public/api-merged.json                                                                                                                          0.0s
 => [go-builder 15/19] COPY pkg pkg                                                                                                                                                                0.8s
 => [go-builder 16/19] COPY scripts scripts                                                                                                                                                        0.1s
 => [go-builder 17/19] COPY conf conf                                                                                                                                                              0.0s
 => [go-builder 18/19] COPY .github .github                                                                                                                                                        0.0s
 => CANCELED [go-builder 19/19] RUN make build-go GO_BUILD_TAGS= WIRE_TAGS=oss        

#0 330.6 <s> [webpack.Progress] 86% sealing record chunks RecordIdsPlugin
#0 330.6 <s> [webpack.Progress] 86% sealing record chunks
#0 331.2 <s> [webpack.Progress] 87% sealing module hashing
#0 331.2 <s> [webpack.Progress] 87% sealing module hashing
#0 335.2 <s> [webpack.Progress] 87% sealing code generation
#0 335.2 <s> [webpack.Progress] 87% sealing code generation
#0 397.9 <s> [webpack.Progress] 88% sealing runtime requirements
#0 397.9 <s> [webpack.Progress] 88% sealing runtime requirements
#0 399.0 <s> [webpack.Progress] 89% sealing hashing
#0 399.1 <s> [webpack.Progress] 89% sealing hashing
#0 400.7 <s> [webpack.Progress] 89% sealing after hashing
#0 400.7 <s> [webpack.Progress] 89% sealing after hashing
#0 400.8 <s> [webpack.Progress] 90% sealing record hash
#0 400.8 <s> [webpack.Progress] 90% sealing record hash
#0 400.8 <s> [webpack.Progress] 91% sealing module assets processing
#0 400.8 <s> [webpack.Progress] 91% sealing module assets processing
#0 400.8 <s> [webpack.Progress] 91% sealing chunk assets processing
#0 400.8 <s> [webpack.Progress] 91% sealing chunk assets processing
#0 403.3 <s> [webpack.Progress] 92% sealing asset processing
#0 403.3 <s> [webpack.Progress] 92% sealing asset processing copy-webpack-plugin
#0 406.3 <s> [webpack.Progress] 92% sealing asset processing PersistentChildCompilerSingletonPlugin
#0 406.3 <s> [webpack.Progress] 92% sealing asset processing esbuild-minify
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:30
--------------------
  28 |     
  29 |     ENV NODE_ENV production
  30 | >>> RUN yarn build
  31 |     
  32 |     FROM ${GO_IMAGE} as go-builder
--------------------
ERROR: failed to solve: process "/bin/sh -c yarn build" did not complete successfully: exit code: 129
make: *** [build-docker-full] Error 1

Following this issue, it seems to be a memory issue. I will reconfigure Docker and update accordingly.

Yes, I had the same issue once and raising the memory from 8GB to 12GB helped. It’s unfortunate that the default settings of buildkit seem to imply that runs steps as parallel as possible which is not ideal with a webpack build being one of them :sweat_smile:

1 Like

It is unfortunate, but glad to have figured it out :slight_smile:. Under Docker Desktop settings, I ended up increasing the RAM to 8 GB and now everything is working in order – thank you for your help! For reference, I am trying to build a custom Grafana image that is being hosted on AWS, but that wasn’t working so I decided to start with the official Grafana repo (I had mentioned it in my now deleted post).

Also, I had slightly edited the tags used in

make build-docker-full

to include --output type=docker, i.e.

docker buildx build \
    --output type=docker \
     --platform linux/amd64 \
    --build-arg BINGO=false \
    --build-arg GO_BUILD_TAGS= \
    --build-arg WIRE_TAGS="oss" \
    --tag grafana-custom .

for it to show up in my Docker Desktop. Thanks again for your help!