Skip to content
This repository has been archived by the owner on Oct 2, 2023. It is now read-only.

Run all BUILD/skylark files through buildifier #14

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 66 additions & 56 deletions docker/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,40 @@
# limitations under the License.
"""Rule for building a Docker image."""

load(":filetype.bzl",
tar_filetype="tar",
deb_filetype="deb",
docker_filetype="docker")
load(":hash.bzl",
_hash_tools="tools", _sha256="sha256")
load(":label.bzl", _string_to_label="string_to_label")
load(":layers.bzl",
_assemble_image="assemble",
_get_layers="get_from_target",
_incr_load="incremental_load",
_layer_tools="tools")
load(
":filetype.bzl",
deb_filetype = "deb",
docker_filetype = "docker",
tar_filetype = "tar",
)
load(
":hash.bzl",
_hash_tools = "tools",
_sha256 = "sha256",
)
load(
":label.bzl",
_string_to_label = "string_to_label",
)
load(
":layers.bzl",
_assemble_image = "assemble",
_get_layers = "get_from_target",
_incr_load = "incremental_load",
_layer_tools = "tools",
)
load(":list.bzl", "reverse")
load(":path.bzl",
"dirname", "strip_prefix",
_join_path="join",
_canonicalize_path="canonicalize")
load(":serialize.bzl", _serialize_dict="dict_to_associative_list")

load(
":path.bzl",
"dirname",
"strip_prefix",
_canonicalize_path = "canonicalize",
_join_path = "join",
)
load(
":serialize.bzl",
_serialize_dict = "dict_to_associative_list",
)

def _build_layer(ctx):
"""Build the current layer for appending it the base layer."""
Expand Down Expand Up @@ -73,7 +88,6 @@ def _build_layer(ctx):
)
return layer


# TODO(mattmoor): In a future change, we should establish the invariant that
# base must expose "docker_layers", possibly by hoisting a "docker_load" rule
# from a tarball "base".
Expand All @@ -86,7 +100,6 @@ def _get_base_artifact(ctx):
fail("base attribute should be a single tar file.")
return ctx.files.base[0]


def _image_config(ctx, layer_names):
"""Create the configuration for a new docker image."""
config = ctx.new_file(ctx.label.name + ".config")
Expand Down Expand Up @@ -145,7 +158,6 @@ def _image_config(ctx, layer_names):
mnemonic = "ImageConfig")
return config


def _metadata_action(ctx, layer, name, output):
"""Generate the action to create the JSON metadata for the layer."""
rewrite_tool = ctx.executable.rewrite_tool
Expand Down Expand Up @@ -203,14 +215,12 @@ def _metadata_action(ctx, layer, name, output):
use_default_shell_env=True,
mnemonic = "RewriteJSON")


def _metadata(ctx, layer, name):
"""Create the metadata for the new docker image."""
metadata = ctx.new_file(ctx.label.name + ".metadata")
_metadata_action(ctx, layer, name, metadata)
return metadata


def _compute_layer_name(ctx, layer):
"""Compute the layer's name.

Expand All @@ -235,7 +245,6 @@ def _compute_layer_name(ctx, layer):
_metadata_action(ctx, layer, layer_sha, metadata)
return _sha256(ctx, metadata)


def _repository_name(ctx):
"""Compute the repository name for the current rule."""
if ctx.attr.legacy_repository_naming:
Expand All @@ -245,7 +254,6 @@ def _repository_name(ctx):
# the v2 registry specification.
return _join_path(ctx.attr.repository, ctx.label.package)


def _create_image(ctx, layers, identifier, config, name, metadata, tags):
"""Create the new image."""
args = [
Expand Down Expand Up @@ -276,7 +284,6 @@ def _create_image(ctx, layers, identifier, config, name, metadata, tags):
mnemonic = "CreateImage",
)


def _docker_build_impl(ctx):
"""Implementation for the docker_build rule."""
layer = _build_layer(ctx)
Expand Down Expand Up @@ -321,18 +328,16 @@ def _docker_build_impl(ctx):
files = set([ctx.outputs.layer]),
docker_layers = layers)


docker_build_ = rule(
implementation = _docker_build_impl,
attrs = {
"base": attr.label(allow_files=docker_filetype),
"base": attr.label(allow_files = docker_filetype),
"data_path": attr.string(),
"directory": attr.string(default="/"),
"tars": attr.label_list(allow_files=tar_filetype),
"debs": attr.label_list(allow_files=deb_filetype),
"files": attr.label_list(allow_files=True),
"legacy_repository_naming": attr.bool(default=False),
"mode": attr.string(default="0555"),
"directory": attr.string(default = "/"),
"tars": attr.label_list(allow_files = tar_filetype),
"debs": attr.label_list(allow_files = deb_filetype),
"files": attr.label_list(allow_files = True),
"legacy_repository_naming": attr.bool(default = False),
"mode": attr.string(default = "0555"),
"symlinks": attr.string_dict(),
"entrypoint": attr.string_list(),
"cmd": attr.string_list(),
Expand All @@ -342,38 +347,44 @@ 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"),
"repository": attr.string(default = "bazel"),
# Implicit dependencies.
"label_files": attr.label_list(
allow_files=True),
allow_files = True,
),
"label_file_strings": attr.string_list(),
"build_layer": attr.label(
default=Label("@bazel_tools//tools/build_defs/pkg:build_tar"),
cfg="host",
executable=True,
allow_files=True),
default = Label("@bazel_tools//tools/build_defs/pkg:build_tar"),
cfg = "host",
executable = True,
allow_files = True,
),
"create_image": attr.label(
default=Label("//docker:create_image"),
cfg="host",
executable=True,
allow_files=True),
default = Label("//docker:create_image"),
cfg = "host",
executable = True,
allow_files = True,
),
"rewrite_tool": attr.label(
default=Label("//docker:rewrite_json"),
cfg="host",
executable=True,
allow_files=True),
default = Label("//docker:rewrite_json"),
cfg = "host",
executable = True,
allow_files = True,
),
"create_image_config": attr.label(
default=Label("//docker:create_image_config"),
cfg="host",
executable=True,
allow_files=True)
default = Label("//docker:create_image_config"),
cfg = "host",
executable = True,
allow_files = True,
),
} + _hash_tools + _layer_tools,
executable = True,
outputs = {
"out": "%{name}.tar",
"layer": "%{name}-layer.tar",
},
executable = True)

implementation = _docker_build_impl,
)

# This validates the two forms of value accepted by
# ENTRYPOINT and CMD, turning them into a canonical
Expand Down Expand Up @@ -405,7 +416,6 @@ def _validate_command(name, argument):
else:
return None


# Produces a new docker image tarball compatible with 'docker load', which
# is a single additional layer atop 'base'. The goal is to have relatively
# complete support for building docker image, from the Dockerfile spec.
Expand Down
27 changes: 15 additions & 12 deletions docker/bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
# limitations under the License.
"""Rule for bundling Docker images into a tarball."""

load(":label.bzl", _string_to_label="string_to_label")
load(":layers.bzl",
_assemble_image="assemble",
_get_layers="get_from_target",
_incr_load="incremental_load",
_layer_tools="tools")
load(
":label.bzl",
_string_to_label = "string_to_label",
)
load(
":layers.bzl",
_assemble_image = "assemble",
_get_layers = "get_from_target",
_incr_load = "incremental_load",
_layer_tools = "tools",
)
load(":list.bzl", "reverse")


def _docker_bundle_impl(ctx):
"""Implementation for the docker_bundle rule."""

Expand Down Expand Up @@ -68,20 +72,19 @@ def _docker_bundle_impl(ctx):
return struct(runfiles = runfiles,
files = set())


docker_bundle_ = rule(
implementation = _docker_bundle_impl,
attrs = {
"images": attr.string_dict(),
# Implicit dependencies.
"image_targets": attr.label_list(allow_files=True),
"image_targets": attr.label_list(allow_files = True),
"image_target_strings": attr.string_list(),
} + _layer_tools,
executable = True,
outputs = {
"out": "%{name}.tar",
},
executable = True)

implementation = _docker_bundle_impl,
)

# Produces a new docker image tarball compatible with 'docker load', which
# contains the N listed 'images', each aliased with their key.
Expand Down
2 changes: 1 addition & 1 deletion docker/docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ load(":pull.bzl", "docker_pull")
load(":push.bzl", "docker_push")

# The release of the github.com/google/containerregistry to consume.
CONTAINERREGISTRY_RELEASE = 'v0.0.3'
CONTAINERREGISTRY_RELEASE = "v0.0.3"

def docker_repositories():
"""Download dependencies of docker rules."""
Expand Down
13 changes: 11 additions & 2 deletions docker/filetype.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
"""Filetype constants."""

# Filetype to restrict inputs
tar = [".tar", ".tar.gz", ".tgz", ".tar.xz"]
deb = [".deb", ".udeb"]
tar = [
".tar",
".tar.gz",
".tgz",
".tar.xz",
]

deb = [
".deb",
".udeb",
]

# Docker files are tarballs, should we allow other extensions than tar?
docker = tar
12 changes: 6 additions & 6 deletions docker/hash.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def sha256(ctx, artifact):
mnemonic = "SHA256")
return out


tools = {
"sha256": attr.label(
default=Label("//docker:sha256"),
cfg="host",
executable=True,
allow_files=True)
}
default = Label("//docker:sha256"),
cfg = "host",
executable = True,
allow_files = True,
),
}
35 changes: 18 additions & 17 deletions docker/layers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
"""Tools for dealing with Docker Image layers."""

load(":list.bzl", "reverse")
load(":path.bzl", _get_runfile_path="runfile")

load(
":path.bzl",
_get_runfile_path = "runfile",
)

def _extract_id(ctx, artifact):
id_out = ctx.new_file(artifact.basename + ".id")
Expand All @@ -31,7 +33,6 @@ def _extract_id(ctx, artifact):
mnemonic = "ExtractID")
return id_out, name_out


def get_from_target(ctx, attr_target, file_target):
if hasattr(attr_target, "docker_layers"):
return attr_target.docker_layers
Expand All @@ -49,7 +50,6 @@ def get_from_target(ctx, attr_target, file_target):
"name": name_out
}]


def assemble(ctx, layers, tags_to_names, output):
"""Create the full image from the list of layers."""
layers = [l["layer"] for l in layers]
Expand All @@ -68,7 +68,6 @@ def assemble(ctx, layers, tags_to_names, output):
mnemonic = "JoinLayers"
)


def incremental_load(ctx, layers, images, output):
"""Generate the incremental load statement."""
ctx.template_action(
Expand All @@ -92,20 +91,22 @@ def incremental_load(ctx, layers, images, output):
output = output,
executable = True)


tools = {
"incremental_load_template": attr.label(
default=Label("//docker:incremental_load_template"),
single_file=True,
allow_files=True),
default = Label("//docker:incremental_load_template"),
single_file = True,
allow_files = True,
),
"join_layers": attr.label(
default=Label("//docker:join_layers"),
cfg="host",
executable=True,
allow_files=True),
default = Label("//docker:join_layers"),
cfg = "host",
executable = True,
allow_files = True,
),
"extract_id": attr.label(
default=Label("//docker:extract_id"),
cfg="host",
executable=True,
allow_files=True),
default = Label("//docker:extract_id"),
cfg = "host",
executable = True,
allow_files = True,
),
}
Loading