Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 8f5dd14

Browse files
author
Priya Wadhwa
committed
Create a bazel rule for container diff
1 parent b089b9b commit 8f5dd14

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docker_diff.bzl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2017 Google, Inc. All rights reserved.
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
def _impl(ctx):
16+
"""Implementation of docker_diff"""
17+
18+
image_location = ctx.executable.image.short_path
19+
cd_binary_loction = ctx.executable._container_diff_tool.short_path
20+
21+
content = "%s diff %s %s" % (cd_binary_loction, image_location, ctx.attr.diff_base)
22+
if ctx.attr.diff_types:
23+
content += " --types=%s" % (",".join(ctx.attr.diff_types))
24+
25+
ctx.file_action(
26+
output = ctx.outputs.executable,
27+
content = content,
28+
)
29+
30+
return struct(runfiles=ctx.runfiles(
31+
files = [
32+
ctx.executable._container_diff_tool,
33+
ctx.executable.image
34+
]),
35+
)
36+
37+
# Diff a bazel image against an image in production with bazel run
38+
# Runs container-diff on the two images and prints the output.
39+
# Args:
40+
# name: name of the rule
41+
# image: bazel target to an image you have bazel built (must be a tar)
42+
# ex: image = "@//target/to:image.tar"
43+
# diff_base: Tag or digest in a remote registry you want to diff against
44+
# ex: diff_base = "gcr.io/google-appengine/debian8:latest"
45+
# diff_types: Types flag to pass to container diff
46+
# ex: ["pip", "file"]
47+
48+
docker_diff = rule(
49+
attrs = {
50+
"image": attr.label(
51+
allow_files = [".tar"],
52+
single_file = True,
53+
mandatory = True,
54+
executable = True,
55+
cfg = "target"
56+
),
57+
"diff_base": attr.string(mandatory = True),
58+
"diff_types": attr.string_list(
59+
allow_empty = True,
60+
),
61+
"_container_diff_tool": attr.label(
62+
default = Label("//:container-diff"),
63+
executable = True,
64+
cfg = "host"
65+
),
66+
},
67+
implementation = _impl,
68+
executable = True,
69+
)

0 commit comments

Comments
 (0)