Giter VIP home page Giter VIP logo

rules_oci's Introduction

rules_oci - blazing fast Bazel rules for building OCI Images

RULES_OCI IS HIGHLY EXPERIMENTAL WITH PLANNED BREAKING CHANGES, PLEASE DO NOT DEPEND ON FOR PRODUCTION USE-CASES.

A Bazel rule-set for extending, creating and publishing OCI artifacts, including image manifests, image indexes (multi-arch images) and custom artifacts (ORAS), with a focus on:

  • Speed, only pulling artifacts that are needed at build-time (no more long image pull times)
  • Extensibility, creating custom artifacts to leverage standard OCI distribution APIs
  • Multi-arch images, compiling and building multi-arch images with a single Bazel invocation

In addition to Bazel rules, we offer many helpers for interacting with OCI artifacts under the go/pkg directory and a CLI tool for creating new OCI artifacts. You can add the Go library as a dependency by running go get github.com/DataDog/rules_oci/go@latest.

rules_oci makes an effort to support Docker media types, but there is no guarantee of long-term support. Most CRI support the OCI types or there are tools available to convert between the specifications.

Setup

# Load OCI Bootstrapping rules or copy the rule into your repository.
git_repository(
    name = "rules_oci_bootstrap",
    remote = "https://github.com/DataDog/rules_oci_bootstrap.git",
    commit = "75330296a80c4a5bfa228dc585ca9a9c3e56d45d",
)

load("@rules_oci_bootstrap//:defs.bzl", "oci_blob_pull")
oci_blob_pull(
    name = "com_github_datadog_rules_oci",
    digest = "sha256:cc6c59ed7da6bb376552461e06068f883bbe335359c122c15dce3c24e19cd8e2",
    extract = True,
    registry = "ghcr.io",
    repository = "datadog/rules_oci/rules",
    type = "tar.gz",
)

Docs

Rule API

Examples can be found in the tests directory.

How it works at a high level

At fetch-time we only pull down the manifest json that represents the structure of the image, rather than pull down everything -- we call this a shallow pull. We then modify the manifest and republish it with just the changed layers at "bazel run"-time.

This is perfect for the use-case of creating "application images", aka images where you just plop a binary on top of a base image. Some additional small changes can be done such as injecting a shared library or a config file.

We've found in most cases we don't need to pull these additional layers as they were pushed there previously or can copy (via the mount api) within the same registry.

This has the downside that there is no verification of all of the content in the image, but this trade-off is worth the speed of not downloaded many GBs of base images.

Roadmap

  • Flesh out code for non-shallow pulls and cases where the layers are coming from a different registry.
  • Full Starlark DSL for creating custom artifacts, it's currently looks a bit wonky
  • Support for the ORAS Artifact Spec
  • Support for custom artifact crawlers to pull artifacts that have children not represented by the OCI Image Spec. Ex pulling a full CNAB bundle and all dependencies.
  • Benchmark against rules_docker and raw docker build.

FAQ

Comparison to rules_docker

  • rules_docker is built on go-containerregistry, which is focused on Docker, rules_oci uses containerd whose implementation complies more to the OCI spec and more easily supports custom artifacts
  • rules_oci focused on supporting the OCI Image spec, rather than the Docker spec
  • rules_oci doesn't have language specific rules, instead a higher-level package can build on rules_oci to create rules like go_image
  • rules_docker doesn't have support for multi-arch images #1599

Developing

Updating dependencies

Run bazel run :go -- get DEPENDENCY && bazel run :gazelle-update-repos

Tests

Run the tests using

bazel run //:bootstrap
bazel test //...

You will also need to make it possible for docker to access ghcr.io (see the code in .github/workflows/main.yaml for what we do in CI; an equivalent method for local build using the gh CLI can be found here).

rules_oci's People

Contributors

abayer avatar ethan-lowman-dd avatar ethanfrogers avatar griffin avatar guyboltonking avatar iamricard avatar joneshf-dd avatar jprobinson avatar nguyening avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rules_oci's Issues

bazel-contrib rules_oci

Are you aware of https://github.com/bazel-contrib/rules_oci ?

It has some of the same philosophies/improvements as this project, and some of the former maintainers of rules_docker.

If there are significant differences, it would be helpful to call them out, in addition to differences with rules_docker.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.