I have a bazel test that docker build
and docker push
to google artifact registry a docker image. It fails, because "cannot create private file:
/home/bill/.config/gcloud/credentials.db".
I can turn off bazel sandboxing by either using local=True
in bazel rule or avoid docker push
(i.e. test with local image). Is there some better work-around?
2
Answers
You can use Bazel’s
--sandbox_writable_path
flag to explicitly specify the path. As mentioned in this documentSeems the flag
--sandbox_writable_path
applies to the entire build process, Not possible to specify on a per test rule basis.I recommend not doing a
docker push
from within abazel build
orbazel test
rule, because it has side-effects (namely, an image may become present on a remote server). Generally speaking, this can cause issues:--runs_per_test=10
) with side effects can cause a race on the external system; the state on the external system may be indeterminate, or the test target may spuriously fail if the external system errors when races occurCommands with side-effects are best put inside a script/binary and triggered via
bazel run
instead. This does complicate end-to-end-type flows, that may need to execute more than one bazel step to complete; however, it keeps a clear delineation between bazel invocations that are not expected to have side effects vs. those that might, which will line up better with user and tool expectations.