Last active
October 28, 2021 06:09
-
-
Save imjasonh/634d604350000813077c8f5a8ce9481f to your computer and use it in GitHub Desktop.
Experiment to build a docker builder image that includes only static docker binaries, using Bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load( | |
"@io_bazel_rules_docker//docker:docker.bzl", | |
"docker_build", | |
) | |
docker_build( | |
name = "target", | |
base = "@base_image//image:image.tar", | |
directory = "/bin", | |
entrypoint = ["/bin/docker"], | |
files = ["@docker_static//:docker_static"], | |
mode = "0777", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package(default_visibility = ["//visibility:public"]) | |
filegroup( | |
name = "docker_static", | |
srcs = ["docker"], | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
- name: 'gcr.io/cloud-builders/bazel' | |
args: ['run', '//src:target', '--verbose_failures'] | |
# Retag to desired image name. | |
- name: 'gcr.io/cloud-builders/docker' | |
args: ['tag', 'bazel:target', 'gcr.io/$PROJECT_ID/docker-via-bazel'] | |
# Sanity check. | |
- name: 'gcr.io/$PROJECT_ID/docker-via-bazel' | |
args: ['run', 'hello-world'] | |
images: | |
- 'gcr.io/$PROJECT_ID/docker-via-bazel' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
workspace(name = "bazel_docker") | |
git_repository( | |
name = "io_bazel_rules_docker", | |
remote = "https://github.com/bazelbuild/rules_docker.git", | |
tag = "v0.3.0", | |
) | |
load( | |
"@io_bazel_rules_docker//docker:docker.bzl", | |
"docker_pull", | |
"docker_repositories", | |
) | |
# Consumers shouldn't need to do this themselves once WORKSPACE is | |
# instantiated recursively. | |
docker_repositories() | |
docker_pull( | |
name = "base_image", | |
registry = "launcher.gcr.io", | |
repository = "google/ubuntu16_04", | |
tag = "latest", # TODO: use digest. | |
) | |
new_http_archive( | |
name = "docker_static", | |
build_file = "BUILD.docker", | |
# TODO: specify SHA256. | |
strip_prefix = "docker", | |
type = "tgz", | |
urls = ["https://download.docker.com/linux/static/stable/x86_64/docker-17.12.0-ce.tgz"], | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment