Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
moving package managers to rules-docker repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Lopez committed Jul 11, 2019
1 parent 88c5cd8 commit 92fff1a
Show file tree
Hide file tree
Showing 37 changed files with 256 additions and 1,457 deletions.
17 changes: 17 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

build --host_force_python=PY2
test --host_force_python=PY2
run --host_force_python=PY2
56 changes: 11 additions & 45 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,49 +1,15 @@
load(
"@bazel_tools//tools/build_rules:test_rules.bzl",
"file_test",
"rule_test",
)
load("//package_managers:download_pkgs.bzl", "download_pkgs")
# Copyright 2017 Google Inc. All rights reserved.

package(default_visibility = ["//visibility:public"])

download_pkgs(
name = "test_download_pkgs_at_root",
image_tar = "//ubuntu:ubuntu_16_0_4_vanilla.tar",
packages = [
"curl",
"netbase",
],
)

rule_test(
name = "test_download_pkgs_at_root_rule",
generates = [
"test_download_pkgs_at_root",
],
rule = "test_download_pkgs_at_root",
)
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

file_test(
name = "test_download_pkgs_at_root_docker_run",
file = ":test_download_pkgs_at_root",
regexp = "image_id.* ubuntu/ubuntu_16_0_4_vanilla.tar)$",
)
# http://www.apache.org/licenses/LICENSE-2.0

file_test(
name = "test_download_pkgs_at_root_docker_cp",
file = ":test_download_pkgs_at_root",
regexp = ".*docker cp .*:test_download_pkgs_at_root_packages.tar test_download_pkgs_at_root.tar.*",
)
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

file_test(
name = "test_download_pkgs_at_root_metadata_csv",
file = ":test_download_pkgs_at_root_metadata.csv",
regexp = "curl",
)

sh_test(
name = "download_pkgs_at_root_run_test",
srcs = [":download_pkgs_at_root_run_test.sh"],
data = [":test_download_pkgs_at_root.tar"],
)
package(default_visibility = ["//visibility:public"])
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ test:
cd centos7 && bazel test --test_output=errors :image-test && cd ..

complex-test:
tests/package_managers/test_complex_packages.sh
tests/package_managers/test_bootstrap_image_macro.sh
19 changes: 7 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,9 @@ git_repository(
# Docker rules.
http_archive(
name = "io_bazel_rules_docker",
sha256 = "1a035f4e9c21e48668e09b327f89bd8197feb42b82d2b6904913c655f27a845a",
strip_prefix = "rules_docker-bb6d6606a6be348115af3552662799fd6d851a88",
urls = ["https://github.com/bazelbuild/rules_docker/archive/bb6d6606a6be348115af3552662799fd6d851a88.tar.gz"],
)

# Register the docker toolchain type
register_toolchains(
# Register the default docker toolchain that expects the 'docker'
# executable to be in the PATH
"@io_bazel_rules_docker//toolchains/docker:default_linux_toolchain",
"@io_bazel_rules_docker//toolchains/docker:default_windows_toolchain",
"@io_bazel_rules_docker//toolchains/docker:default_osx_toolchain",
sha256 = "b16afde01b99f8b9a067b98903a5fa1879307f9344ccdbbc4aa796ae657e910f",
strip_prefix = "rules_docker-4ea9e6708ec5ac29dc18f991921e2c064969159a",
urls = ["https://github.com/bazelbuild/rules_docker/archive/4ea9e6708ec5ac29dc18f991921e2c064969159a.tar.gz"],
)

load(
Expand All @@ -54,6 +45,10 @@ load(

container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
Expand Down
17 changes: 17 additions & 0 deletions centos7/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

build --host_force_python=PY2
test --host_force_python=PY2
run --host_force_python=PY2
2 changes: 1 addition & 1 deletion centos7/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@base_images_docker//util:run.bzl", "container_run_and_extract")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")
load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_extract")

licenses(["notice"]) # Apache 2.0

Expand Down
17 changes: 7 additions & 10 deletions centos7/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_rules_docker",
sha256 = "1a035f4e9c21e48668e09b327f89bd8197feb42b82d2b6904913c655f27a845a",
strip_prefix = "rules_docker-bb6d6606a6be348115af3552662799fd6d851a88",
urls = ["https://github.com/bazelbuild/rules_docker/archive/bb6d6606a6be348115af3552662799fd6d851a88.tar.gz"],
)

http_archive(
name = "base_images_docker",
sha256 = "16da54ef0734a0658d7006bc8bf6b9be26b963edec497b13974a1bfb46cefc41",
strip_prefix = "base-images-docker-7fdd2bb83a6957fe66712bd5238087b257b04378",
urls = ["https://github.com/GoogleContainerTools/base-images-docker/archive/7fdd2bb83a6957fe66712bd5238087b257b04378.tar.gz"],
sha256 = "b16afde01b99f8b9a067b98903a5fa1879307f9344ccdbbc4aa796ae657e910f",
strip_prefix = "rules_docker-4ea9e6708ec5ac29dc18f991921e2c064969159a",
urls = ["https://github.com/bazelbuild/rules_docker/archive/4ea9e6708ec5ac29dc18f991921e2c064969159a.tar.gz"],
)

http_archive(
Expand All @@ -45,6 +38,10 @@ load(

container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
Expand Down
17 changes: 17 additions & 0 deletions debian9/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

build --host_force_python=PY2
test --host_force_python=PY2
run --host_force_python=PY2
2 changes: 1 addition & 1 deletion debian9/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@base_images_docker//util:run.bzl", "container_run_and_extract")
load(
"@bazel_toolchains//rules/container:docker_toolchains.bzl",
"toolchain_container",
)
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")
load("@io_bazel_rules_docker//docker/util:run.bzl", "container_run_and_extract")

licenses(["notice"]) # Apache 2.0

Expand Down
23 changes: 10 additions & 13 deletions debian9/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,16 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_toolchains",
sha256 = "e886e0624871dcce823cccc7f9a634c58b0d68fdc3ad6577347826558f1581d8",
strip_prefix = "bazel-toolchains-9f6cd65b5fd8bc85634dafc99075556c06d8d3a6",
urls = ["https://github.com/bazelbuild/bazel-toolchains/archive/9f6cd65b5fd8bc85634dafc99075556c06d8d3a6.tar.gz"],
sha256 = "7d0c157364ce8dac5282af7c7b9e8d9e2c4ee7a6a30dfdb763e9e40b09a656e9",
strip_prefix = "bazel-toolchains-e6e7db64dfcfe82f54782a75ee549b0e392ecefc",
urls = ["https://github.com/bazelbuild/bazel-toolchains/archive/e6e7db64dfcfe82f54782a75ee549b0e392ecefc.tar.gz"],
)

http_archive(
name = "io_bazel_rules_docker",
sha256 = "1a035f4e9c21e48668e09b327f89bd8197feb42b82d2b6904913c655f27a845a",
strip_prefix = "rules_docker-bb6d6606a6be348115af3552662799fd6d851a88",
urls = ["https://github.com/bazelbuild/rules_docker/archive/bb6d6606a6be348115af3552662799fd6d851a88.tar.gz"],
)

http_archive(
name = "base_images_docker",
sha256 = "16da54ef0734a0658d7006bc8bf6b9be26b963edec497b13974a1bfb46cefc41",
strip_prefix = "base-images-docker-7fdd2bb83a6957fe66712bd5238087b257b04378",
urls = ["https://github.com/GoogleContainerTools/base-images-docker/archive/7fdd2bb83a6957fe66712bd5238087b257b04378.tar.gz"],
sha256 = "b16afde01b99f8b9a067b98903a5fa1879307f9344ccdbbc4aa796ae657e910f",
strip_prefix = "rules_docker-4ea9e6708ec5ac29dc18f991921e2c064969159a",
urls = ["https://github.com/bazelbuild/rules_docker/archive/4ea9e6708ec5ac29dc18f991921e2c064969159a.tar.gz"],
)

http_archive(
Expand All @@ -52,6 +45,10 @@ load(

container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
Expand Down
2 changes: 0 additions & 2 deletions dockerfile_build/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
package(default_visibility = ["//visibility:public"])

load(":dockerfile_build.bzl", "dockerfile_build")
71 changes: 36 additions & 35 deletions dockerfile_build/dockerfile_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def _impl(ctx):
unstripped_tar = ctx.actions.declare_file(ctx.label.name + ".unstripped")

if bool(ctx.attr.base) == bool(ctx.attr.base_tar):
fail('Please specify only one of base and base_tar')
fail("Please specify only one of base and base_tar")

# Use the incremental loader if possible.
if ctx.attr.base:
loader = ctx.executable.base.path
Expand All @@ -37,10 +38,13 @@ def _impl(ctx):
attr = ctx.attr.base_tar

# Strip off the '.tar'
base_image = attr.label.name.split('.', 1)[0]
base_image = attr.label.name.split(".", 1)[0]

# docker_build rules always generate an image named 'bazel/$package:$name'.
base_image_name = "bazel/%s:%s" % (attr.label.package,
base_image)
base_image_name = "bazel/%s:%s" % (
attr.label.package,
base_image,
)

# Generate a shell script to run the build.
build_contents = """\
Expand All @@ -65,62 +69,59 @@ cat {dockerfile} | sed "s|FROM.*|FROM {base_name}|g" > "$tmpdir"/Dockerfile
docker build -t {tag} "$tmpdir"
# Copy out the rootfs.
docker save {tag} > {output}
""".format(base_loader=loader,
base_name=base_image_name,
dockerfile=dockerfile_path,
context=context_path,
tag="bazel/%s:%s" % (ctx.label.package, ctx.label.name),
output=unstripped_tar.path)
""".format(
base_loader = loader,
base_name = base_image_name,
dockerfile = dockerfile_path,
context = context_path,
tag = "bazel/%s:%s" % (ctx.label.package, ctx.label.name),
output = unstripped_tar.path,
)
script = ctx.actions.declare_file(ctx.label.name + ".build")
ctx.file_action(
output=script,
content=build_contents
ctx.actions.write(
output = script,
content = build_contents,
)

inputs = (attr.files.to_list() + ctx.attr.dockerfile.files.to_list() +
attr.data_runfiles.files.to_list() + attr.default_runfiles.files.to_list())
attr.data_runfiles.files.to_list() + attr.default_runfiles.files.to_list())
if ctx.attr.context:
inputs += ctx.attr.context.files.to_list()

ctx.actions.run(
outputs=[unstripped_tar],
inputs=inputs,
executable=script,
mnemonic="BuildTar",
outputs = [unstripped_tar],
inputs = inputs,
executable = script,
mnemonic = "BuildTar",
)


ctx.actions.run(
outputs=[ctx.outputs.out],
inputs=[unstripped_tar],
executable=ctx.executable._config_stripper,
arguments=['--in_tar_path=%s' % unstripped_tar.path, '--out_tar_path=%s' % ctx.outputs.out.path],
mnemonic="StripTar",
outputs = [ctx.outputs.out],
inputs = [unstripped_tar],
executable = ctx.executable._config_stripper,
arguments = ["--in_tar_path=%s" % unstripped_tar.path, "--out_tar_path=%s" % ctx.outputs.out.path],
mnemonic = "StripTar",
)

return struct()

_dockerfile_build = rule(
attrs = {
"base": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
executable = True,
cfg = "target",
),
"base_tar": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
cfg = "target",
),
"dockerfile": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
mandatory = True,
),
"context": attr.label(
allow_files = True,
single_file = True,
allow_single_file = True,
),
"_config_stripper": attr.label(
cfg = "host",
Expand All @@ -138,11 +139,11 @@ _dockerfile_build = rule(
def dockerfile_build(name, *args, **kwargs):
intermediate_name = "%s-intermediate" % name
_dockerfile_build(
name=intermediate_name,
name = intermediate_name,
*args,
**kwargs
)
docker_build(
name=name,
base=intermediate_name + ".tar"
name = name,
base = intermediate_name + ".tar",
)
Loading

0 comments on commit 92fff1a

Please sign in to comment.