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

support passing label as container cli tool to bazel run //my/tarball #441

Merged
merged 6 commits into from
Jan 2, 2024

Conversation

jchorl
Copy link
Contributor

@jchorl jchorl commented Dec 15, 2023

Enables passing a label to oci_tarball which will be used to load the image into the local container engine.

Solves #295

Follows guidance from #430

I think it would be nice if oci_register_toolchains configured this, but I understand not wanting to clutter the configs.

To test:

WORKSPACE:

local_repository(
    name = "rules_oci",
    path = "/local/rules_oci",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")

rules_oci_dependencies()

load("@rules_oci//oci:repositories.bzl", "LATEST_CRANE_VERSION", "oci_register_toolchains")

oci_register_toolchains(
    name = "oci",
    crane_version = LATEST_CRANE_VERSION,
)

load("@rules_oci//oci:pull.bzl", "oci_pull")

oci_pull(
    name = "distroless_base",
    digest = "sha256:ccaef5ee2f1850270d453fdf700a5392534f8d1a8ca2acda391fbb6a06b81c86",
    image = "gcr.io/distroless/base",
    platforms = [
        "linux/amd64",
        "linux/arm64",
    ],
)

# from https://download.docker.com/linux/static/stable/x86_64/
http_archive(
    name = "docker_cli",
    url = "https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz",
    sha256 = "984d59a77fa6acab97ea725a966facd33725e0e09c2fee975397fe1c6379bd3d",
    build_file_content = """
exports_files(["docker/docker"])
    """
)

BUILD.bazel:

load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")

oci_image(
    name = "image",
    base = "@distroless_base",
    cmd = ["echo", "hi"],
)

oci_tarball(
    name = "tarball",
    image = ":image",
    repo_tags = ["jchorl/test:latest"],
    container_cli_tool = "@docker_cli//:docker/docker",
)
ubuntu@99ab9feb506a:/src/workspace$ bazel run //:tarball
INFO: Analyzed target //:tarball (1 packages loaded, 4 targets configured).
INFO: Found 1 target...
Target //:tarball up-to-date:
  bazel-bin/tarball/tarball.tar
INFO: Elapsed time: 0.046s, Critical Path: 0.00s
INFO: 4 processes: 4 internal.
INFO: Build completed successfully, 4 total actions
INFO: Running command line: bazel-bin/tarball.sh
Loaded image: jchorl/test:latest

oci/private/tarball.bzl Outdated Show resolved Hide resolved
@jchorl
Copy link
Contributor Author

jchorl commented Dec 20, 2023

Tested with

load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")

oci_image(
    name = "image",
    base = "@distroless_base",
    cmd = ["echo", "hi"],
)

oci_tarball(
    name = "tarball",
    image = ":image",
    repo_tags = ["jchorl/test:latest"],
    command = "@docker_cli//:docker/docker",
)

oci/private/tarball_run.sh.tpl Outdated Show resolved Hide resolved
@thesayyn
Copy link
Collaborator

You need to run; bazel run //docs:update_1

@jchorl
Copy link
Contributor Author

jchorl commented Dec 26, 2023

You need to run; bazel run //docs:update_1

Done

@thesayyn thesayyn merged commit e420a13 into bazel-contrib:main Jan 2, 2024
16 checks passed
alexeagle added a commit that referenced this pull request Jan 3, 2024
Followup to #441. I think 'command' is too vague, as it might seem to apply to the creation of the tarball under 'bazel build', and also doesn't say anything about what purpose the command has.
Also improve the docs around this pair of attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants