• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language Starlark
  • License
    Apache License 2.0
  • Created almost 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bazel rules for building OCI containers

Bazel rules for OCI containers

This is a "barebones" alternative to rules_docker.

A lot of companies have already done a successful migration from rules_docker. Please let us know about yours on our adoption discussion! #299

We start from first principles and avoided some pitfalls we learned in maintaining that repo:

  • Use a toolchain consisting of off-the-shelf, pre-built layer and container manipulation tools.
  • Don't write language-specific rules, as we cannot be experts on all languages, nor can users deal with the versioning issues that come with dependencies we would be forced to take on the rules for those languages.
  • Don't be docker-specific, now that it has a commercial license and other container runtimes exist (podman for example).
  • Use our toolchain hermetically: don't assume there is a docker pre-installed on the machine.
  • Keep a tight complexity budget for the project so we are able to commit to effective maintenance.

Need help? This ruleset has support provided by https://aspect.dev.

Installation

See the install instructions on the release notes: https://github.com/bazel-contrib/rules_oci/releases

To use a commit rather than a release, you can point at any SHA of the repo.

With bzlmod, you can use archive_override or git_override. For WORKSPACE, you modify the http_archive call; for example to use commit abc123 with a WORKSPACE file:

  1. Replace url = "https://github.com/bazel-contrib/rules_oci/releases/download/v0.1.0/rules_oci-v0.1.0.tar.gz" with a GitHub-provided source archive like url = "https://github.com/bazel-contrib/rules_oci/archive/abc123.tar.gz"
  2. Replace strip_prefix = "rules_oci-0.1.0" with strip_prefix = "rules_oci-abc123"
  3. Update the sha256. The easiest way to do this is to comment out the line, then Bazel will print a message with the correct value.

Note that GitHub source archives don't have a strong guarantee on the sha256 stability, see https://github.blog/2023-02-21-update-on-the-future-stability-of-source-code-archives-and-hashes

Usage

rules_oci does not contain language-specific rules, but we do have limited documentation on how to accomplish typical tasks, and how to migrate from the language-specific rules in rules_docker.

Your language not listed above? Please contribute engineering resources or financially through our Sponsor link!

There are some generic examples of usage in the examples folder. Note that these examples rely on the setup code in the /WORKSPACE file in the root of this repo.

Choosing between zot or crane as the local registry

rules_oci supports two different registry implementation for the temporary storage within actions spawned by bazel.

  1. By default we recommend using zot as it stores blobs on disk, however it doesn't support Docker-format images.
  2. crane is memory hungry as it stores blobs in memory, leading to high memory usage. However it supports both OCI and Docker formats which is quite useful for using Docker images pulled from the registries such as DockerHub.

Public API Docs

Construct image layers

  • oci_image Build an OCI compatible container image.
  • oci_image_index Build a multi-architecture OCI compatible container image.
  • oci_tarball Creates tarball from oci_image that can be loaded by runtimes.

Pull and Push

  • oci_pull Pulls image layers using Bazel's downloader.
  • oci_push Push an oci_image or oci_image_index to a remote registry.

Testing

More Repositories

1

rules_nodejs

NodeJS toolchain for Bazel.
Starlark
727
star
2

rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
Starlark
662
star
3

rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Starlark
324
star
4

toolchains_llvm

LLVM toolchain for bazel
Starlark
294
star
5

vscode-bazel

Bazel support for Visual Studio Code
TypeScript
241
star
6

rules_dotnet

.NET rules for Bazel
Starlark
190
star
7

bazel-lib

Common useful functions for writing BUILD files and Starlark macros/rules
Starlark
137
star
8

target-determinator

Determines which Bazel targets were affected between two git commits.
Go
131
star
9

bazel-mypy-integration

🐍🌿💚 Integrate MyPy type-checking into your Python Bazel builds
Starlark
119
star
10

rules_fuzzing

Bazel Starlark extensions for defining fuzz tests in Bazel projects
Starlark
87
star
11

rules_cuda

Starlark implementation of bazel rules for CUDA.
Starlark
83
star
12

rules_jsonnet

Jsonnet rules for Bazel
Starlark
69
star
13

rules_jvm

Contributed Bazel rules that make working with java projects more pleasant
Java
46
star
14

rules-template

A template for creating a new Bazel ruleset
Starlark
45
star
15

rules_bazel_integration_test

Rules and macros for executing integration tests that use Bazel. Supports running integration tests with multiple versions of Bazel.
Starlark
40
star
16

rules_debian_packages

Rules for installing debian-packages into Docker-Images with bazel
Starlark
23
star
17

SIG-rules-authors

Governance and admin for the rules authors Special Interest Group
Shell
22
star
18

publish-to-bcr

A GitHub app that mirrors releases of your Bazel ruleset to the Central Registry
TypeScript
21
star
19

Bazel-learning-paths

Bazel training materials and codelabs focused on beginner, advanced and contributor learning paths
Java
19
star
20

bazel_features

Support Bazel "feature detection" from starlark
Starlark
17
star
21

musl-toolchain

Python
14
star
22

unused-jvm-deps

Tool to remove unused deps entries for Java
Java
14
star
23

bcr-ui

Website for the Bazel Central Registry
TypeScript
10
star
24

bazel-catalog

Catalog of Bazel rules. http://awesomebazel.com meets https://bazel.build/rules plus live stats.
Shell
3
star
25

target-determinator-testdata

Sample commits used to test implementations of target determinators.
1
star
26

.github

GitHub metadata for the org
1
star