Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement container_layer rule. #279

Merged
merged 14 commits into from
Feb 28, 2018
Merged
162 changes: 161 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,11 +988,163 @@ An executable rule that pushes a Docker image to a Docker registry on `bazel run
</tbody>
</table>

<a name="container_layer"></a>
## container_layer

```python
container_layer(data_path, directory, files, mode, tars, debs, symlinks, env)
```

A rule that assembles data into a tarball which can be use as in `layers` attr in `container_image` rule.

<table class="table table-condensed table-bordered table-implicit">
<colgroup>
<col class="col-param" />
<col class="param-description" />
</colgroup>
<thead>
<tr>
<th colspan="2">Implicit output targets</th>
</tr>
</thead>
<tbody>
<tr>
<td><code><i>name</i>-layer.tar</code></td>
<td>
<code>A tarball of current layer</code>
<p>
A data tarball corresponding to the layer.
</p>
</td>
</tr>
</tbody>
</table>

<table class="table table-condensed table-bordered table-params">
<colgroup>
<col class="col-param" />
<col class="param-description" />
</colgroup>
<thead>
<tr>
<th colspan="2">Attributes</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>name</code></td>
<td>
<code>Name, required</code>
<p>A unique name for this rule.</p>
</td>
</tr>
<tr>
<td><code>data_path</code></td>
<td>
<code>String, optional</code>
<p>Root path of the files.</p>
<p>
The directory structure from the files is preserved inside the
Docker image, but a prefix path determined by `data_path`
is removed from the directory structure. This path can
be absolute from the workspace root if starting with a `/` or
relative to the rule's directory. A relative path may starts with "./"
(or be ".") but cannot use go up with "..". By default, the
`data_path` attribute is unused, and all files should have no prefix.
</p>
</td>
</tr>
<tr>
<td><code>directory</code></td>
<td>
<code>String, optional</code>
<p>Target directory.</p>
<p>
The directory in which to expand the specified files, defaulting to '/'.
Only makes sense accompanying one of files/tars/debs.
</p>
</td>
</tr>
<tr>
<td><code>files</code></td>
<td>
<code>List of files, optional</code>
<p>File to add to the layer.</p>
<p>
A list of files that should be included in the Docker image.
</p>
</td>
</tr>
<tr>
<td><code>mode</code></td>
<td>
<code>String, default to 0555</code>
<p>
Set the mode of files added by the <code>files</code> attribute.
</p>
</td>
</tr>
<tr>
<td><code>tars</code></td>
<td>
<code>List of files, optional</code>
<p>Tar file to extract in the layer.</p>
<p>
A list of tar files whose content should be in the Docker image.
</p>
</td>
</tr>
<tr>
<td><code>debs</code></td>
<td>
<code>List of files, optional</code>
<p>Debian package to install.</p>
<p>
A list of debian packages that will be installed in the Docker image.
</p>
</td>
</tr>
<tr>
<td><code>symlinks</code></td>
<td>
<code>Dictionary, optional</code>
<p>Symlinks to create in the Docker image.</p>
<p>
<code>
symlinks = {
"/path/to/link": "/path/to/target",
...
},
</code>
</p>
</td>
</tr>
<tr>
<td><code>env</code></td>
<td>
<code>Dictionary from strings to strings, optional</code>
<p><a href="https://docs.docker.com/engine/reference/builder/#env">Dictionary
from environment variable names to their values when running the
Docker image.</a></p>
<p>
<code>
env = {
"FOO": "bar",
...
},
</code>
</p>
<p>The values of this field support stamp variables.</p>
</td>
</tr>
</tbody>
</table>

<a name="container_image"></a>
## container_image

```python
container_image(name, base, data_path, directory, files, legacy_repository_naming, mode, tars, debs, symlinks, entrypoint, cmd, env, labels, ports, volumes, workdir, repository)
container_image(name, base, data_path, directory, files, legacy_repository_naming, mode, tars, debs, symlinks, entrypoint, cmd, env, labels, ports, volumes, workdir, layers, repository)
```

<table class="table table-condensed table-bordered table-implicit">
Expand Down Expand Up @@ -1262,6 +1414,14 @@ container_image(name, base, data_path, directory, files, legacy_repository_namin
<p>This field supports stamp variables.</p>
</td>
</tr>
<tr>
<td><code>layers</code></td>
<td>
<code>Label list, optional</code>
<p>List of `container_layer` targets. </p>
<p>The data from each `container_layer` will be part of container image, and the environment variable will be available in the image as well.</p>
</td>
</tr>
<tr>
<td><code>repository</code></td>
<td>
Expand Down
2 changes: 1 addition & 1 deletion cc/image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ def cc_image(name, base=None, deps=[], layers=[], binary=None, **kwargs):
base = this_name

visibility = kwargs.get('visibility', None)
app_layer(name=name, base=base, binary=binary, layers=layers,
app_layer(name=name, base=base, binary=binary, lang_layers=layers,
visibility=visibility)
18 changes: 11 additions & 7 deletions container/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ TEST_TARGETS = [
"directory_with_tar_base",
"files_base",
"files_with_files_base",
"files_in_layer_with_files_base",
"files_with_tar_base",
"tar_base",
"tar_with_files_base",
"tar_with_tar_base",
"tars_in_layer_with_tar_base",
"docker_tarball_base",
"layers_with_docker_tarball_base",
# TODO(mattmoor): Re-enable once archive is visible
# "generated_tarball",
"with_env",
"layers_with_env",
"with_double_env",
"with_label",
"with_double_label",
Expand Down Expand Up @@ -145,7 +149,7 @@ skylark_library(
name = "bundle",
srcs = ["bundle.bzl"],
deps = [
":layers",
":layer_tools",
"//skylib:label",
],
)
Expand All @@ -166,7 +170,7 @@ skylark_library(
name = "flatten",
srcs = ["flatten.bzl"],
deps = [
":layers",
":layer_tools",
"//skylib:label",
],
)
Expand All @@ -175,7 +179,7 @@ skylark_library(
name = "image",
srcs = ["image.bzl"],
deps = [
":layers",
":layer_tools",
"//skylib:filetype",
"//skylib:label",
"//skylib:path",
Expand All @@ -189,7 +193,7 @@ skylark_library(
name = "import",
srcs = ["import.bzl"],
deps = [
":layers",
":layer_tools",
"//skylib:filetype",
"//skylib:path",
"//skylib:zip",
Expand All @@ -198,8 +202,8 @@ skylark_library(
)

skylark_library(
name = "layers",
srcs = ["layers.bzl"],
name = "layer_tools",
srcs = ["layer_tools.bzl"],
deps = ["//skylib:path"],
)

Expand All @@ -218,7 +222,7 @@ skylark_library(
name = "push",
srcs = ["push.bzl"],
deps = [
":layers",
":layer_tools",
"//skylib:path",
],
)
2 changes: 1 addition & 1 deletion container/bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load(
_string_to_label = "string_to_label",
)
load(
"//container:layers.bzl",
"//container:layer_tools.bzl",
_assemble_image = "assemble",
_get_layers = "get_from_target",
_incr_load = "incremental_load",
Expand Down
1 change: 1 addition & 0 deletions container/container.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
load("//container:bundle.bzl", "container_bundle")
load("//container:flatten.bzl", "container_flatten")
load("//container:image.bzl", "container_image", "image")
load("//container:layer.bzl", "container_layer")
load("//container:import.bzl", "container_import")
load("//container:load.bzl", "container_load")
load("//container:pull.bzl", "container_pull")
Expand Down
2 changes: 1 addition & 1 deletion container/flatten.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""A rule to flatten container images."""

load(
"//container:layers.bzl",
"//container:layer_tools.bzl",
_get_layers = "get_from_target",
_layer_tools = "tools",
)
Expand Down
Loading