forked from GoogleContainerTools/container-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker_diff.bzl
70 lines (60 loc) · 2.23 KB
/
docker_diff.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright 2017 Google, Inc. 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.
def _impl(ctx):
"""Implementation of docker_diff"""
container_diff_loction = ctx.executable._container_diff.short_path
image_location = ctx.file.image.short_path
# Shell script to execute container-diff with appropriate flags
content = """\
#!/bin/bash
set -e
./%s diff %s %s""" % (container_diff_loction, image_location, ctx.attr.diff_base)
content += " ".join(["--type=%s" % t for t in ctx.attr.diff_types])
ctx.file_action(
output = ctx.outputs.executable,
content = content,
)
return struct(runfiles=ctx.runfiles(
files = [
ctx.executable._container_diff,
ctx.file.image
]),
)
# Diff a bazel image against an image in production with bazel run
# Runs container-diff on the two images and prints the output.
# Args:
# name: name of the rule
# image: bazel target to an image you have bazel built (must be a tar)
# ex: image = "@//target/to:image.tar"
# diff_base: Tag or digest in a remote registry you want to diff against
# ex: diff_base = "gcr.io/google-appengine/debian8:latest"
# diff_types: Types flag to pass to container diff
# ex: ["pip", "file"]
docker_diff = rule(
attrs = {
"image": attr.label(
allow_files = [".tar"],
single_file = True,
mandatory = True,
),
"diff_base": attr.string(mandatory = True),
"diff_types": attr.string_list(
allow_empty = True,
),
"_container_diff": attr.label(
default = Label("//:container-diff"),
executable = True,
cfg = "host",
),
},
executable = True,
implementation = _impl,
)