How to properly run a release build in a golang container?

I have a Dockerfile which is FROM golang:latest. When trying to execute a release build, I end up with the following error:

Running "compress:release" (compress) task
>> Compressed 1375 files.

mkdir -p /tmp/grafana-linux-pack668511386/usr/share/grafana
mkdir -p /tmp/grafana-linux-pack668511386/etc/grafana
mkdir -p /tmp/grafana-linux-pack668511386/etc/init.d
mkdir -p /tmp/grafana-linux-pack668511386/etc/default
mkdir -p /tmp/grafana-linux-pack668511386/usr/lib/systemd/system
mkdir -p /tmp/grafana-linux-pack668511386/usr/sbin
cp -p /go/src/ /tmp/grafana-linux-pack668511386/usr/sbin/grafana-server
cp: cannot stat '/go/src/': No such file or directory
exit status 1
exit status 1

I’m running the build via: go run build.go build pkg-deb (because using just package always resulted in a Need executable 'rpmbuild' to convert dir to rpm {:level=>:error})

What am I doing wrong?


What is your goal? Do you want to produce debian packages, or a docker image or something else?

To build and package Grafana you need a bunch of different tools, Golang is only one of them. What you need for building is documented here: For packaging you also need to install fpm.

One option would be to use our build container grafana/build-container which should contain everything you need and then some (it also supports multiplatform builds). You could also look at the official build pipeline if you really want to know how everything fits together:

Thanks for the response. I have a docker container being built already, but I’d like to transition it to use a release build (hopefully to improve on some performance issues we’re seeing in the UI). Below is my Dockerfile for reference:

FROM golang:latest AS build

ENV SRC_DIR=/go/src/


# Basic dependencies for building
apt-get -y update && \
apt-get -y install git && \
apt-get -y install ruby-full && \
gem install fpm

# Basic dependencies for building NPM projects
apt-get -y install --reinstall ca-certificates && \
curl -sL | bash - && \
apt-get -y install nodejs build-essential libfontconfig curl && \
npm install -g npm && \
npm config set strict-ssl=false

# Basic dependencies for building Grafana NPM project
npm install -g yarn && \
yarn config set "strict-ssl" false

RUN chmod go-w /go/bin

# Building of Grafana
yarn install --pure-lockfile && \
npm run build

go run build.go setup && \
go run build.go build

# Create final stage containing only required artifacts
FROM golang:latest
ENV SRC_DIR=/go/src/

COPY --from=build $SRC_DIR/conf ./conf
COPY --from=build $SRC_DIR/public ./public
COPY --from=build $SRC_DIR/data ./data
COPY --from=build $SRC_DIR/tools ./tools
COPY --from=build $SRC_DIR/bin/linux-amd64/grafana-server ./bin/grafana-server

CMD ["./bin/grafana-server"]

So basically, I just want to change the line go run build.go build to go run build.go build package – this works just fine on my laptop (MacOS), but fails with the error above when building my container. I’m not terribly sure if it’s a path issue, or a platform issue.

Does the package command place a optimized build in the same directory as the standard build? Does it overwrite the standard build?

As for the container image, it’s the official Docker golang container. The docs for this container specify:

I feel a bit silly, should have caught on to this right away: the problem is that you’re missing the rpmbuild binary (apt install rpm to get it) which is used to package the rpm package.

go run build.go package will place packages in the dist folder, a tar-ball, deb and rpm.