aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Damien Martin-Guillerez <dmarting@google.com>2015-10-01 17:07:08 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-10-01 19:44:40 +0000
commitf345d0806eb7b7458c1988a6eeab822944ce5c71 (patch)
tree4fa97f4e0c4c88c22575a4757453bc6c7f6821a8 /tools
parent5943bfb8d15bfb14c747204c36f7c8f7a6672180 (diff)
[Docker] add a `repository` attribute
This attribute specifies the default repository for the generated image. -- MOS_MIGRATED_REVID=104408398
Diffstat (limited to 'tools')
-rw-r--r--tools/build_defs/docker/BUILD1
-rw-r--r--tools/build_defs/docker/README.md14
-rwxr-xr-xtools/build_defs/docker/build_test.sh14
-rw-r--r--tools/build_defs/docker/docker.bzl11
-rw-r--r--tools/build_defs/docker/testdata/BUILD6
5 files changed, 39 insertions, 7 deletions
diff --git a/tools/build_defs/docker/BUILD b/tools/build_defs/docker/BUILD
index 227ca033a3..921d347a60 100644
--- a/tools/build_defs/docker/BUILD
+++ b/tools/build_defs/docker/BUILD
@@ -35,6 +35,7 @@ TEST_DATA = [
"//tools/build_defs/docker/testdata:gen_image",
"//tools/build_defs/docker/testdata:data_path_image",
"//tools/build_defs/docker/testdata:no_data_path_image",
+ "//tools/build_defs/docker/testdata:dummy_repository",
]
sh_test(
diff --git a/tools/build_defs/docker/README.md b/tools/build_defs/docker/README.md
index a225f5c259..8a13076a15 100644
--- a/tools/build_defs/docker/README.md
+++ b/tools/build_defs/docker/README.md
@@ -181,7 +181,7 @@ docker_build(
### `docker_build`
`docker_build(name, base, data_path, directory, files, mode, tars,
-debs, symlinks, entrypoint, cmd, env, ports, volumes, workdir)`
+debs, symlinks, entrypoint, cmd, env, ports, volumes, workdir, repository)`
<table>
<thead>
@@ -333,6 +333,18 @@ debs, symlinks, entrypoint, cmd, env, ports, volumes, workdir)`
adding files).</p>
</td>
</tr>
+ <tr>
+ <td><code>repository</code></td>
+ <td>
+ <code>String, default to `bazel`</code>
+ <p>The repository for the default tag for the image.</a></p>
+ <p>Image generated by `docker_build` are tagged by default to
+ `bazel/package_name:target` for a `docker_build` target at
+ `//package/name:target`. Setting this attribute to
+ `gcr.io/dummy` would set the default tag to
+ `gcr.io/dummy/package_name:target`.</p>
+ </td>
+ </tr>
</tbody>
</tbody>
</table>
diff --git a/tools/build_defs/docker/build_test.sh b/tools/build_defs/docker/build_test.sh
index 4381552f34..9d9d1429c6 100755
--- a/tools/build_defs/docker/build_test.sh
+++ b/tools/build_defs/docker/build_test.sh
@@ -186,6 +186,20 @@ function test_gen_image() {
|| fail "'./gen.out' not found in '$TEST_DATA_DIR/gen_image.tar'"
}
+function test_dummy_repository() {
+ local layer="eae4fa9baf743667fbe3f8d76fd598cf9ea5052261bbfaa552780dd2744c47a4"
+ local test_data="${TEST_DATA_DIR}/dummy_repository.tar"
+ check_layers_aux "dummy_repository" "$layer"
+
+
+ local repositories="$(tar xOf "${test_data}" "./repositories")"
+ # This would really need to use `jq` instead.
+ echo "${repositories}" | \
+ grep -Esq -- "\"gcr.io/dummy/[a-zA-Z_]*_docker_testdata\": {" \
+ || fail "Cannot find image in repository gcr.io/dummy in '${repositories}'"
+ EXPECT_CONTAINS "${repositories}" "\"dummy_repository\": \"$layer\""
+}
+
function test_files_base() {
check_layers "files_base" \
"240dd12c02aee796394ce18eee3108475f7d544294b17fc90ec54e983601fe1b"
diff --git a/tools/build_defs/docker/docker.bzl b/tools/build_defs/docker/docker.bzl
index 1f818b032c..67e17e0761 100644
--- a/tools/build_defs/docker/docker.bzl
+++ b/tools/build_defs/docker/docker.bzl
@@ -197,11 +197,9 @@ def _create_image(ctx, layer, name, metadata):
"--layer=" + layer.path,
"--id=@" + name.path,
# We label at push time, so we only put a single name in this file:
- # bazel/package:target => {the layer being appended}
- # TODO(dmarting): Does the name makes sense? We could use the
- # repositoryName/package instead. (why do we need to replace
- # slashes?)
- "--repository=bazel/" + ctx.label.package.replace("/", "_"),
+ # repository/package:target => {the layer being appended}
+ "--repository=%s/%s" % (ctx.attr.repository,
+ ctx.label.package.replace("/", "_")),
"--name=" + ctx.label.name
]
inputs = [layer, metadata, name]
@@ -251,6 +249,7 @@ docker_build_ = rule(
"ports": attr.string_list(), # Skylark doesn't support int_list...
"volumes": attr.string_list(),
"workdir": attr.string(),
+ "repository": attr.string(default="bazel"),
# Implicit dependencies.
"_build_layer": attr.label(
default=Label("//tools/build_defs/docker:build_layer"),
@@ -373,7 +372,7 @@ def docker_build(**kwargs):
This rule appends a single new layer to the tarball of this form provided
via the 'base' parameter.
- The images produced by this rule are always named 'blaze/tmp:latest' when
+ The images produced by this rule are always named 'bazel/tmp:latest' when
loaded (an internal detail). The expectation is that the images produced
by these rules will be uploaded using the 'docker_push' rule below.
diff --git a/tools/build_defs/docker/testdata/BUILD b/tools/build_defs/docker/testdata/BUILD
index 75d36e4073..9ea8f162d4 100644
--- a/tools/build_defs/docker/testdata/BUILD
+++ b/tools/build_defs/docker/testdata/BUILD
@@ -25,6 +25,12 @@ genrule(
)
docker_build(
+ name = "dummy_repository",
+ files = ["foo"],
+ repository = "gcr.io/dummy",
+)
+
+docker_build(
name = "no_data_path_image",
files = ["//tools/build_defs/docker/testdata/test:test-data"],
mode = "0644",