Created
October 15, 2017 16:59
-
-
Save excavador/4cfc1fd7e10e55f451fa9b4f05964d39 to your computer and use it in GitHub Desktop.
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//container:container.bzl", "repositories", "container_pull", "container_image") | |
DEFAULT_VERSION = "1.1.54292" | |
def _pull_name(kind, version): | |
return "external_clickhouse_{}_{}".format(kind, version) | |
def _pull_label(kind, version): | |
return "@{}//image".format(_pull_name(kind, version)) | |
def _image_name(kind, version): | |
return "clickhouse_{}_{}".format(kind, version) | |
def _image_label(kind, version): | |
return "//:{}.tar".format(_image_name("server", version)) | |
def clickhouse_repositories(version=DEFAULT_VERSION): | |
repositories() | |
container_pull( | |
name = _pull_name("server", version), | |
registry = "index.docker.io", | |
repository = "yandex/clickhouse-server", | |
tag = version, | |
) | |
container_pull( | |
name = _pull_name("client", version), | |
registry = "index.docker.io", | |
repository = "yandex/clickhouse-client", | |
tag = version, | |
) | |
COMMAND = """#!/bin/bash | |
cat {server_source} | docker load | awk '{{print $3}}' > {server_result} | |
cat {client_source} | docker load | awk '{{print $3}}' > {client_result} | |
""" | |
def _clickhouse_export_impl(ctx): | |
server_source = ctx.attr.server.files.to_list()[0] | |
client_source = ctx.attr.client.files.to_list()[0] | |
server_result = ctx.outputs.server | |
client_result = ctx.outputs.client | |
command = COMMAND.format( | |
server_source = server_source.path, | |
client_source = client_source.path, | |
server_result = server_result.path, | |
client_result = client_result.path, | |
) | |
ctx.actions.run_shell( | |
inputs=[server_source, client_source], | |
outputs=[server_result, client_result], | |
progress_message="Exporting clickhouse images of %s" % ctx.attr.version, | |
command=command | |
) | |
return [DefaultInfo(runfiles=ctx.runfiles([server_source, client_source]))] | |
_clickhouse_export = rule( | |
implementation = _clickhouse_export_impl, | |
attrs = { | |
"server": attr.label(mandatory=True, allow_single_file=True), | |
"client": attr.label(mandatory=True, allow_single_file=True), | |
"version": attr.string(mandatory=True), | |
}, | |
outputs = { | |
"server": "%{name}-server", | |
"client": "%{name}-client", | |
}, | |
) | |
def clickhouse_export(name, version=DEFAULT_VERSION): | |
container_image( | |
name = _image_name("server", version), | |
base = _pull_label("server", version), | |
) | |
container_image( | |
name = _image_name("client", version), | |
base = _pull_label("client", version), | |
) | |
_clickhouse_export( | |
name = name, | |
server = _image_name("server", version) + ".tar", | |
client = _image_name("client", version) + ".tar", | |
version = version, | |
) |
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
➜ bazel build //:clickhouse-image-reference | |
INFO: Found 1 target... | |
Target //:clickhouse-image-reference up-to-date: | |
bazel-bin/clickhouse-image-reference-server | |
bazel-bin/clickhouse-image-reference-client | |
INFO: Elapsed time: 15.740s, Critical Path: 12.86s | |
oleg@macbook-oleg:~/pp/atrevido (git: master) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
➜ cat bazel-bin/clickhouse-image-reference-server | |
bazel:clickhouse_server_1.1.54292 | |
oleg@macbook-oleg:~/pp/atrevido (git: master) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
➜ cat bazel-bin/clickhouse-image-reference-client | |
bazel:clickhouse_client_1.1.54292 | |
oleg@macbook-oleg:~/pp/atrevido (git: master) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── | |
➜ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment