Docker ships with both a container runtime and a "build system" for creating images, using Dockerfile.
A Dockerfile consists of multiple instructions and stages. Most of the time FROM, COPY, and RUN
instructions which mutate the rootfs by adding or deleting files.
rules_oci cannot use Dockerfile to describe the build.
We think it's possible in theory, but such an effort would require some dedicated funding.
Most of the Dockerfile operators can be replaced with rules_oci, but it looks different.
Let's compare them to their rules_oci counterparts:
ADD-> Package the files usingtar()orpkg_tar()and useoci_image#layersARG-> Not supportedCMD-> Useoci_image#cmdCOPY-> Not supportedENTRYPOINT-> Useoci_image#entrypointENV-> Useoci_image#envEXPOSE-> Useoci_image#exposed_portsFROM-> Useoci_pullHEALTHCHECK-> Not supportedLABEL-> Useoci_image#labelsMAINTAINER-> Not supportedONBUILD-> Not supportedRUN-> See: #132SHELL-> Useoci_image#entrypointinstead.STOPSIGNAL-> Not supportedUSER-> Not supported. Use the tar rule's mechanism for setting gid/uidVOLUME-> Useoci_image#volumesWORKDIR-> Useoci_image#workdir
References:
- https://docs.docker.com/engine/reference/builder/#overview
- https://github.com/bazel-contrib/rules_oci/blob/main/docs/image.md
- https://github.com/bazel-contrib/rules_oci/blob/main/docs/pull.md
- https://github.com/aspect-build/bazel-lib/blob/main/docs/tar.md
Given the replacements above, with a Dockerfile that looks like this
FROM gcr.io/distroless/static-debian11@sha256:f4787e810dbc39dd59fcee319cf88e8a01181e1758dbd07c32ed4e14a9ba8904
COPY --from=0 /web-assets/ /
WORKDIR /
ENTRYPOINT ["/web-assets"]- Use
oci_pullto pull the base image.
oci_pull(
name = "distroless_static",
digest = "sha256:f4787e810dbc39dd59fcee319cf88e8a01181e1758dbd07c32ed4e14a9ba8904",
image = "gcr.io/distroless/static-debian11",
platforms = [
"linux/amd64",
"linux/arm64",
],
)- Replace
COPYwithtar.
load("@tar.bzl", "tar")
tar(
name = "web_assets",
srcs = glob(["web-assets/**"]),
compress = "gzip",
)- The resulting
BUILDfile would look like:
load("@tar.bzl", "tar")
tar(
name = "web_assets",
srcs = glob(["web-assets/**"]),
compress = "gzip",
)
oci_image(
name = "app",
base = "@distroless_static",
layers = [
":web_assets"
],
workdir = "/",
entrypoint = ["/web-assets"]
)Long story short, rules_oci doesn't have a replacement for it and the reason is that RUN requires us to depend
on a running Container Daemon to work, and is non-hermetic.
See: #35
That said, instructions like apk add xyz and apt-get install xyz is supported by other rulesets.