Let me start by saying I'm new to Bazel. I am trying to build a Docker container from a golang project that contains local module references.
First I'm creating a local golang module:
go mod init go-example
Here is the general project structure:
.
├── BUILD.bazel
├── WORKSPACE
├── cmd
│ └── hello
│ ├── BUILD.bazel
│ └── main.go
├── go.mod
├── go.sum
└── pkg
└── echo
├── BUILD.bazel
└── echo.go
In main.go
I am importing pkg/echo
from the local module.
import (
"go-example/pkg/echo"
)
(top level BUILD.bazel)
...
# gazelle:prefix go-example
✅ Default bazel build works
$ bazel run //:gazelle
$ bazel build //cmd/hello
❌ Docker build fails. I get the following error:
(cmd/hello/BUILD.bazel)
...
go_image(
name = "docker",
srcs = ["main.go"],
importpath = "go-example/cmd/hello",
)
$ bazel build //cmd/hello:docker
...
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel[...]/__main__/cmd/hello/main.go: import of "go-example/pkg/echo"
No dependencies were provided.