metaflow-prebuilt 0.2.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metaflow_extensions/prebuilt/plugins/conda/__init__.py +0 -0
- metaflow_extensions/prebuilt/plugins/conda/build_service.py +76 -0
- metaflow_extensions/prebuilt/plugins/conda/image_registry.py +97 -0
- metaflow_extensions/prebuilt/plugins/conda/prebuilt_build_install.py +21 -0
- metaflow_extensions/prebuilt/plugins/conda/prebuilt_conda_environment.py +511 -0
- metaflow_extensions/prebuilt/plugins/conda/prebuilt_runtime_activate.py +101 -0
- metaflow_extensions/prebuilt/plugins/conda/registries/__init__.py +0 -0
- metaflow_extensions/prebuilt/plugins/conda/registries/dockerhub_registry.py +53 -0
- metaflow_extensions/prebuilt/plugins/conda/registries/ecr_registry.py +67 -0
- metaflow_extensions/prebuilt/plugins/conda/registries/gcr_registry.py +71 -0
- metaflow_extensions/prebuilt/plugins/conda/registries/local_registry.py +105 -0
- metaflow_extensions/prebuilt/plugins/conda/services/__init__.py +0 -0
- metaflow_extensions/prebuilt/plugins/conda/services/buildx_service.py +80 -0
- metaflow_extensions/prebuilt/plugins/conda/services/codebuild_service.py +131 -0
- metaflow_extensions/prebuilt/plugins/conda/services/docker_service.py +88 -0
- metaflow_extensions/prebuilt/plugins/conda/services/kaniko_service.py +218 -0
- metaflow_extensions/prebuilt/plugins/mfextinit_prebuilt.py +3 -0
- metaflow_prebuilt-0.2.1.dist-info/METADATA +198 -0
- metaflow_prebuilt-0.2.1.dist-info/RECORD +23 -0
- metaflow_prebuilt-0.2.1.dist-info/WHEEL +6 -0
- metaflow_prebuilt-0.2.1.dist-info/entry_points.txt +11 -0
- metaflow_prebuilt-0.2.1.dist-info/licenses/LICENSE +201 -0
- metaflow_prebuilt-0.2.1.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
import os
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import Any, Callable, Dict, TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
pass
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _resolve_entry_point(group: str, name: str) -> Any:
|
|
11
|
+
try:
|
|
12
|
+
eps = importlib.metadata.entry_points(group=group)
|
|
13
|
+
except TypeError:
|
|
14
|
+
# Python 3.8 compatibility
|
|
15
|
+
eps = importlib.metadata.entry_points().get(group, []) # type: ignore[assignment]
|
|
16
|
+
mapping = {ep.name: ep for ep in eps}
|
|
17
|
+
if name not in mapping:
|
|
18
|
+
from metaflow.exception import MetaflowException # noqa: PLC0415
|
|
19
|
+
|
|
20
|
+
raise MetaflowException(
|
|
21
|
+
"No entry point named %r in group %r. "
|
|
22
|
+
"Installed: %s. "
|
|
23
|
+
"Install the package that provides this backend or check "
|
|
24
|
+
"METAFLOW_PREBUILT_BUILD_SERVICE." % (name, group, sorted(mapping))
|
|
25
|
+
)
|
|
26
|
+
return mapping[name].load()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DockerBuildService(ABC):
|
|
30
|
+
"""Abstract base class for Docker image build-and-push backends.
|
|
31
|
+
|
|
32
|
+
Implement this class and register it under the
|
|
33
|
+
``metaflow_prebuilt.build_services`` entry point group to make it
|
|
34
|
+
selectable via ``METAFLOW_PREBUILT_BUILD_SERVICE=<name>``.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def build_and_push(
|
|
39
|
+
self,
|
|
40
|
+
dockerfile: str,
|
|
41
|
+
context_files: Dict[str, Any],
|
|
42
|
+
image_tag: str,
|
|
43
|
+
push_credentials: Dict[str, Any],
|
|
44
|
+
echo: Callable[..., None],
|
|
45
|
+
) -> bool:
|
|
46
|
+
"""Build a Docker image and push it to the registry.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
dockerfile: Full Dockerfile content.
|
|
50
|
+
context_files: Files to include in the build context alongside the
|
|
51
|
+
Dockerfile. Keys are filenames; values are ``str`` (text) or
|
|
52
|
+
``bytes`` (binary).
|
|
53
|
+
image_tag: Fully-qualified destination tag, e.g.
|
|
54
|
+
``registry.example.com/ns/name:v28-abc123``.
|
|
55
|
+
Provided by ``ImageRegistry.push_tag()``.
|
|
56
|
+
push_credentials: Opaque dict from ``ImageRegistry.push_credentials()``.
|
|
57
|
+
Schema is defined by the paired registry implementation.
|
|
58
|
+
echo: Callable for user-visible progress output.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
``True`` on success, ``False`` on recoverable failure.
|
|
62
|
+
Must NOT raise on recoverable failures — return ``False`` and
|
|
63
|
+
call ``echo()`` with a diagnostic. MAY raise on programmer errors.
|
|
64
|
+
"""
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def from_config(cls) -> "DockerBuildService":
|
|
69
|
+
"""Resolve and instantiate the build service selected by
|
|
70
|
+
``METAFLOW_PREBUILT_BUILD_SERVICE`` (default: ``docker``).
|
|
71
|
+
|
|
72
|
+
Raises ``MetaflowException`` if the name is not registered.
|
|
73
|
+
"""
|
|
74
|
+
name = os.environ.get("METAFLOW_PREBUILT_BUILD_SERVICE", "docker")
|
|
75
|
+
service_cls = _resolve_entry_point("metaflow_prebuilt.build_services", name)
|
|
76
|
+
return service_cls()
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from abc import ABC, abstractmethod
|
|
3
|
+
from typing import Any, Dict, TYPE_CHECKING
|
|
4
|
+
|
|
5
|
+
from .build_service import _resolve_entry_point
|
|
6
|
+
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from metaflow_extensions.nflx.plugins.conda.env_descr import EnvID
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ImageRegistry(ABC):
|
|
12
|
+
"""Abstract base class for Docker image registries.
|
|
13
|
+
|
|
14
|
+
Implement this class and register it under the
|
|
15
|
+
``metaflow_prebuilt.image_registries`` entry point group to make it
|
|
16
|
+
selectable via ``METAFLOW_PREBUILT_IMAGE_REGISTRY=<name>``.
|
|
17
|
+
|
|
18
|
+
For most registries ``push_tag()`` and ``pull_tag()`` both delegate to
|
|
19
|
+
``image_tag()`` — subclasses only need to implement ``image_tag()``.
|
|
20
|
+
Override ``push_tag()`` and/or ``pull_tag()`` independently only when the
|
|
21
|
+
push address differs from the pull address (e.g. ``LocalRegistry``).
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def image_tag(self, env_id: "EnvID") -> str:
|
|
26
|
+
"""Canonical fully-qualified image tag for the given env_id.
|
|
27
|
+
|
|
28
|
+
Used as the default return value for both ``push_tag()`` and
|
|
29
|
+
``pull_tag()``. Format: ``<registry>/<namespace>/<name>:<version>``.
|
|
30
|
+
"""
|
|
31
|
+
...
|
|
32
|
+
|
|
33
|
+
def push_tag(self, env_id: "EnvID") -> str:
|
|
34
|
+
"""Tag the build service uses to push. Defaults to ``image_tag()``."""
|
|
35
|
+
return self.image_tag(env_id)
|
|
36
|
+
|
|
37
|
+
def pull_tag(self, env_id: "EnvID") -> str:
|
|
38
|
+
"""Tag baked into the remote runner spec. Defaults to ``image_tag()``."""
|
|
39
|
+
return self.image_tag(env_id)
|
|
40
|
+
|
|
41
|
+
def image_tag_for_named(self, name: str) -> str:
|
|
42
|
+
"""Full mutable tag for a ``@named_env(fetch_at_exec=True)`` env.
|
|
43
|
+
|
|
44
|
+
Tagged by alias name (not env_id hash) so subsequent deploys under the
|
|
45
|
+
same name overwrite the manifest — matching fetch_at_exec semantics.
|
|
46
|
+
|
|
47
|
+
Raises ``NotImplementedError`` by default; registries that support named
|
|
48
|
+
envs must override this method.
|
|
49
|
+
"""
|
|
50
|
+
raise NotImplementedError(
|
|
51
|
+
"Registry %r does not implement named env tags. "
|
|
52
|
+
"Override image_tag_for_named() to use @named_env(fetch_at_exec=True)."
|
|
53
|
+
% type(self).__name__
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def push_tag_for_named(self, name: str) -> str:
|
|
57
|
+
"""Push-side tag for a named env. Defaults to ``image_tag_for_named()``."""
|
|
58
|
+
return self.image_tag_for_named(name)
|
|
59
|
+
|
|
60
|
+
def pull_tag_for_named(self, name: str) -> str:
|
|
61
|
+
"""Pull-side tag for a named env. Defaults to ``push_tag_for_named()``."""
|
|
62
|
+
return self.push_tag_for_named(name)
|
|
63
|
+
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def push_credentials(self) -> Dict[str, Any]:
|
|
66
|
+
"""Credentials/config passed to ``DockerBuildService.build_and_push``.
|
|
67
|
+
|
|
68
|
+
Return ``{}`` when the build service uses ambient auth (e.g. docker login).
|
|
69
|
+
The schema is build-service-specific; see the ``DockerBuildService``
|
|
70
|
+
contract for which keys each service consumes.
|
|
71
|
+
"""
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def pull_config(self, pull_tag: str) -> Dict[str, Any]:
|
|
76
|
+
"""Attributes to inject into the remote runner decorator so it can pull
|
|
77
|
+
the image at ``pull_tag``.
|
|
78
|
+
|
|
79
|
+
Return ``{}`` when the runner has ambient pull credentials (e.g. an IAM
|
|
80
|
+
role for ECR + Batch, or a service account for GKE).
|
|
81
|
+
|
|
82
|
+
Non-empty example (private registry with K8s imagePullSecrets)::
|
|
83
|
+
|
|
84
|
+
{"image_pull_policy": "Always", "image_pull_secrets": "my-secret"}
|
|
85
|
+
"""
|
|
86
|
+
...
|
|
87
|
+
|
|
88
|
+
@classmethod
|
|
89
|
+
def from_config(cls) -> "ImageRegistry":
|
|
90
|
+
"""Resolve and instantiate the registry selected by
|
|
91
|
+
``METAFLOW_PREBUILT_IMAGE_REGISTRY`` (default: ``dockerhub``).
|
|
92
|
+
|
|
93
|
+
Raises ``MetaflowException`` if the name is not registered.
|
|
94
|
+
"""
|
|
95
|
+
name = os.environ.get("METAFLOW_PREBUILT_IMAGE_REGISTRY", "dockerhub")
|
|
96
|
+
registry_cls = _resolve_entry_point("metaflow_prebuilt.image_registries", name)
|
|
97
|
+
return registry_cls()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Build-time conda installer stub.
|
|
3
|
+
|
|
4
|
+
This module is intentionally empty in the OSS metaflow-prebuilt package.
|
|
5
|
+
The real implementation lives alongside the conda stack (e.g. nflx-metaflow's
|
|
6
|
+
metaflow_extensions.nflx.plugins.conda.prebuilt_build_install), which
|
|
7
|
+
imports the Conda class and related utilities needed to install the env.
|
|
8
|
+
|
|
9
|
+
Set PrebuiltCondaEnvironment._BUILD_INSTALL_MODULE to the package that
|
|
10
|
+
provides the real prebuilt_build_install module.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
if __name__ == "__main__":
|
|
16
|
+
print(
|
|
17
|
+
"ERROR: This is a stub. Configure PrebuiltCondaEnvironment._BUILD_INSTALL_MODULE "
|
|
18
|
+
"to point to a real prebuilt_build_install implementation.",
|
|
19
|
+
file=sys.stderr,
|
|
20
|
+
)
|
|
21
|
+
sys.exit(1)
|