outerbounds 0.3.173rc0__py3-none-any.whl → 0.3.174__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.
- outerbounds/command_groups/apps_cli.py +5 -1
- {outerbounds-0.3.173rc0.dist-info → outerbounds-0.3.174.dist-info}/METADATA +3 -3
- {outerbounds-0.3.173rc0.dist-info → outerbounds-0.3.174.dist-info}/RECORD +5 -19
- outerbounds/apps/__init__.py +0 -0
- outerbounds/apps/app_cli.py +0 -519
- outerbounds/apps/app_config.py +0 -308
- outerbounds/apps/artifacts.py +0 -0
- outerbounds/apps/capsule.py +0 -382
- outerbounds/apps/code_package/__init__.py +0 -3
- outerbounds/apps/code_package/code_packager.py +0 -612
- outerbounds/apps/code_package/examples.py +0 -125
- outerbounds/apps/config_schema.yaml +0 -194
- outerbounds/apps/dependencies.py +0 -115
- outerbounds/apps/deployer.py +0 -0
- outerbounds/apps/secrets.py +0 -164
- outerbounds/apps/utils.py +0 -228
- outerbounds/apps/validations.py +0 -34
- {outerbounds-0.3.173rc0.dist-info → outerbounds-0.3.174.dist-info}/WHEEL +0 -0
- {outerbounds-0.3.173rc0.dist-info → outerbounds-0.3.174.dist-info}/entry_points.txt +0 -0
outerbounds/apps/utils.py
DELETED
@@ -1,228 +0,0 @@
|
|
1
|
-
import random
|
2
|
-
import time
|
3
|
-
import sys
|
4
|
-
import json
|
5
|
-
import requests
|
6
|
-
from outerbounds._vendor import click
|
7
|
-
from .app_config import CAPSULE_DEBUG
|
8
|
-
|
9
|
-
|
10
|
-
class MaximumRetriesExceeded(Exception):
|
11
|
-
def __init__(self, url, method, status_code, text):
|
12
|
-
self.url = url
|
13
|
-
self.method = method
|
14
|
-
self.status_code = status_code
|
15
|
-
self.text = text
|
16
|
-
|
17
|
-
def __str__(self):
|
18
|
-
return f"Maximum retries exceeded for {self.url}[{self.method}] {self.status_code} {self.text}"
|
19
|
-
|
20
|
-
|
21
|
-
class KeyValuePair(click.ParamType):
|
22
|
-
name = "KV-PAIR"
|
23
|
-
|
24
|
-
def convert(self, value, param, ctx):
|
25
|
-
# Parse a string of the form KEY=VALUE into a dict {KEY: VALUE}
|
26
|
-
if len(value.split("=", 1)) != 2:
|
27
|
-
self.fail(
|
28
|
-
f"Invalid format for {value}. Expected format: KEY=VALUE", param, ctx
|
29
|
-
)
|
30
|
-
|
31
|
-
key, _value = value.split("=", 1)
|
32
|
-
try:
|
33
|
-
return {key: json.loads(_value)}
|
34
|
-
except json.JSONDecodeError:
|
35
|
-
return {key: _value}
|
36
|
-
except Exception as e:
|
37
|
-
self.fail(f"Invalid value for {value}. Error: {e}", param, ctx)
|
38
|
-
|
39
|
-
def __str__(self):
|
40
|
-
return repr(self)
|
41
|
-
|
42
|
-
def __repr__(self):
|
43
|
-
return "KV-PAIR"
|
44
|
-
|
45
|
-
|
46
|
-
class MountMetaflowArtifact(click.ParamType):
|
47
|
-
name = "MOUNT-METAFLOW-ARTIFACT"
|
48
|
-
|
49
|
-
def convert(self, value, param, ctx):
|
50
|
-
"""
|
51
|
-
Convert a string like "flow=MyFlow,artifact=my_model,path=/tmp/abc" or
|
52
|
-
"pathspec=MyFlow/123/foo/345/my_model,path=/tmp/abc" to a dict.
|
53
|
-
"""
|
54
|
-
artifact_dict = {}
|
55
|
-
parts = value.split(",")
|
56
|
-
|
57
|
-
for part in parts:
|
58
|
-
if "=" not in part:
|
59
|
-
self.fail(
|
60
|
-
f"Invalid format in part '{part}'. Expected 'key=value'", param, ctx
|
61
|
-
)
|
62
|
-
|
63
|
-
key, val = part.split("=", 1)
|
64
|
-
artifact_dict[key.strip()] = val.strip()
|
65
|
-
|
66
|
-
# Validate required fields
|
67
|
-
if "pathspec" in artifact_dict:
|
68
|
-
if "path" not in artifact_dict:
|
69
|
-
self.fail(
|
70
|
-
"When using 'pathspec', you must also specify 'path'", param, ctx
|
71
|
-
)
|
72
|
-
|
73
|
-
# Return as pathspec format
|
74
|
-
return {
|
75
|
-
"pathspec": artifact_dict["pathspec"],
|
76
|
-
"path": artifact_dict["path"],
|
77
|
-
}
|
78
|
-
elif (
|
79
|
-
"flow" in artifact_dict
|
80
|
-
and "artifact" in artifact_dict
|
81
|
-
and "path" in artifact_dict
|
82
|
-
):
|
83
|
-
# Return as flow/artifact format
|
84
|
-
result = {
|
85
|
-
"flow": artifact_dict["flow"],
|
86
|
-
"artifact": artifact_dict["artifact"],
|
87
|
-
"path": artifact_dict["path"],
|
88
|
-
}
|
89
|
-
|
90
|
-
# Add optional namespace if provided
|
91
|
-
if "namespace" in artifact_dict:
|
92
|
-
result["namespace"] = artifact_dict["namespace"]
|
93
|
-
|
94
|
-
return result
|
95
|
-
else:
|
96
|
-
self.fail(
|
97
|
-
"Invalid format. Must be either 'flow=X,artifact=Y,path=Z' or 'pathspec=X,path=Z'",
|
98
|
-
param,
|
99
|
-
ctx,
|
100
|
-
)
|
101
|
-
|
102
|
-
def __str__(self):
|
103
|
-
return repr(self)
|
104
|
-
|
105
|
-
def __repr__(self):
|
106
|
-
return "MOUNT-METAFLOW-ARTIFACT"
|
107
|
-
|
108
|
-
|
109
|
-
class MountSecret(click.ParamType):
|
110
|
-
name = "MOUNT-SECRET"
|
111
|
-
|
112
|
-
def convert(self, value, param, ctx):
|
113
|
-
"""
|
114
|
-
Convert a string like "id=my_secret,path=/tmp/secret" to a dict.
|
115
|
-
"""
|
116
|
-
secret_dict = {}
|
117
|
-
parts = value.split(",")
|
118
|
-
|
119
|
-
for part in parts:
|
120
|
-
if "=" not in part:
|
121
|
-
self.fail(
|
122
|
-
f"Invalid format in part '{part}'. Expected 'key=value'", param, ctx
|
123
|
-
)
|
124
|
-
|
125
|
-
key, val = part.split("=", 1)
|
126
|
-
secret_dict[key.strip()] = val.strip()
|
127
|
-
|
128
|
-
# Validate required fields
|
129
|
-
if "id" in secret_dict and "path" in secret_dict:
|
130
|
-
return {"id": secret_dict["id"], "path": secret_dict["path"]}
|
131
|
-
else:
|
132
|
-
self.fail("Invalid format. Must be 'key=X,path=Y'", param, ctx)
|
133
|
-
|
134
|
-
def __str__(self):
|
135
|
-
return repr(self)
|
136
|
-
|
137
|
-
def __repr__(self):
|
138
|
-
return "MOUNT-SECRET"
|
139
|
-
|
140
|
-
|
141
|
-
class CommaSeparatedList(click.ParamType):
|
142
|
-
name = "COMMA-SEPARATED-LIST"
|
143
|
-
|
144
|
-
def convert(self, value, param, ctx):
|
145
|
-
return value.split(",")
|
146
|
-
|
147
|
-
def __str__(self):
|
148
|
-
return repr(self)
|
149
|
-
|
150
|
-
def __repr__(self):
|
151
|
-
return "COMMA-SEPARATED-LIST"
|
152
|
-
|
153
|
-
|
154
|
-
KVPairType = KeyValuePair()
|
155
|
-
MetaflowArtifactType = MountMetaflowArtifact()
|
156
|
-
SecretMountType = MountSecret()
|
157
|
-
CommaSeparatedListType = CommaSeparatedList()
|
158
|
-
|
159
|
-
|
160
|
-
class TODOException(Exception):
|
161
|
-
pass
|
162
|
-
|
163
|
-
|
164
|
-
requests_funcs = [
|
165
|
-
requests.get,
|
166
|
-
requests.post,
|
167
|
-
requests.put,
|
168
|
-
requests.delete,
|
169
|
-
requests.patch,
|
170
|
-
requests.head,
|
171
|
-
requests.options,
|
172
|
-
]
|
173
|
-
|
174
|
-
|
175
|
-
def safe_requests_wrapper(
|
176
|
-
requests_module_fn,
|
177
|
-
*args,
|
178
|
-
conn_error_retries=2,
|
179
|
-
retryable_status_codes=[409],
|
180
|
-
**kwargs,
|
181
|
-
):
|
182
|
-
"""
|
183
|
-
There are two categories of errors that we need to handle when dealing with any API server.
|
184
|
-
1. HTTP errors. These are are errors that are returned from the API server.
|
185
|
-
- How to handle retries for this case will be application specific.
|
186
|
-
2. Errors when the API server may not be reachable (DNS resolution / network issues)
|
187
|
-
- In this scenario, we know that something external to the API server is going wrong causing the issue.
|
188
|
-
- Failing pre-maturely in the case might not be the best course of action since critical user jobs might crash on intermittent issues.
|
189
|
-
- So in this case, we can just planely retry the request.
|
190
|
-
|
191
|
-
This function handles the second case. It's a simple wrapper to handle the retry logic for connection errors.
|
192
|
-
If this function is provided a `conn_error_retries` of 5, then the last retry will have waited 32 seconds.
|
193
|
-
Generally this is a safe enough number of retries after which we can assume that something is really broken. Until then,
|
194
|
-
there can be intermittent issues that would resolve themselves if we retry gracefully.
|
195
|
-
"""
|
196
|
-
if requests_module_fn not in requests_funcs:
|
197
|
-
raise TODOException(
|
198
|
-
f"safe_requests_wrapper doesn't support {requests_module_fn.__name__}. You can only use the following functions: {requests_funcs}"
|
199
|
-
)
|
200
|
-
|
201
|
-
_num_retries = 0
|
202
|
-
noise = random.uniform(-0.5, 0.5)
|
203
|
-
response = None
|
204
|
-
while _num_retries < conn_error_retries:
|
205
|
-
try:
|
206
|
-
response = requests_module_fn(*args, **kwargs)
|
207
|
-
if response.status_code not in retryable_status_codes:
|
208
|
-
return response
|
209
|
-
if CAPSULE_DEBUG:
|
210
|
-
print(
|
211
|
-
f"[outerbounds-debug] safe_requests_wrapper: {response.url}[{requests_module_fn.__name__}] {response.status_code} {response.text}",
|
212
|
-
file=sys.stderr,
|
213
|
-
)
|
214
|
-
_num_retries += 1
|
215
|
-
time.sleep((2 ** (_num_retries + 1)) + noise)
|
216
|
-
except requests.exceptions.ConnectionError:
|
217
|
-
if _num_retries <= conn_error_retries - 1:
|
218
|
-
# Exponential backoff with 2^(_num_retries+1) seconds
|
219
|
-
time.sleep((2 ** (_num_retries + 1)) + noise)
|
220
|
-
_num_retries += 1
|
221
|
-
else:
|
222
|
-
raise
|
223
|
-
raise MaximumRetriesExceeded(
|
224
|
-
response.url,
|
225
|
-
requests_module_fn.__name__,
|
226
|
-
response.status_code,
|
227
|
-
response.text,
|
228
|
-
)
|
outerbounds/apps/validations.py
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from .app_config import AppConfig, AppConfigError
|
3
|
-
from .secrets import SecretRetriever, SecretNotFound
|
4
|
-
from .dependencies import bake_deployment_image
|
5
|
-
|
6
|
-
|
7
|
-
def deploy_validations(app_config: AppConfig, cache_dir: str, logger):
|
8
|
-
|
9
|
-
# First check if the secrets for the app exist.
|
10
|
-
app_secrets = app_config.get("secrets", [])
|
11
|
-
secret_retriever = SecretRetriever()
|
12
|
-
for secret in app_secrets:
|
13
|
-
try:
|
14
|
-
secret_retriever.get_secret_as_dict(secret)
|
15
|
-
except SecretNotFound:
|
16
|
-
raise AppConfigError(f"Secret not found: {secret}")
|
17
|
-
|
18
|
-
# TODO: Next check if the compute pool exists.
|
19
|
-
logger("🍞 Baking Docker Image")
|
20
|
-
baking_status = bake_deployment_image(
|
21
|
-
app_config=app_config,
|
22
|
-
cache_file_path=os.path.join(cache_dir, "image_cache"),
|
23
|
-
logger=logger,
|
24
|
-
)
|
25
|
-
app_config.set_state(
|
26
|
-
"image",
|
27
|
-
baking_status.resolved_image,
|
28
|
-
)
|
29
|
-
app_config.set_state("python_path", baking_status.python_path)
|
30
|
-
logger("🐳 Using The Docker Image : %s" % app_config.get_state("image"))
|
31
|
-
|
32
|
-
|
33
|
-
def run_validations(app_config: AppConfig):
|
34
|
-
pass
|
File without changes
|
File without changes
|