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

fix: set runfiles and workdir for py3_image #176

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion {{ .ProjectSnake }}/tools/oci/py3_image.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,27 @@ load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup")
load("@aspect_rules_py//py:defs.bzl", "py_image_layer")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_load")

def py3_image(name, binary, root = "/", layer_groups = {}, base = "@python_base"):
def py3_image(name, binary, root = "/", layer_groups = {}, env = {}, workdir = None, base = "@python_base"):
"""Create a Python 3 image from a Python binary.

Args:
name: The name of the image.
binary: The Python binary to create the image from.
root: The root directory where everything will be put into
layer_groups: The layer groups to use for the image.
env: The environment variables to set in the image.
workdir: The working directory to set in the image.
base: The base image to use for the image.
"""
binary = native.package_relative_label(binary)
binary_path = "{}{}/{}".format(root, binary.package, binary.name)
runfiles_dir = "{}.runfiles".format(binary_path)
repo_name = binary.repo_name or "_main"
env = dict({
alexeagle marked this conversation as resolved.
Show resolved Hide resolved
"BAZEL_WORKSPACE": repo_name,
"RUNFILES_DIR": runfiles_dir,
}, **env)

oci_image(
name = name + "_image",
base = base,
Expand All @@ -17,6 +35,8 @@ def py3_image(name, binary, root = "/", layer_groups = {}, base = "@python_base"
layer_groups = layer_groups,
),
entrypoint = [binary_path],
env = env,
workdir = workdir or "{}/{}".format(runfiles_dir, repo_name),
)
platform_transition_filegroup(
name = name,
Expand Down
Loading