Building in Docker: `go install -v ./pkg/cmd/grafana-server` fails (cannot find packages) -- v5.2-beta1

I’m getting the following error when trying to run go run build.go setup inside my container – however, I don’t get the error when I run it outside the container.

go install -v ./pkg/cmd/grafana-server
pkg/login/ldap_settings.go:7:2: cannot find package “GitHub - BurntSushi/toml: TOML parser for Golang with reflection.” in any of:
/usr/local/go/src/github.com/BurntSushi/toml (from $GOROOT)
/go/src/github.com/BurntSushi/toml (from $GOPATH)
pkg/services/notifications/codes.go:9:2: cannot find package “GitHub - unknwon/com: This is an open source project for commonly used functions for the Go programming language.” in any of:
/usr/local/go/src/github.com/Unknwon/com (from $GOROOT)
/go/src/github.com/Unknwon/com (from $GOPATH)

[…]

I’m building 5.2-beta. I’ll post my Dockerfile below if it helps:

FROM golang:latest AS build

ENV SRC_DIR=/go/src/github.com/grafana/grafana/
ENV GIT_SSL_NO_VERIFY=1

COPY . $SRC_DIR
WORKDIR $SRC_DIR

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

# Basic dependencies for building NPM projects
RUN \
  apt-get -y install --reinstall ca-certificates && \
  curl -sL https://deb.nodesource.com/setup_9.x | bash - && \
  apt-get -y install nodejs build-essential && \
  npm install -g npm && \
  npm config set strict-ssl=false

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

# Building of Grafana
RUN \
  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/github.com/grafana/grafana/
WORKDIR $SRC_DIR

COPY --from=build $SRC_DIR/conf ./conf
COPY --from=build $SRC_DIR/public ./public
COPY --from=build $SRC_DIR/data/plugins ./data/plugins
COPY --from=build $SRC_DIR/bin/grafana-server ./bin/grafana-server

EXPOSE 3001

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

slight bump on this, I’m unsure what may have changed that would cause these (previous versions of grafana built fine using the same Dockerfile). If I’m doing something woefully wrong, please let me know.

Looks like this is due to a bug in the .dockerignore file that was recently added (hence why the issue only popped up with the upgrade to v5.2-beta1); we likely want to preserve the vendor path into the container.

Pull request submitted to address the issue: https://github.com/grafana/grafana/pull/12306