Skip to content

Commit

Permalink
Enable using Darwin binary. (bazelbuild#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
xingao267 authored and nlopezgi committed Jul 10, 2019
1 parent 967ae93 commit de975e8
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ platforms:
- "--incompatible_disallow_legacy_javainfo=false"
macos:
build_targets:
- "//tests/container:test_digest_output1"
- "//tests/container/..."
build_flags:
- "--action_env=PATH"
# For tests/container:set_env_make_vars_test
- "--define=ENV_KEY=my_key"
- "--define=ENV_VALUE=my_value"
# TODO(xingao): Remove after https://github.com/bazelbuild/rules_scala/issues/644 is addressed.
- "--incompatible_disallow_legacy_javainfo=false"
test_targets:
Expand Down
17 changes: 13 additions & 4 deletions container/new_load.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Rule for loading an image from 'docker save' tarball or the current
"""Rule for loading an image from 'docker save' tarball or the current
container_pull tarball format into OCI intermediate layout.
This extracts the tarball amd creates a filegroup of the untarred objects in OCI layout.
Expand All @@ -37,8 +37,12 @@ container_import(
exports_files(glob(["**"]))""")

loader = repository_ctx.attr._loader_linux
if repository_ctx.os.name.lower().startswith("mac os"):
loader = repository_ctx.attr._loader_darwin

result = repository_ctx.execute([
repository_ctx.path(repository_ctx.attr._loader),
repository_ctx.path(loader),
"-directory",
repository_ctx.path(""),
"-tarball",
Expand All @@ -54,9 +58,14 @@ new_container_load = repository_rule(
allow_single_file = True,
mandatory = True,
),
"_loader": attr.label(
"_loader_darwin": attr.label(
executable = True,
default = Label("@loader_darwin//file:downloaded"),
cfg = "host",
),
"_loader_linux": attr.label(
executable = True,
default = Label("@loader//file:downloaded"),
default = Label("@loader_linux//file:downloaded"),
cfg = "host",
),
},
Expand Down
15 changes: 12 additions & 3 deletions container/new_pull.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ _container_pull_attrs = {
doc = "(optional) The tag of the image, default to 'latest' " +
"if this and 'digest' remain unspecified.",
),
"_puller": attr.label(
"_puller_darwin": attr.label(
executable = True,
default = Label("@go_puller//file:downloaded"),
default = Label("@go_puller_darwin//file:downloaded"),
cfg = "host",
),
"_puller_linux": attr.label(
executable = True,
default = Label("@go_puller_linux//file:downloaded"),
cfg = "host",
),
}
Expand Down Expand Up @@ -111,8 +116,12 @@ container_import(
exports_files(glob(["**"]))""")

puller = repository_ctx.attr._puller_linux
if repository_ctx.os.name.lower().startswith("mac os"):
puller = repository_ctx.attr._puller_darwin

args = [
repository_ctx.path(repository_ctx.attr._puller),
repository_ctx.path(puller),
"-directory",
repository_ctx.path(""),
"-format",
Expand Down
45 changes: 31 additions & 14 deletions repositories/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ load(

# The release of the github.com/google/containerregistry to consume.
CONTAINERREGISTRY_RELEASE = "v0.0.36"
RULES_DOCKER_GO_BINARY_RELEASE = "0ff1a8a2315b40cd41bba5c5b28d98a5c31d770d"

_local_tool_build_template = """
sh_binary(
Expand Down Expand Up @@ -56,17 +57,41 @@ def repositories():
"""Download dependencies of container rules."""
excludes = native.existing_rules().keys()

if "go_puller" not in excludes:
# Go puller binary.
# Go binaries.
if "go_puller_linux" not in excludes:
http_file(
name = "go_puller",
name = "go_puller_linux",
executable = True,
sha256 = "c845a96d91c10f1aea328f53c665825190512f84492bcb3a30d596f2090faf82",
urls = [("https://storage.googleapis.com/rules_docker/06d9bf4e7205a46ec9b72d2dfb28271baf8968af/puller-linux-amd64")],
sha256 = "3ba84a62695f8d4fb08d6181a85640c80ab317ed3c363db670a7a2f237ab044c",
urls = [("https://storage.googleapis.com/rules_docker/" + RULES_DOCKER_GO_BINARY_RELEASE + "/puller-linux-amd64")],
)

if "go_puller_darwin" not in excludes:
http_file(
name = "go_puller_darwin",
executable = True,
sha256 = "236cbc4788c8c287ff80b33dd5b1bd9a64ee8d8cf09413f251672340d37532eb",
urls = [("https://storage.googleapis.com/rules_docker/" + RULES_DOCKER_GO_BINARY_RELEASE + "/puller-darwin-amd64")],
)

if "loader_linux" not in excludes:
http_file(
name = "loader_linux",
executable = True,
sha256 = "720aabb9ccc67a11e657dc20534281528d3ab6a4fe963d4127380a42e6ffadd2",
urls = [("https://storage.googleapis.com/rules_docker/" + RULES_DOCKER_GO_BINARY_RELEASE + "/loader-linux-amd64")],
)

if "loader_darwin" not in excludes:
http_file(
name = "loader_darwin",
executable = True,
sha256 = "1f948fae0f32ee463e857c6dc431a7be5fe3ea21e03fbac0530a2478ec07fe2c",
urls = [("https://storage.googleapis.com/rules_docker/" + RULES_DOCKER_GO_BINARY_RELEASE + "/loader-darwin-amd64")],
)

# Legacy Python binaries.
if "puller" not in excludes:
# Python puller binary.
http_file(
name = "puller",
executable = True,
Expand All @@ -84,14 +109,6 @@ def repositories():
CONTAINERREGISTRY_RELEASE + "/importer.par")],
)

if "loader" not in excludes:
http_file(
name = "loader",
executable = True,
sha256 = "5903d2d278ebfde2466a736593defb25b40b4eccfc8d0949948a2d58de57d784",
urls = [("https://storage.googleapis.com/rules_docker/432706d99825d271ead68f9fb9b66a83c1f00cb9/loader-linux-amd64")],
)

if "containerregistry" not in excludes:
http_archive(
name = "containerregistry",
Expand Down

0 comments on commit de975e8

Please sign in to comment.