ob-metaflow-extensions 1.1.170__py2.py3-none-any.whl → 1.4.35__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.

Potentially problematic release.


This version of ob-metaflow-extensions might be problematic. Click here for more details.

Files changed (65) hide show
  1. metaflow_extensions/outerbounds/plugins/__init__.py +6 -2
  2. metaflow_extensions/outerbounds/plugins/apps/app_cli.py +0 -0
  3. metaflow_extensions/outerbounds/plugins/apps/app_deploy_decorator.py +146 -0
  4. metaflow_extensions/outerbounds/plugins/apps/core/__init__.py +10 -0
  5. metaflow_extensions/outerbounds/plugins/apps/core/_state_machine.py +506 -0
  6. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/__init__.py +0 -0
  7. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/spinner/__init__.py +4 -0
  8. metaflow_extensions/outerbounds/plugins/apps/core/_vendor/spinner/spinners.py +478 -0
  9. metaflow_extensions/outerbounds/plugins/apps/core/app_cli.py +1200 -0
  10. metaflow_extensions/outerbounds/plugins/apps/core/app_config.py +146 -0
  11. metaflow_extensions/outerbounds/plugins/apps/core/artifacts.py +0 -0
  12. metaflow_extensions/outerbounds/plugins/apps/core/capsule.py +958 -0
  13. metaflow_extensions/outerbounds/plugins/apps/core/click_importer.py +24 -0
  14. metaflow_extensions/outerbounds/plugins/apps/core/code_package/__init__.py +3 -0
  15. metaflow_extensions/outerbounds/plugins/apps/core/code_package/code_packager.py +618 -0
  16. metaflow_extensions/outerbounds/plugins/apps/core/code_package/examples.py +125 -0
  17. metaflow_extensions/outerbounds/plugins/apps/core/config/__init__.py +12 -0
  18. metaflow_extensions/outerbounds/plugins/apps/core/config/cli_generator.py +161 -0
  19. metaflow_extensions/outerbounds/plugins/apps/core/config/config_utils.py +868 -0
  20. metaflow_extensions/outerbounds/plugins/apps/core/config/schema_export.py +288 -0
  21. metaflow_extensions/outerbounds/plugins/apps/core/config/typed_configs.py +139 -0
  22. metaflow_extensions/outerbounds/plugins/apps/core/config/typed_init_generator.py +398 -0
  23. metaflow_extensions/outerbounds/plugins/apps/core/config/unified_config.py +1088 -0
  24. metaflow_extensions/outerbounds/plugins/apps/core/config_schema.yaml +337 -0
  25. metaflow_extensions/outerbounds/plugins/apps/core/dependencies.py +115 -0
  26. metaflow_extensions/outerbounds/plugins/apps/core/deployer.py +303 -0
  27. metaflow_extensions/outerbounds/plugins/apps/core/experimental/__init__.py +89 -0
  28. metaflow_extensions/outerbounds/plugins/apps/core/perimeters.py +87 -0
  29. metaflow_extensions/outerbounds/plugins/apps/core/secrets.py +164 -0
  30. metaflow_extensions/outerbounds/plugins/apps/core/utils.py +233 -0
  31. metaflow_extensions/outerbounds/plugins/apps/core/validations.py +17 -0
  32. metaflow_extensions/outerbounds/plugins/aws/assume_role_decorator.py +25 -12
  33. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/coreweave.py +9 -77
  34. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/external_chckpt.py +85 -0
  35. metaflow_extensions/outerbounds/plugins/checkpoint_datastores/nebius.py +7 -78
  36. metaflow_extensions/outerbounds/plugins/fast_bakery/baker.py +110 -0
  37. metaflow_extensions/outerbounds/plugins/fast_bakery/docker_environment.py +6 -2
  38. metaflow_extensions/outerbounds/plugins/fast_bakery/fast_bakery.py +1 -0
  39. metaflow_extensions/outerbounds/plugins/nvct/nvct_decorator.py +8 -8
  40. metaflow_extensions/outerbounds/plugins/optuna/__init__.py +48 -0
  41. metaflow_extensions/outerbounds/plugins/profilers/simple_card_decorator.py +96 -0
  42. metaflow_extensions/outerbounds/plugins/s3_proxy/__init__.py +7 -0
  43. metaflow_extensions/outerbounds/plugins/s3_proxy/binary_caller.py +132 -0
  44. metaflow_extensions/outerbounds/plugins/s3_proxy/constants.py +11 -0
  45. metaflow_extensions/outerbounds/plugins/s3_proxy/exceptions.py +13 -0
  46. metaflow_extensions/outerbounds/plugins/s3_proxy/proxy_bootstrap.py +59 -0
  47. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_api.py +93 -0
  48. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_decorator.py +250 -0
  49. metaflow_extensions/outerbounds/plugins/s3_proxy/s3_proxy_manager.py +225 -0
  50. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_client.py +6 -3
  51. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_decorator.py +13 -7
  52. metaflow_extensions/outerbounds/plugins/snowpark/snowpark_job.py +8 -2
  53. metaflow_extensions/outerbounds/plugins/torchtune/__init__.py +4 -0
  54. metaflow_extensions/outerbounds/plugins/vllm/__init__.py +173 -95
  55. metaflow_extensions/outerbounds/plugins/vllm/status_card.py +9 -9
  56. metaflow_extensions/outerbounds/plugins/vllm/vllm_manager.py +159 -9
  57. metaflow_extensions/outerbounds/remote_config.py +8 -3
  58. metaflow_extensions/outerbounds/toplevel/global_aliases_for_metaflow_package.py +63 -1
  59. metaflow_extensions/outerbounds/toplevel/ob_internal.py +3 -0
  60. metaflow_extensions/outerbounds/toplevel/plugins/optuna/__init__.py +1 -0
  61. metaflow_extensions/outerbounds/toplevel/s3_proxy.py +88 -0
  62. {ob_metaflow_extensions-1.1.170.dist-info → ob_metaflow_extensions-1.4.35.dist-info}/METADATA +2 -2
  63. {ob_metaflow_extensions-1.1.170.dist-info → ob_metaflow_extensions-1.4.35.dist-info}/RECORD +65 -21
  64. {ob_metaflow_extensions-1.1.170.dist-info → ob_metaflow_extensions-1.4.35.dist-info}/WHEEL +0 -0
  65. {ob_metaflow_extensions-1.1.170.dist-info → ob_metaflow_extensions-1.4.35.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,110 @@
1
+ import threading
2
+ import time
3
+ import sys
4
+ from typing import Dict, Optional, Any, Callable
5
+ from functools import partial
6
+ from metaflow.exception import MetaflowException
7
+ from metaflow.metaflow_config import FAST_BAKERY_URL
8
+
9
+ from .fast_bakery import FastBakery, FastBakeryApiResponse, FastBakeryException
10
+ from .docker_environment import cache_request
11
+
12
+ BAKERY_METAFILE = ".imagebakery-cache"
13
+
14
+
15
+ class BakerException(MetaflowException):
16
+ headline = "Ran into an error while baking image"
17
+
18
+ def __init__(self, msg):
19
+ super(BakerException, self).__init__(msg)
20
+
21
+
22
+ def bake_image(
23
+ cache_file_path: str,
24
+ ref: Optional[str] = None,
25
+ python: Optional[str] = None,
26
+ pypi_packages: Optional[Dict[str, str]] = None,
27
+ conda_packages: Optional[Dict[str, str]] = None,
28
+ base_image: Optional[str] = None,
29
+ logger: Optional[Callable[[str], Any]] = None,
30
+ ) -> FastBakeryApiResponse:
31
+ """
32
+ Bakes a Docker image with the specified dependencies.
33
+
34
+ Args:
35
+ cache_file_path: Path to the cache file
36
+ ref: Reference identifier for this bake (for logging purposes)
37
+ python: Python version to use
38
+ pypi_packages: Dictionary of PyPI packages and versions
39
+ conda_packages: Dictionary of Conda packages and versions
40
+ base_image: Base Docker image to use
41
+ logger: Optional logger function to output progress
42
+
43
+ Returns:
44
+ FastBakeryApiResponse: The response from the bakery service
45
+
46
+ Raises:
47
+ BakerException: If the baking process fails
48
+ """
49
+ # Default logger if none provided
50
+ if logger is None:
51
+ logger = partial(print, file=sys.stderr)
52
+
53
+ # Thread lock for logging
54
+ logger_lock = threading.Lock()
55
+ images_baked = 0
56
+
57
+ @cache_request(cache_file_path)
58
+ def _cached_bake(
59
+ ref=None,
60
+ python=None,
61
+ pypi_packages=None,
62
+ conda_packages=None,
63
+ base_image=None,
64
+ ):
65
+ try:
66
+ bakery = FastBakery(url=FAST_BAKERY_URL)
67
+ bakery._reset_payload()
68
+ bakery.python_version(python)
69
+ bakery.pypi_packages(pypi_packages)
70
+ bakery.conda_packages(conda_packages)
71
+ bakery.base_image(base_image)
72
+ # bakery.ignore_cache()
73
+
74
+ with logger_lock:
75
+ logger(f"🍳 Baking [{ref}] ...")
76
+ logger(f" 🐍 Python: {python}")
77
+
78
+ if pypi_packages:
79
+ logger(f" 📦 PyPI packages:")
80
+ for package, version in pypi_packages.items():
81
+ logger(f" 🔧 {package}: {version}")
82
+
83
+ if conda_packages:
84
+ logger(f" 📦 Conda packages:")
85
+ for package, version in conda_packages.items():
86
+ logger(f" 🔧 {package}: {version}")
87
+
88
+ logger(f" 🏗️ Base image: {base_image}")
89
+
90
+ start_time = time.time()
91
+ res = bakery.bake()
92
+ # TODO: Get actual bake time from bakery
93
+ bake_time = time.time() - start_time
94
+
95
+ with logger_lock:
96
+ logger(f"🏁 Baked [{ref}] in {bake_time:.2f} seconds!")
97
+ nonlocal images_baked
98
+ images_baked += 1
99
+ return res
100
+ except FastBakeryException as ex:
101
+ raise BakerException(f"Bake [{ref}] failed: {str(ex)}")
102
+
103
+ # Call the cached bake function with the provided parameters
104
+ return _cached_bake(
105
+ ref=ref,
106
+ python=python,
107
+ pypi_packages=pypi_packages,
108
+ conda_packages=conda_packages,
109
+ base_image=base_image,
110
+ )
@@ -351,12 +351,16 @@ class DockerEnvironment(MetaflowEnvironment):
351
351
  config.append("--disable=F0401")
352
352
  return config
353
353
 
354
- def get_package_commands(self, codepackage_url, datastore_type):
354
+ def get_package_commands(
355
+ self, codepackage_url, datastore_type, code_package_metadata=None
356
+ ):
355
357
  # we must set the skip install flag at this stage in order to skip package downloads,
356
358
  # doing so in bootstrap_commands is too late in the lifecycle.
357
359
  return [
358
360
  "export METAFLOW_SKIP_INSTALL_DEPENDENCIES=$FASTBAKERY_IMAGE",
359
- ] + super().get_package_commands(codepackage_url, datastore_type)
361
+ ] + super().get_package_commands(
362
+ codepackage_url, datastore_type, code_package_metadata=code_package_metadata
363
+ )
360
364
 
361
365
  def bootstrap_commands(self, step_name, datastore_type):
362
366
  if step_name in self.skipped_steps:
@@ -122,6 +122,7 @@ class FastBakery:
122
122
  "responseMaxAgeSeconds": 0,
123
123
  "layerMaxAgeSeconds": 0,
124
124
  "baseImageMaxAgeSeconds": 0,
125
+ "overwriteExistingLayers": True, # Used primarily to rewrite possibly corrupted layers.
125
126
  }
126
127
  return self
127
128
 
@@ -46,23 +46,23 @@ SUPPORTABLE_GPU_TYPES = {
46
46
  "H100": [
47
47
  {
48
48
  "n_gpus": 1,
49
- "instance_type": "GCP.GPU.H100_1x",
50
- "backend": "gcp-asia-se-1a",
49
+ "instance_type": "OCI.GPU.H100_1x",
50
+ "backend": "nvcf-dgxc-k8s-oci-nrt-prd8",
51
51
  },
52
52
  {
53
53
  "n_gpus": 2,
54
- "instance_type": "GCP.GPU.H100_2x",
55
- "backend": "gcp-asia-se-1a",
54
+ "instance_type": "OCI.GPU.H100_2x",
55
+ "backend": "nvcf-dgxc-k8s-oci-nrt-prd8",
56
56
  },
57
57
  {
58
58
  "n_gpus": 4,
59
- "instance_type": "GCP.GPU.H100_4x",
60
- "backend": "gcp-asia-se-1a",
59
+ "instance_type": "OCI.GPU.H100_4x",
60
+ "backend": "nvcf-dgxc-k8s-oci-nrt-prd8",
61
61
  },
62
62
  {
63
63
  "n_gpus": 8,
64
- "instance_type": "GCP.GPU.H100_8x",
65
- "backend": "gcp-asia-se-1a",
64
+ "instance_type": "OCI.GPU.H100_8x",
65
+ "backend": "nvcf-dgxc-k8s-oci-nrt-prd8",
66
66
  },
67
67
  ],
68
68
  "NEBIUS_H100": [
@@ -0,0 +1,48 @@
1
+ import os
2
+ import json
3
+
4
+ __mf_promote_submodules__ = ["plugins.optuna"]
5
+
6
+
7
+ def auth():
8
+ from metaflow.metaflow_config_funcs import init_config
9
+
10
+ conf = init_config()
11
+ if conf:
12
+ headers = {"x-api-key": conf["METAFLOW_SERVICE_AUTH_KEY"]}
13
+ else:
14
+ headers = json.loads(os.environ["METAFLOW_SERVICE_HEADERS"])
15
+ return headers
16
+
17
+
18
+ def get_deployment_db_access_endpoint(name: str):
19
+ from ..apps.core.perimeters import PerimeterExtractor
20
+ from ..apps.core.capsule import CapsuleApi
21
+
22
+ perimeter, cap_url = PerimeterExtractor.during_metaflow_execution()
23
+ deployment = CapsuleApi(cap_url, perimeter).get_by_name(name)
24
+ if not deployment:
25
+ raise Exception(f"No app deployment found with name `{name}`")
26
+
27
+ if (
28
+ "status" in deployment
29
+ and "accessInfo" in deployment["status"]
30
+ and "extraAccessUrls" in deployment["status"]["accessInfo"]
31
+ ):
32
+ for extra_url in deployment["status"]["accessInfo"]["extraAccessUrls"]:
33
+ if extra_url["name"] == "in_cluster_db_access":
34
+ db_url = extra_url["url"].replace("http://", "")
35
+ return db_url
36
+
37
+ raise Exception(f"No db access endpoint found for deployment `{name}`")
38
+
39
+
40
+ def get_db_url(app_name: str):
41
+ """
42
+ Example usage:
43
+ >>> from metaflow.plugins.optuna import get_db_url
44
+ >>> s = optuna.create_study(..., storage=get_db_url("optuna-dashboard"))
45
+ """
46
+ mf_token = auth()["x-api-key"]
47
+ app_url = get_deployment_db_access_endpoint(app_name)
48
+ return f"postgresql://userspace_default:{mf_token}@{app_url}/userspace_default?sslmode=disable"
@@ -0,0 +1,96 @@
1
+ from datetime import datetime
2
+ from metaflow.decorators import StepDecorator
3
+ from ..card_utilities.injector import CardDecoratorInjector
4
+
5
+
6
+ class DynamicCardAppendDecorator(StepDecorator):
7
+ """
8
+ A simple decorator that demonstrates using CardDecoratorInjector
9
+ to inject a card and render simple markdown content.
10
+ """
11
+
12
+ name = "test_append_card"
13
+
14
+ defaults = {
15
+ "title": "Simple Card",
16
+ "message": "Hello from DynamicCardAppendDecorator!",
17
+ "show_timestamp": True,
18
+ "refresh_interval": 5,
19
+ }
20
+
21
+ CARD_ID = "simple_card"
22
+
23
+ def step_init(
24
+ self, flow, graph, step_name, decorators, environment, flow_datastore, logger
25
+ ):
26
+ """Initialize the decorator and inject the card."""
27
+ self.deco_injector = CardDecoratorInjector()
28
+ self.deco_injector.attach_card_decorator(
29
+ flow,
30
+ step_name,
31
+ self.CARD_ID,
32
+ "blank",
33
+ refresh_interval=self.attributes["refresh_interval"],
34
+ )
35
+
36
+ def task_decorate(
37
+ self, step_func, flow, graph, retry_count, max_user_code_retries, ubf_context
38
+ ):
39
+ """Decorate the step function to add card content."""
40
+ from metaflow import current
41
+ from metaflow.cards import Markdown
42
+
43
+ # Create the card content
44
+ title = self.attributes["title"]
45
+ message = self.attributes["message"]
46
+ show_timestamp = self.attributes["show_timestamp"]
47
+
48
+ # Add title to the card
49
+ current.card[self.CARD_ID].append(Markdown(f"# {title}"))
50
+
51
+ # Add message to the card
52
+ current.card[self.CARD_ID].append(Markdown(f"**Message:** {message}"))
53
+
54
+ # Add timestamp if requested
55
+ if show_timestamp:
56
+ timestamp = datetime.now().astimezone().strftime("%Y-%m-%d %H:%M:%S %z")
57
+ current.card[self.CARD_ID].append(Markdown(f"**Created at:** {timestamp}"))
58
+
59
+ # Add step information
60
+ current.card[self.CARD_ID].append(Markdown(f"**Step:** `{current.pathspec}`"))
61
+
62
+ # Add a simple divider
63
+ current.card[self.CARD_ID].append(Markdown("---"))
64
+
65
+ # Add some dynamic content that shows this is working
66
+ current.card[self.CARD_ID].append(
67
+ Markdown("**Status:** Card successfully injected! 🎉")
68
+ )
69
+
70
+ def wrapped_step_func():
71
+ """Execute the original step function."""
72
+ try:
73
+ # Before execution
74
+ current.card[self.CARD_ID].append(
75
+ Markdown("**Execution:** Step started...")
76
+ )
77
+ current.card[self.CARD_ID].refresh()
78
+
79
+ # Execute the original step
80
+ step_func()
81
+
82
+ # After execution
83
+ current.card[self.CARD_ID].append(
84
+ Markdown("**Execution:** Step completed successfully! ✅")
85
+ )
86
+ current.card[self.CARD_ID].refresh()
87
+
88
+ except Exception as e:
89
+ # Handle errors
90
+ current.card[self.CARD_ID].append(
91
+ Markdown(f"**Error:** Step failed with error: `{str(e)}` ❌")
92
+ )
93
+ current.card[self.CARD_ID].refresh()
94
+ raise
95
+
96
+ return wrapped_step_func
@@ -0,0 +1,7 @@
1
+ from .s3_proxy_decorator import (
2
+ S3ProxyDecorator,
3
+ NebiusS3ProxyDecorator,
4
+ CoreWeaveS3ProxyDecorator,
5
+ )
6
+
7
+ __all__ = ["S3ProxyDecorator", "NebiusS3ProxyDecorator", "CoreWeaveS3ProxyDecorator"]
@@ -0,0 +1,132 @@
1
+ import sys
2
+ import os
3
+ import subprocess
4
+ from metaflow.mflog.mflog import decorate
5
+ from metaflow.mflog import TASK_LOG_SOURCE
6
+ from typing import Union, TextIO, BinaryIO, Callable, Optional
7
+ from queue import Queue, Empty
8
+ from concurrent.futures import ThreadPoolExecutor
9
+ import subprocess
10
+
11
+
12
+ def enqueue_output(file, queue):
13
+ for line in iter(file.readline, ""):
14
+ queue.put(line)
15
+ file.close()
16
+
17
+
18
+ def read_popen_pipes(p: subprocess.Popen):
19
+
20
+ with ThreadPoolExecutor(2) as pool:
21
+ q_stdout, q_stderr = Queue(), Queue()
22
+ pool.submit(enqueue_output, p.stdout, q_stdout)
23
+ pool.submit(enqueue_output, p.stderr, q_stderr)
24
+ while True:
25
+
26
+ if p.poll() is not None and q_stdout.empty() and q_stderr.empty():
27
+ break
28
+
29
+ out_line = err_line = ""
30
+
31
+ try:
32
+ out_line = q_stdout.get_nowait()
33
+ except Empty:
34
+ pass
35
+ try:
36
+ err_line = q_stderr.get_nowait()
37
+ except Empty:
38
+ pass
39
+
40
+ yield (out_line, err_line)
41
+
42
+
43
+ class LogBroadcaster:
44
+ def __init__(
45
+ self,
46
+ process: subprocess.Popen,
47
+ ):
48
+ self._process = process
49
+ self._file_descriptors_and_parsers = []
50
+
51
+ def add_channel(
52
+ self, file_path: str, parser: Optional[Callable[[str], str]] = None
53
+ ):
54
+ self._file_descriptors_and_parsers.append((open(file_path, "a"), parser))
55
+
56
+ def _broadcast_lines(self, out_line: str, err_line: str):
57
+ for file_descriptor, parser in self._file_descriptors_and_parsers:
58
+ if out_line != "":
59
+ if parser:
60
+ out_line = parser(out_line)
61
+ print(out_line, file=file_descriptor, end="", flush=True)
62
+ if err_line != "":
63
+ if parser:
64
+ err_line = parser(err_line)
65
+ print(err_line, file=file_descriptor, end="", flush=True)
66
+
67
+ def publish_line(self, out_line: str, err_line: str):
68
+ self._broadcast_lines(out_line, err_line)
69
+
70
+ def broadcast_logs_to_files(self):
71
+ for out_line, err_line in read_popen_pipes(self._process):
72
+ self._broadcast_lines(out_line, err_line)
73
+
74
+ self._process.wait()
75
+
76
+ for file_descriptor, _ in self._file_descriptors_and_parsers:
77
+ file_descriptor.close()
78
+
79
+
80
+ def run_with_mflog_capture(command, debug=False):
81
+ """
82
+ Run a subprocess with proper mflog integration for stdout/stderr capture.
83
+ This mimics what bash_capture_logs does but in Python.
84
+ """
85
+ # Get the log file paths from environment variables
86
+ stdout_path = os.environ.get("MFLOG_STDOUT")
87
+ stderr_path = os.environ.get("MFLOG_STDERR")
88
+
89
+ if not stdout_path or not stderr_path:
90
+ # Fallback to regular subprocess if mflog env vars aren't set
91
+ return subprocess.run(command, check=True, shell=True)
92
+
93
+ pipe = subprocess.PIPE if debug else subprocess.DEVNULL
94
+ # Start the subprocess with pipes
95
+ process = subprocess.Popen(
96
+ command,
97
+ shell=True,
98
+ stdout=pipe,
99
+ stderr=pipe,
100
+ text=False, # Use bytes for proper mflog handling
101
+ bufsize=0, # Unbuffered for real-time logging
102
+ )
103
+
104
+ broadcaster = LogBroadcaster(process)
105
+
106
+ broadcaster.add_channel(
107
+ stderr_path, lambda line: decorate(TASK_LOG_SOURCE, line).decode("utf-8")
108
+ )
109
+ broadcaster.publish_line(f"[S3 PROXY] Starting Fast S3 Proxy.....\n", "")
110
+ broadcaster.broadcast_logs_to_files()
111
+
112
+ # Check the return code and raise if non-zero
113
+ if process.returncode != 0:
114
+ raise subprocess.CalledProcessError(process.returncode, command)
115
+
116
+ return process.returncode
117
+
118
+
119
+ if __name__ == "__main__":
120
+ s3_proxy_binary_path = os.environ.get("S3_PROXY_BINARY_COMMAND")
121
+ s3_proxy_debug = bool(os.environ.get("S3_PROXY_BINARY_DEBUG", False))
122
+ if not s3_proxy_binary_path:
123
+ print("S3_PROXY_BINARY_COMMAND environment variable not set")
124
+ sys.exit(1)
125
+
126
+ try:
127
+ run_with_mflog_capture(s3_proxy_binary_path, debug=s3_proxy_debug)
128
+ except subprocess.CalledProcessError as e:
129
+ sys.exit(e.returncode)
130
+ except Exception as e:
131
+ print(f"Error running S3 proxy binary: {e}", file=sys.stderr)
132
+ sys.exit(1)
@@ -0,0 +1,11 @@
1
+ S3_PROXY_BINARY_URLS = {
2
+ "aarch64": "https://fast-s3-proxy.outerbounds.sh/linux-arm64/s3-proxy-0.1.1.gz",
3
+ "x86_64": "https://fast-s3-proxy.outerbounds.sh/linux-amd64/s3-proxy-0.1.1.gz",
4
+ }
5
+
6
+ DEFAULT_PROXY_PORT = 8081
7
+ DEFAULT_PROXY_HOST = "localhost"
8
+ S3_PROXY_WRITE_MODES = [
9
+ "origin-and-cache",
10
+ "origin",
11
+ ]
@@ -0,0 +1,13 @@
1
+ from metaflow.exception import MetaflowException
2
+
3
+
4
+ class S3ProxyException(MetaflowException):
5
+ headline = "S3 Proxy Error"
6
+
7
+
8
+ class S3ProxyConfigException(S3ProxyException):
9
+ headline = "S3 Proxy Configuration Error"
10
+
11
+
12
+ class S3ProxyApiException(S3ProxyException):
13
+ headline = "S3 Proxy API Error"
@@ -0,0 +1,59 @@
1
+ from .s3_proxy_manager import S3ProxyManager
2
+ from metaflow._vendor import click
3
+ from metaflow import JSONType
4
+ import json
5
+
6
+
7
+ @click.group()
8
+ def cli():
9
+ pass
10
+
11
+
12
+ @cli.command()
13
+ @click.option(
14
+ "--integration-name", type=str, help="The integration name", required=True
15
+ )
16
+ @click.option("--write-mode", type=str, help="The write mode")
17
+ @click.option("--debug", type=bool, help="The debug mode", default=False)
18
+ @click.option(
19
+ "--uc-proxy-cfg-write-path",
20
+ type=str,
21
+ help="The path to write the user code proxy config",
22
+ required=True,
23
+ )
24
+ @click.option(
25
+ "--proxy-status-write-path",
26
+ type=str,
27
+ help="The path to write the proxy status",
28
+ required=True,
29
+ )
30
+ def bootstrap(
31
+ integration_name,
32
+ write_mode,
33
+ debug,
34
+ uc_proxy_cfg_write_path,
35
+ proxy_status_write_path,
36
+ ):
37
+ manager = S3ProxyManager(
38
+ integration_name=integration_name,
39
+ write_mode=write_mode,
40
+ debug=debug,
41
+ )
42
+ user_code_proxy_config, proxy_pid, config_path, binary_path = manager.setup_proxy()
43
+ with open(uc_proxy_cfg_write_path, "w") as f:
44
+ f.write(json.dumps(user_code_proxy_config))
45
+ with open(proxy_status_write_path, "w") as f:
46
+ f.write(
47
+ json.dumps(
48
+ {
49
+ "proxy_pid": proxy_pid,
50
+ "config_path": config_path,
51
+ "binary_path": binary_path,
52
+ }
53
+ )
54
+ )
55
+
56
+
57
+ if __name__ == "__main__":
58
+ print("[@s3_proxy] Jumpstarting the proxy....")
59
+ cli()
@@ -0,0 +1,93 @@
1
+ import json
2
+ import time
3
+ from typing import Dict, Optional
4
+
5
+ from .exceptions import S3ProxyConfigException, S3ProxyApiException
6
+
7
+
8
+ class S3ProxyConfigResponse:
9
+ def __init__(self, data: Dict):
10
+ self.bucket_name = data.get("bucket_name")
11
+ self.endpoint_url = data.get("endpoint_url")
12
+ self.access_key_id = data.get("access_key_id")
13
+ self.secret_access_key = data.get("secret_access_key")
14
+ self.region = data.get("region")
15
+
16
+
17
+ class S3ProxyApiClient:
18
+ def __init__(self):
19
+ self.perimeter, self.integrations_url = self._get_api_configs()
20
+
21
+ def _get_api_configs(self):
22
+ from metaflow_extensions.outerbounds.remote_config import init_config
23
+ from os import environ
24
+
25
+ conf = init_config()
26
+ perimeter = conf.get("OBP_PERIMETER") or environ.get("OBP_PERIMETER", "")
27
+ integrations_url = conf.get("OBP_INTEGRATIONS_URL") or environ.get(
28
+ "OBP_INTEGRATIONS_URL", ""
29
+ )
30
+
31
+ if not perimeter:
32
+ raise S3ProxyConfigException(
33
+ "No perimeter set. Please run `outerbounds configure` command."
34
+ )
35
+
36
+ if not integrations_url:
37
+ raise S3ProxyConfigException(
38
+ "No integrations URL set. Please contact your Outerbounds support team."
39
+ )
40
+
41
+ return perimeter, integrations_url
42
+
43
+ def fetch_s3_proxy_config(
44
+ self, integration_name: Optional[str] = None
45
+ ) -> S3ProxyConfigResponse:
46
+ url = f"{self.integrations_url}/s3proxy"
47
+
48
+ payload = {"perimeter_name": self.perimeter}
49
+ if integration_name:
50
+ payload["integration_name"] = integration_name
51
+
52
+ headers = {"Content-Type": "application/json"}
53
+
54
+ try:
55
+ from metaflow.metaflow_config import SERVICE_HEADERS
56
+
57
+ headers.update(SERVICE_HEADERS or {})
58
+ except ImportError:
59
+ pass
60
+
61
+ response = self._make_request(url, headers, payload)
62
+ return S3ProxyConfigResponse(response)
63
+
64
+ def _make_request(self, url: str, headers: Dict, payload: Dict) -> Dict:
65
+ from metaflow_extensions.outerbounds.plugins.secrets.secrets import (
66
+ _api_server_get,
67
+ )
68
+
69
+ retryable_status_codes = [409]
70
+ json_payload = json.dumps(payload)
71
+
72
+ for attempt in range(3):
73
+ response = _api_server_get(
74
+ url, data=json_payload, headers=headers, conn_error_retries=5
75
+ )
76
+
77
+ if response.status_code not in retryable_status_codes:
78
+ break
79
+
80
+ if attempt < 2:
81
+ time.sleep(0.5 * (attempt + 1))
82
+
83
+ if response.status_code != 200:
84
+ error_msg = f"API request failed with status {response.status_code}"
85
+ try:
86
+ error_data = response.json()
87
+ if "message" in error_data:
88
+ error_msg = error_data["message"]
89
+ except:
90
+ pass
91
+ raise S3ProxyApiException(error_msg)
92
+
93
+ return response.json()