Skip to navigation

nemo_gym.tasks.harbor.harbor_compat

View as Markdown

Environment content hashing and image naming vendored from Harbor v0.22.0 (Apache-2.0).

Gym builds the images of Harbor tasks with its own tools (buildah, podman or docker; see nemo_gym.tasks.harbor.image_build) but hashes the task’s environment/ folder and names the image the way Harbor does, so a task prepared by either framework resolves to the same image name. Kept byte-for-byte so Gym and Harbor compute the same image names for the same build context.

Vendored from https://github.com/harbor-framework/harbor (Apache-2.0, see ATTRIBUTIONS.md):

Harbor’s environment id is environment_content_hash(environment_dir) and its task image is sanitize_docker_image_name(f"hb__{environment_id}"): hb__<32 hex characters>.

Module Contents

Functions

NameDescription
environment_content_hashReturn a stable SHA-256 hash of the environment contents.
sanitize_docker_image_nameSanitize a name to be a valid Docker image name.

Data

_CONTENT_HASH_IGNORE_NAMES

API

nemo_gym.tasks.harbor.harbor_compat.environment_content_hash(
environment_dir: pathlib.Path,
docker_image: str | None = None,
truncate: int = 32
) -> str

Return a stable SHA-256 hash of the environment contents.

The result is consistent across Linux and macOS. For an empty environment, the Docker image reference is hashed instead.

nemo_gym.tasks.harbor.harbor_compat.sanitize_docker_image_name(
name: str
) -> str
nemo_gym.tasks.harbor.harbor_compat._CONTENT_HASH_IGNORE_NAMES = frozenset({'.DS_Store', '.git', '__pycache__'})