aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--WORKSPACE3
-rw-r--r--src/test/docker/BUILD41
-rw-r--r--src/test/docker/docker_pull.bzl80
-rw-r--r--src/test/docker/docker_repository.bzl9
-rw-r--r--src/test/docker/flavours.bzl37
5 files changed, 41 insertions, 129 deletions
diff --git a/WORKSPACE b/WORKSPACE
index e7bf065e57..5dae9249c0 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -42,9 +42,8 @@ new_http_archive(
# For src/test/docker/...
load("//src/test/docker:docker_repository.bzl", "docker_repository")
+
docker_repository()
-load("//src/test/docker:flavours.bzl", "pull_images_for_docker_tests")
-pull_images_for_docker_tests()
# To run the Android integration tests in //src/test/shell/bazel/android:all or
# build the Android sample app in //examples/android/java/bazel:hello_world
diff --git a/src/test/docker/BUILD b/src/test/docker/BUILD
index e489a6b019..7393126af3 100644
--- a/src/test/docker/BUILD
+++ b/src/test/docker/BUILD
@@ -1,6 +1,43 @@
load("//tools/build_defs/docker:docker.bzl", "docker_build")
load("//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
-load("//src/test/docker:flavours.bzl", "FLAVOURS")
+
+# This is totally non hermetic, we should really replace that by a
+# docker_pull rule.
+FLAVOURS = [f[f.find(".") + 1:] for f in glob(["Dockerfile.*"])]
+
+[
+ # This is totally non hermetic.
+ genrule(
+ name = "docker-" + flavour,
+ srcs = ["Dockerfile." + flavour],
+ outs = ["docker-%s.tar" % flavour],
+ cmd = "\n".join([
+ "DIR=\"$$(dirname $<)\"",
+ "IMG=\"$$(basename $<)\"",
+ "DOCKER=\"$${PWD}/$(location @docker//:docker)\"",
+ "(",
+ " cd $$DIR",
+ " $$DOCKER build -f $$IMG -t bazel_tools_cpp_test:%s ." % flavour,
+ ")",
+ "$$DOCKER save bazel_tools_cpp_test:%s > $@" % flavour,
+ ]),
+ tags = ["local"],
+ # Docker needs to knows how to contact the daemon from the environment.
+ # @docker//:docker point to a docker wrapper that copy the environment
+ # of the user.
+ tools = ["@docker//:docker"],
+ )
+ for flavour in FLAVOURS
+]
+
+# Just to avoid re-reading docker images all the time
+[
+ docker_build(
+ name = "base-" + flavour,
+ base = "docker-" + flavour,
+ )
+ for flavour in FLAVOURS
+]
pkg_tar(
name = "bazel_cc_configure",
@@ -12,7 +49,7 @@ pkg_tar(
[
[docker_build(
name = "bazel_cc_configure-%s-%s" % (flavour, mode),
- base = "@docker-%s//:image" % flavour,
+ base = ":base-" + flavour,
entrypoint = "/opt/workspace/compile.sh && ./output/bazel test ${EXTRA_BAZEL_ARGS} //examples/cpp:hello-success_test",
env = {
"EXTRA_BAZEL_ARGS": "--spawn_strategy=standalone --genrule_strategy=standalone -c %s" % mode,
diff --git a/src/test/docker/docker_pull.bzl b/src/test/docker/docker_pull.bzl
deleted file mode 100644
index 8fab57fe88..0000000000
--- a/src/test/docker/docker_pull.bzl
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copyright 2016 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.
-
-"""Quick and not really nice docker_pull rules based on the docker daemon."""
-
-def _impl(repository_ctx):
- docker = repository_ctx.which("docker")
- if docker == None and repository_ctx.attr.optional:
- repository_ctx.file("BUILD", """
-load("@bazel_tools//tools/build_defs/docker:docker.bzl", "docker_build")
-
-# an empty image to still allow building despite not having the base
-# image.
-docker_build(
- name = "image",
- visibility = ['//visibility:public'],
-)
-""")
- repository_ctx.file("image.tar")
- return
-
- repository_ctx.file("BUILD", """
-load("@bazel_tools//tools/build_defs/docker:docker.bzl", "docker_build")
-
-docker_build(
- name = "image",
- base = ":base.tar",
- visibility = ["//visibility:public"],
-)
-""")
- tag = repository_ctx.attr.tag
- cmd = "pull"
- if repository_ctx.attr.dockerfile:
- dockerfile = repository_ctx.path(repository_ctx.attr.dockerfile)
- cmd = "build"
- print("Running `docker build`")
- result = repository_ctx.execute([
- docker,
- "build",
- "-q",
- "-t",
- tag,
- "-f",
- dockerfile,
- dockerfile.dirname,
- ], quiet=False, timeout=3600)
- else:
- print("Running `docker pull`")
- result = repository_ctx.execute([docker, "pull", tag], quiet=False, timeout=3600)
- if result.return_code:
- fail("docker %s failed with error code %s:\n%s" % (
- cmd,
- result.return_code,
- result.stderr))
- result = repository_ctx.execute([
- docker, "save", "-o", repository_ctx.path("base.tar"), tag])
- if result.return_code:
- fail("docker save failed with error code %s:\n%s" % (
- result.return_code,
- result.stderr))
-
-docker_pull = repository_rule(
- implementation = _impl,
- attrs = {
- "tag": attr.string(mandatory=True),
- "dockerfile": attr.label(default=None),
- "optional": attr.bool(default=False),
- },
-)
diff --git a/src/test/docker/docker_repository.bzl b/src/test/docker/docker_repository.bzl
index 1b49d1a9ed..4f96170176 100644
--- a/src/test/docker/docker_repository.bzl
+++ b/src/test/docker/docker_repository.bzl
@@ -20,17 +20,11 @@ def _impl(ctx):
# on it, silently ignoring.
ctx.file("BUILD",
"\n".join([
- "sh_binary(",
+ "filegroup(",
" name = 'docker',",
- " srcs = ['docker.sh'],",
" visibility = ['//visibility:public'],",
")"
]))
- ctx.file("docker.sh", "\n".join([
- "#!/bin/bash",
- "echo 'ERROR: docker is not installed' >&2",
- "exit 1"
- ]))
else:
exports = []
for k in ctx.os.environ:
@@ -61,4 +55,3 @@ docker_repository_ = repository_rule(_impl)
def docker_repository():
"""Declare a @docker repository that provide a docker binary."""
docker_repository_(name = "docker")
-
diff --git a/src/test/docker/flavours.bzl b/src/test/docker/flavours.bzl
deleted file mode 100644
index 713c7c5243..0000000000
--- a/src/test/docker/flavours.bzl
+++ /dev/null
@@ -1,37 +0,0 @@
-# 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.
-"""Create base images for docker tests."""
-# TODO(dmarting): Right now we use a custom docker_pull that can build
-# docker images, which is not reproducible and as a high cost, ideally
-# we would switch to the docker_pull from bazelbuild/rules_docker but
-# we do not have an easy mean to create and maintain the images we need
-# for those tests.
-load("//src/test/docker:docker_pull.bzl", "docker_pull")
-
-FLAVOURS = [
- "centos6.7",
- "debian-stretch",
- "fedora23",
- "ubuntu-15.04",
- "ubuntu-16.04",
-]
-
-def pull_images_for_docker_tests():
- for flavour in FLAVOURS:
- docker_pull(
- name = "docker-" + flavour,
- tag = "bazel_tools_cpp_test:" + flavour,
- dockerfile = "//src/test/docker:Dockerfile." + flavour,
- optional = True,
- )