gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/images/defs.bzl (about)

     1  """Helpers for Docker image generation."""
     2  
     3  def _docker_image_impl(ctx):
     4      importer = ctx.actions.declare_file(ctx.label.name)
     5  
     6      importer_content = [
     7          "#!/bin/bash",
     8          "set -euo pipefail",
     9          "source_file='%s'" % ctx.file.data.path,
    10          "if [[ ! -f \"$source_file\" ]]; then",
    11          "  source_file='%s'" % ctx.file.data.short_path,
    12          "fi",
    13          "exec docker import " + " ".join([
    14              "-c '%s'" % attr
    15              for attr in ctx.attr.statements
    16          ]) + " \"$source_file\" $1",
    17          "",
    18      ]
    19  
    20      ctx.actions.write(importer, "\n".join(importer_content), is_executable = True)
    21      return [DefaultInfo(
    22          runfiles = ctx.runfiles([ctx.file.data]),
    23          executable = importer,
    24      )]
    25  
    26  docker_image = rule(
    27      implementation = _docker_image_impl,
    28      doc = "Tool to import a Docker image; takes a single parameter (image name).",
    29      attrs = {
    30          "statements": attr.string_list(doc = "Extra Dockerfile directives."),
    31          "data": attr.label(doc = "Image filesystem tarball", allow_single_file = [".tgz", ".tar.gz"]),
    32      },
    33      executable = True,
    34  )