Skip to content

Commit

Permalink
refactor: rename oci_tarball to oci_load (#636)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Jun 24, 2024
1 parent 0d90696 commit fcdaf24
Show file tree
Hide file tree
Showing 20 changed files with 147 additions and 145 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ docs/image_index.md linguist-generated=true
docs/image.md linguist-generated=true
docs/pull.md linguist-generated=true
docs/push.md linguist-generated=true
docs/tarball.md linguist-generated=true
docs/load.md linguist-generated=true

#################################
# Configuration for 'git archive'
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ docs/image*.md
docs/structure*.md
docs/pull.md
docs/push.md
docs/tarball.md
docs/load.md
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ _Need help?_ This ruleset has support provided by [Aspect Build](https://www.asp
## Comparison with rules_docker

This ruleset is not intended as a complete replacement for [rules_docker]!
Many use cases can be accomodated, and we know that many users have completely replaced rules_docker.
Many use cases can be accomodated, and we know that many users have completely replaced rules*docker.
You can find a migration guide at <https://docs.aspect.build/guides/rules_oci_migration>.
However, some other use cases such as `container_run_and_*` rules have no equivalent.
However, some other use cases such as `container_run_and*\*` rules have no equivalent.

[rules_docker] was largely unmaintained for 18 months, and as of October 2023 it has been archived.
See https://github.com/bazelbuild/rules_docker/discussions/2038.
Expand Down Expand Up @@ -78,7 +78,7 @@ Note that these examples rely on the setup code in the `/WORKSPACE` file in the

- [oci_image](docs/image.md) Build an OCI compatible container image.
- [oci_image_index](docs/image_index.md) Build a multi-architecture OCI compatible container image.
- [oci_tarball](docs/tarball.md) Creates tarball from `oci_image` that can be loaded by runtimes.
- [oci_load](docs/load.md) Loads an `oci_image` into a container daemon. Can optionally produce a loadable tarball.

### Pull and Push

Expand Down
4 changes: 2 additions & 2 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ stardoc_with_diff_test(
)

stardoc_with_diff_test(
name = "tarball",
bzl_library_target = "//oci/private:tarball",
name = "load",
bzl_library_target = "//oci/private:load",
)

stardoc_with_diff_test(
Expand Down
18 changes: 12 additions & 6 deletions docs/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ in rules_docker.
## An example of packaging a simple C++ program

Using a minimal example C++ program `example.cc`:

```cpp
#include <iostream>

Expand All @@ -15,8 +16,9 @@ int main(){
```

To make a container image for this program, the `BUILD.bazel` would have something like this:

```python
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

Expand Down Expand Up @@ -47,16 +49,17 @@ oci_image(
entrypoint = ["/example_binary"],
)

# Create tarball from oci image that can be run by container runtime.
# Use with 'bazel run' to load the oci image into a container runtime.
# The image is designated using `repo_tags` attribute.
oci_tarball(
name = "image_tarball",
oci_load(
name = "image_load",
image = ":image",
repo_tags = ["example:latest"],
)
```

In `MODULE.bazel` file, be sure to add the following sections:

```python
# Pull needed base image
oci.pull(
Expand All @@ -71,17 +74,20 @@ oci.pull(
# Expose the base image
use_repo(oci, "docker_lib_ubuntu")
```

```python
# Import rules_pkg
bazel_dep(name = "rules_pkg", version = "0.10.1")
```

To make tarball, execute:
To load the image, execute:

```bash
bazel run //:image_tarball
bazel run //:image_load
```

Then to run the program with runtime, e.g., Docker:

```bash
docker run --rm example:latest
```
72 changes: 72 additions & 0 deletions docs/load.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/static_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ And finally the build rules for our image.
**./frontend/BUILD**

```python
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
filegroup(
name = "static",
Expand All @@ -70,7 +70,7 @@ oci_image(
# entrypoint = [],
# cmd = [],
)
oci_tarball(
oci_load(
name = "frontend_tarball",
image = ":frontend_image",
repo_tags = ["ourfrontend:latest"],
Expand Down
72 changes: 0 additions & 72 deletions docs/tarball.md

This file was deleted.

8 changes: 4 additions & 4 deletions e2e/smoke/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_bazel_lib//lib:testing.bzl", "assert_json_matches")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@container_structure_test//:defs.bzl", "container_structure_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")

oci_image(
name = "image",
Expand All @@ -21,15 +21,15 @@ tags = [
"my/image:latest",
]

oci_tarball(
name = "tarball",
oci_load(
name = "load",
image = ":image",
repo_tags = tags,
)

filegroup(
name = "tarball.tar",
srcs = [":tarball"],
srcs = [":load"],
output_group = "tarball",
)

Expand Down
4 changes: 2 additions & 2 deletions e2e/wasm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@aspect_bazel_lib//lib:tar.bzl", "tar")
load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")
load("@rules_rust//rust:defs.bzl", "rust_binary")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -48,7 +48,7 @@ build_test(
# then run the following;
# `bazel run :tarball``
# `docker run --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm32 --pull=never gcr.io/wasm:latest`
oci_tarball(
oci_load(
name = "tarball",
image = ":image",
repo_tags = ["gcr.io/wasm:latest"],
Expand Down
4 changes: 2 additions & 2 deletions examples/assert.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@bazel_skylib//rules:write_file.bzl", "write_file")

# THIS LOAD STATEMENT DEPENDS ON setup_assertion_repos.bzl
load("@docker_configure//:defs.bzl", "TARGET_COMPATIBLE_WITH")
load("//oci:defs.bzl", "oci_tarball")
load("//oci:defs.bzl", "oci_load")

DIGEST_CMD = """
image_path="$(location {image})"
Expand Down Expand Up @@ -118,7 +118,7 @@ def assert_oci_image_command(
"assert a that a container works with the given command."

tag = "oci.local/assert/" + native.package_name().replace("/", "_") + ":latest"
oci_tarball(
oci_load(
name = name + "_tarball",
image = image,
repo_tags = [tag],
Expand Down
Loading

0 comments on commit fcdaf24

Please sign in to comment.