QQ: how to build a Docker image from external go repo?

37 views
Skip to first unread message

mskon...@gmail.com

unread,
Jul 3, 2019, 2:59:03 AM7/3/19
to bazel-go-discuss
I have my bazel project.
And I want to build Docker image from external go repo from GitHub (no bazel).

How can achieve that?
I add go_repository() to my WORKSPACE file. Do I need to add Gazelle to generate BUILD file for the repo and how?
Thanks in advanca

T H

unread,
Jul 3, 2019, 2:20:43 PM7/3/19
to bazel-go-discuss
The go_repository rule will automatically run gazelle against the source code in that repo. Bazel however won't pull down the repo until it's declared as a dependency of a target.

If you're interested in the targets that gazelle will generate the build files for, you can run

bazel query @repo_name//...

The building of docker images with bazel can be achieved using rules_docker (https://github.com/bazelbuild/rules_docker)


rules_docker provides container_pull and container_image rules. The former is a repository rule (lives in WORKSPACE) and is used to pull down base images.

container_image (lives in a BUILD.bazel) creates the image target and lets you include other targets if you wish

In this case, you could include whichever go binary gazelle has written the build file for into your image.

Reply all
Reply to author
Forward
0 new messages