truefoundry 0.5.1rc7__py3-none-any.whl → 0.5.2__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 truefoundry might be problematic. Click here for more details.
- truefoundry/autodeploy/cli.py +1 -1
- truefoundry/cli/__main__.py +92 -2
- truefoundry/{deploy/cli → cli}/display_util.py +9 -4
- truefoundry/{deploy/cli → cli}/util.py +2 -11
- truefoundry/common/constants.py +11 -0
- truefoundry/common/utils.py +10 -0
- truefoundry/deploy/auto_gen/models.py +3 -3
- truefoundry/deploy/builder/builders/tfy_notebook_buildpack/__init__.py +4 -2
- truefoundry/deploy/builder/builders/tfy_python_buildpack/__init__.py +7 -5
- truefoundry/deploy/builder/builders/tfy_python_buildpack/dockerfile_template.py +87 -28
- truefoundry/deploy/builder/constants.py +8 -0
- truefoundry/deploy/builder/utils.py +9 -4
- truefoundry/deploy/cli/commands/apply_command.py +12 -5
- truefoundry/deploy/cli/commands/build_command.py +3 -3
- truefoundry/deploy/cli/commands/build_logs_command.py +2 -2
- truefoundry/deploy/cli/commands/create_command.py +3 -3
- truefoundry/deploy/cli/commands/delete_command.py +4 -4
- truefoundry/deploy/cli/commands/deploy_command.py +2 -2
- truefoundry/deploy/cli/commands/deploy_init_command.py +1 -1
- truefoundry/deploy/cli/commands/get_command.py +5 -5
- truefoundry/deploy/cli/commands/list_command.py +4 -4
- truefoundry/deploy/cli/commands/login_command.py +3 -3
- truefoundry/deploy/cli/commands/logout_command.py +2 -2
- truefoundry/deploy/cli/commands/logs_command.py +2 -2
- truefoundry/deploy/cli/commands/patch_application_command.py +2 -2
- truefoundry/deploy/cli/commands/patch_command.py +2 -2
- truefoundry/deploy/cli/commands/redeploy_command.py +2 -2
- truefoundry/deploy/cli/commands/terminate_comand.py +3 -3
- truefoundry/deploy/cli/commands/trigger_command.py +2 -2
- truefoundry/deploy/lib/clients/servicefoundry_client.py +2 -2
- truefoundry/deploy/lib/const.py +0 -3
- truefoundry/deploy/lib/dao/apply.py +21 -6
- truefoundry/deploy/lib/dao/workspace.py +1 -1
- truefoundry/deploy/lib/model/entity.py +2 -2
- truefoundry/deploy/lib/util.py +0 -14
- truefoundry/ml/__init__.py +8 -4
- truefoundry/ml/cli/cli.py +5 -1
- truefoundry/ml/cli/commands/download.py +16 -3
- truefoundry/ml/cli/commands/model_init.py +4 -4
- truefoundry/ml/mlfoundry_api.py +2 -1
- truefoundry/ml/mlfoundry_run.py +2 -1
- truefoundry/ml/model_framework.py +47 -10
- {truefoundry-0.5.1rc7.dist-info → truefoundry-0.5.2.dist-info}/METADATA +1 -1
- {truefoundry-0.5.1rc7.dist-info → truefoundry-0.5.2.dist-info}/RECORD +49 -52
- truefoundry/deploy/cli/cli.py +0 -96
- truefoundry/deploy/json_util.py +0 -7
- truefoundry/deploy/lib/exceptions.py +0 -10
- /truefoundry/{deploy/cli → cli}/config.py +0 -0
- /truefoundry/{deploy/cli → cli}/console.py +0 -0
- /truefoundry/{deploy/cli → cli}/const.py +0 -0
- {truefoundry-0.5.1rc7.dist-info → truefoundry-0.5.2.dist-info}/WHEEL +0 -0
- {truefoundry-0.5.1rc7.dist-info → truefoundry-0.5.2.dist-info}/entry_points.txt +0 -0
truefoundry/autodeploy/cli.py
CHANGED
|
@@ -31,8 +31,8 @@ from truefoundry.autodeploy.tools.ask import AskQuestion
|
|
|
31
31
|
from truefoundry.autodeploy.tools.commit import CommitConfirmation
|
|
32
32
|
from truefoundry.autodeploy.tools.docker_run import DockerRun, DockerRunLog
|
|
33
33
|
from truefoundry.autodeploy.utils.client import get_git_binary
|
|
34
|
+
from truefoundry.cli.const import COMMAND_CLS
|
|
34
35
|
from truefoundry.deploy import Build, DockerFileBuild, Job, LocalSource, Port, Service
|
|
35
|
-
from truefoundry.deploy.cli.const import COMMAND_CLS
|
|
36
36
|
from truefoundry.deploy.lib.auth.servicefoundry_session import ServiceFoundrySession
|
|
37
37
|
from truefoundry.deploy.lib.clients.servicefoundry_client import (
|
|
38
38
|
ServiceFoundryServiceClient,
|
truefoundry/cli/__main__.py
CHANGED
|
@@ -1,9 +1,100 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
import sys
|
|
2
3
|
|
|
3
4
|
import rich_click as click
|
|
4
5
|
|
|
5
|
-
from truefoundry
|
|
6
|
+
from truefoundry import logger
|
|
7
|
+
from truefoundry.cli.config import CliConfig
|
|
8
|
+
from truefoundry.cli.const import GROUP_CLS
|
|
9
|
+
from truefoundry.cli.util import setup_rich_click
|
|
10
|
+
from truefoundry.common.utils import is_debug_env_set, is_internal_env_set
|
|
11
|
+
from truefoundry.deploy.cli.commands import (
|
|
12
|
+
get_apply_command,
|
|
13
|
+
get_build_command,
|
|
14
|
+
get_delete_command,
|
|
15
|
+
get_deploy_command,
|
|
16
|
+
get_deploy_init_command,
|
|
17
|
+
get_login_command,
|
|
18
|
+
get_logout_command,
|
|
19
|
+
get_patch_application_command,
|
|
20
|
+
get_patch_command,
|
|
21
|
+
get_terminate_command,
|
|
22
|
+
get_trigger_command,
|
|
23
|
+
)
|
|
6
24
|
from truefoundry.ml.cli.cli import get_ml_cli
|
|
25
|
+
from truefoundry.version import __version__
|
|
26
|
+
|
|
27
|
+
click.rich_click.USE_RICH_MARKUP = True
|
|
28
|
+
|
|
29
|
+
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) # noqa: C408
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@click.group(
|
|
33
|
+
cls=GROUP_CLS, context_settings=CONTEXT_SETTINGS, invoke_without_command=True
|
|
34
|
+
)
|
|
35
|
+
@click.option(
|
|
36
|
+
"--json",
|
|
37
|
+
is_flag=True,
|
|
38
|
+
help="Output entities in json format instead of formatted tables",
|
|
39
|
+
)
|
|
40
|
+
@click.option(
|
|
41
|
+
"--debug",
|
|
42
|
+
is_flag=True,
|
|
43
|
+
default=is_debug_env_set,
|
|
44
|
+
help="Set logging level to Debug. Can also be set using environment variable. E.g. SFY_DEBUG=1",
|
|
45
|
+
)
|
|
46
|
+
@click.version_option(__version__)
|
|
47
|
+
@click.pass_context
|
|
48
|
+
def truefoundry_cli(ctx, json, debug):
|
|
49
|
+
"""
|
|
50
|
+
TrueFoundry provides an easy way to deploy your Services, Jobs and Models.
|
|
51
|
+
\b
|
|
52
|
+
|
|
53
|
+
To start, login to your TrueFoundry account with [b]tfy login[/]
|
|
54
|
+
|
|
55
|
+
Then start deploying with [b]tfy deploy[/]
|
|
56
|
+
|
|
57
|
+
And more: [link=https://docs.truefoundry.com/docs]https://docs.truefoundry.com/docs[/]
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
setup_rich_click()
|
|
61
|
+
# TODO (chiragjn): Change this to -o json|yaml|table|pager
|
|
62
|
+
CliConfig.set("json", json)
|
|
63
|
+
if ctx.invoked_subcommand is None:
|
|
64
|
+
click.echo(ctx.get_help())
|
|
65
|
+
log_level = logging.INFO
|
|
66
|
+
# no info logs while outputting json
|
|
67
|
+
if json:
|
|
68
|
+
log_level = logging.ERROR
|
|
69
|
+
if debug:
|
|
70
|
+
log_level = logging.DEBUG
|
|
71
|
+
logger.add_cli_handler(level=log_level)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def create_truefoundry_cli() -> click.MultiCommand:
|
|
75
|
+
"""Generates CLI by combining all subcommands into a main CLI and returns in
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
function: main CLI functions will all added sub-commands
|
|
79
|
+
"""
|
|
80
|
+
cli = truefoundry_cli
|
|
81
|
+
cli.add_command(get_login_command())
|
|
82
|
+
cli.add_command(get_logout_command())
|
|
83
|
+
cli.add_command(get_apply_command())
|
|
84
|
+
cli.add_command(get_deploy_command())
|
|
85
|
+
cli.add_command(get_deploy_init_command())
|
|
86
|
+
cli.add_command(get_patch_application_command())
|
|
87
|
+
cli.add_command(get_delete_command())
|
|
88
|
+
cli.add_command(get_trigger_command())
|
|
89
|
+
cli.add_command(get_terminate_command())
|
|
90
|
+
cli.add_command(get_ml_cli())
|
|
91
|
+
|
|
92
|
+
if not (sys.platform.startswith("win32") or sys.platform.startswith("cygwin")):
|
|
93
|
+
cli.add_command(get_patch_command())
|
|
94
|
+
|
|
95
|
+
if is_internal_env_set():
|
|
96
|
+
cli.add_command(get_build_command())
|
|
97
|
+
return cli
|
|
7
98
|
|
|
8
99
|
|
|
9
100
|
def main():
|
|
@@ -13,7 +104,6 @@ def main():
|
|
|
13
104
|
# If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure).
|
|
14
105
|
try:
|
|
15
106
|
cli = create_truefoundry_cli()
|
|
16
|
-
cli.add_command(get_ml_cli())
|
|
17
107
|
except Exception as e:
|
|
18
108
|
raise click.exceptions.UsageError(message=str(e)) from e
|
|
19
109
|
sys.exit(cli())
|
|
@@ -5,10 +5,15 @@ from rich import box
|
|
|
5
5
|
from rich import print_json as _rich_print_json
|
|
6
6
|
from rich.table import Table
|
|
7
7
|
|
|
8
|
-
from truefoundry.
|
|
9
|
-
from truefoundry.
|
|
10
|
-
from truefoundry.
|
|
11
|
-
|
|
8
|
+
from truefoundry.cli.config import CliConfig
|
|
9
|
+
from truefoundry.cli.console import console
|
|
10
|
+
from truefoundry.cli.const import DISPLAY_DATETIME_FORMAT
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def json_default_encoder(o):
|
|
14
|
+
if isinstance(o, datetime.datetime):
|
|
15
|
+
return o.isoformat()
|
|
16
|
+
raise TypeError(f"Cannot json encode {type(o)}: {o}")
|
|
12
17
|
|
|
13
18
|
|
|
14
19
|
def print_json(data, default=json_default_encoder):
|
|
@@ -10,12 +10,9 @@ from rich.padding import Padding
|
|
|
10
10
|
from rich.panel import Panel
|
|
11
11
|
from rich.table import Table
|
|
12
12
|
|
|
13
|
+
from truefoundry.cli.console import console
|
|
13
14
|
from truefoundry.common.exceptions import BadRequestException
|
|
14
|
-
from truefoundry.
|
|
15
|
-
from truefoundry.deploy.lib.exceptions import (
|
|
16
|
-
ConfigurationException,
|
|
17
|
-
)
|
|
18
|
-
from truefoundry.deploy.lib.util import is_debug_env_set
|
|
15
|
+
from truefoundry.common.utils import is_debug_env_set
|
|
19
16
|
|
|
20
17
|
|
|
21
18
|
def setup_rich_click():
|
|
@@ -45,12 +42,6 @@ def handle_exception(exception):
|
|
|
45
42
|
title="Command Failed",
|
|
46
43
|
border_style="red",
|
|
47
44
|
)
|
|
48
|
-
elif isinstance(exception, ConfigurationException):
|
|
49
|
-
print_dict_as_table_panel(
|
|
50
|
-
{"Error": exception.message},
|
|
51
|
-
title="Command Failed",
|
|
52
|
-
border_style="red",
|
|
53
|
-
)
|
|
54
45
|
else:
|
|
55
46
|
print_dict_as_table_panel(
|
|
56
47
|
{"Error": str(exception)},
|
truefoundry/common/constants.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import enum
|
|
1
2
|
import os
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
from typing import Optional
|
|
@@ -10,11 +11,18 @@ CREDENTIAL_FILEPATH = TFY_CONFIG_DIR / "credentials.json"
|
|
|
10
11
|
# These keys are kept separately because we use them in error messages and some checks
|
|
11
12
|
TFY_HOST_ENV_KEY = "TFY_HOST"
|
|
12
13
|
TFY_API_KEY_ENV_KEY = "TFY_API_KEY"
|
|
14
|
+
TFY_DEBUG_ENV_KEY = "TFY_DEBUG"
|
|
15
|
+
TFY_INTERNAL_ENV_KEY = "TFY_INTERNAL"
|
|
13
16
|
|
|
14
17
|
TFY_INTERNAL_SIGNED_URL_SERVER_HOST_ENV_KEY = "TFY_INTERNAL_SIGNED_URL_SERVER_HOST"
|
|
15
18
|
TFY_INTERNAL_SIGNED_URL_SERVER_TOKEN_ENV_KEY = "TFY_INTERNAL_SIGNED_URL_SERVER_TOKEN"
|
|
16
19
|
|
|
17
20
|
|
|
21
|
+
class PythonPackageManager(str, enum.Enum):
|
|
22
|
+
PIP = "pip"
|
|
23
|
+
UV = "uv"
|
|
24
|
+
|
|
25
|
+
|
|
18
26
|
class TrueFoundrySdkEnv(BaseSettings):
|
|
19
27
|
# Note: Every field in this class should have a default value
|
|
20
28
|
# Never expect the user to set these values
|
|
@@ -46,6 +54,9 @@ class TrueFoundrySdkEnv(BaseSettings):
|
|
|
46
54
|
# For local development, this enables futher configuration via _TFYServersConfig
|
|
47
55
|
TFY_CLI_LOCAL_DEV_MODE: bool = False
|
|
48
56
|
|
|
57
|
+
TFY_PYTHON_BUILD_PACKAGE_MANAGER: PythonPackageManager = PythonPackageManager.PIP
|
|
58
|
+
TFY_PYTHON_BUILD_UV_IMAGE_URI: str = "ghcr.io/astral-sh/uv:latest"
|
|
59
|
+
|
|
49
60
|
|
|
50
61
|
ENV_VARS = TrueFoundrySdkEnv()
|
|
51
62
|
API_SERVER_RELATIVE_PATH = "api/svc"
|
truefoundry/common/utils.py
CHANGED
|
@@ -15,7 +15,9 @@ from truefoundry.common.constants import (
|
|
|
15
15
|
API_SERVER_RELATIVE_PATH,
|
|
16
16
|
ENV_VARS,
|
|
17
17
|
MLFOUNDRY_SERVER_RELATIVE_PATH,
|
|
18
|
+
TFY_DEBUG_ENV_KEY,
|
|
18
19
|
TFY_HOST_ENV_KEY,
|
|
20
|
+
TFY_INTERNAL_ENV_KEY,
|
|
19
21
|
)
|
|
20
22
|
from truefoundry.pydantic_v1 import BaseSettings
|
|
21
23
|
|
|
@@ -182,3 +184,11 @@ def list_pip_packages_installed(
|
|
|
182
184
|
InstalledPipPackage(package["name"], package["version"])
|
|
183
185
|
)
|
|
184
186
|
return relevant_package_names
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def is_debug_env_set() -> bool:
|
|
190
|
+
return bool(os.getenv(TFY_DEBUG_ENV_KEY))
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def is_internal_env_set() -> bool:
|
|
194
|
+
return bool(os.getenv(TFY_INTERNAL_ENV_KEY))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# generated by datamodel-codegen:
|
|
2
2
|
# filename: application.json
|
|
3
|
-
# timestamp: 2024-
|
|
3
|
+
# timestamp: 2024-12-16T11:59:07+00:00
|
|
4
4
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
@@ -877,7 +877,7 @@ class Resources(BaseModel):
|
|
|
877
877
|
None,
|
|
878
878
|
description="+label=GPU Count\n+usage=Count of GPUs to provide to the application\nNote the exact count and max count available for a given GPU type depends on cloud provider and cluster type.",
|
|
879
879
|
)
|
|
880
|
-
shared_memory_size: Optional[conint(ge=64, le=
|
|
880
|
+
shared_memory_size: Optional[conint(ge=64, le=2000000)] = Field(
|
|
881
881
|
None,
|
|
882
882
|
description="+label=Shared Memory Size (MB)\n+usage=Define the shared memory requirements for your workload. Machine learning libraries like Pytorch can use Shared Memory\nfor inter-process communication. If you use this, we will mount a `tmpfs` backed volume at the `/dev/shm` directory.\nAny usage will also count against the workload's memory limit (`resources.memory_limit`) along with your workload's memory usage.\nIf the overall usage goes above `resources.memory_limit` the user process may get killed.\nShared Memory Size cannot be more than the defined Memory Limit for the workload.",
|
|
883
883
|
)
|
|
@@ -913,7 +913,7 @@ class Rolling(BaseModel):
|
|
|
913
913
|
description="+label=Max unavailable(%)\n+usage=Percentage of total replicas that can be brought down at one time.\nFor a value of 25 when replicas are set to 12 this would mean minimum (25% of 12) = 3 pods might be unavailable during the deployment.\nSetting this to a higher value can help in speeding up the deployment process.",
|
|
914
914
|
)
|
|
915
915
|
max_surge_percentage: conint(ge=0, le=100) = Field(
|
|
916
|
-
|
|
916
|
+
25,
|
|
917
917
|
description="+label=Max Surge(%)\n+usage=Percentage of total replicas of updated image that can be brought up over the total replicas count.\nFor a value of 25 when replicas are set to 12 this would mean (12+(25% of 12) = 15) pods might be running at one time.\nSetting this to a higher value can help in speeding up the deployment process.",
|
|
918
918
|
)
|
|
919
919
|
|
|
@@ -8,7 +8,7 @@ from truefoundry.deploy.builder.builders.tfy_notebook_buildpack.dockerfile_templ
|
|
|
8
8
|
NotebookImageBuild,
|
|
9
9
|
generate_dockerfile_content,
|
|
10
10
|
)
|
|
11
|
-
from truefoundry.deploy.builder.utils import
|
|
11
|
+
from truefoundry.deploy.builder.utils import has_python_package_manager_conf_secret
|
|
12
12
|
|
|
13
13
|
__all__ = ["generate_dockerfile_content", "build"]
|
|
14
14
|
|
|
@@ -38,7 +38,9 @@ def build(
|
|
|
38
38
|
build_configuration: NotebookImageBuild,
|
|
39
39
|
extra_opts: Optional[List[str]] = None,
|
|
40
40
|
):
|
|
41
|
-
mount_pip_conf_secret =
|
|
41
|
+
mount_pip_conf_secret = (
|
|
42
|
+
has_python_package_manager_conf_secret(extra_opts) if extra_opts else False
|
|
43
|
+
)
|
|
42
44
|
with TemporaryDirectory() as local_dir:
|
|
43
45
|
docker_build_configuration = _convert_to_dockerfile_build_config(
|
|
44
46
|
build_configuration,
|
|
@@ -7,7 +7,7 @@ from truefoundry.deploy.builder.builders import dockerfile
|
|
|
7
7
|
from truefoundry.deploy.builder.builders.tfy_python_buildpack.dockerfile_template import (
|
|
8
8
|
generate_dockerfile_content,
|
|
9
9
|
)
|
|
10
|
-
from truefoundry.deploy.builder.utils import
|
|
10
|
+
from truefoundry.deploy.builder.utils import has_python_package_manager_conf_secret
|
|
11
11
|
|
|
12
12
|
__all__ = ["generate_dockerfile_content", "build"]
|
|
13
13
|
|
|
@@ -15,11 +15,11 @@ __all__ = ["generate_dockerfile_content", "build"]
|
|
|
15
15
|
def _convert_to_dockerfile_build_config(
|
|
16
16
|
build_configuration: PythonBuild,
|
|
17
17
|
dockerfile_path: str,
|
|
18
|
-
|
|
18
|
+
mount_python_package_manager_conf_secret: bool = False,
|
|
19
19
|
) -> DockerFileBuild:
|
|
20
20
|
dockerfile_content = generate_dockerfile_content(
|
|
21
21
|
build_configuration=build_configuration,
|
|
22
|
-
|
|
22
|
+
mount_python_package_manager_conf_secret=mount_python_package_manager_conf_secret,
|
|
23
23
|
)
|
|
24
24
|
with open(dockerfile_path, "w", encoding="utf8") as fp:
|
|
25
25
|
fp.write(dockerfile_content)
|
|
@@ -36,12 +36,14 @@ def build(
|
|
|
36
36
|
build_configuration: PythonBuild,
|
|
37
37
|
extra_opts: Optional[List[str]] = None,
|
|
38
38
|
):
|
|
39
|
-
|
|
39
|
+
mount_python_package_manager_conf_secret = (
|
|
40
|
+
has_python_package_manager_conf_secret(extra_opts) if extra_opts else False
|
|
41
|
+
)
|
|
40
42
|
with TemporaryDirectory() as local_dir:
|
|
41
43
|
docker_build_configuration = _convert_to_dockerfile_build_config(
|
|
42
44
|
build_configuration,
|
|
43
45
|
dockerfile_path=os.path.join(local_dir, "Dockerfile"),
|
|
44
|
-
|
|
46
|
+
mount_python_package_manager_conf_secret=mount_python_package_manager_conf_secret,
|
|
45
47
|
)
|
|
46
48
|
dockerfile.build(
|
|
47
49
|
tag=tag,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import shlex
|
|
2
3
|
from typing import Dict, List, Optional
|
|
3
4
|
|
|
4
5
|
from mako.template import Template
|
|
5
6
|
|
|
6
|
-
from truefoundry.common.constants import ENV_VARS
|
|
7
|
+
from truefoundry.common.constants import ENV_VARS, PythonPackageManager
|
|
7
8
|
from truefoundry.deploy.auto_gen.models import PythonBuild
|
|
8
9
|
from truefoundry.deploy.builder.constants import (
|
|
9
10
|
PIP_CONF_BUILDKIT_SECRET_MOUNT,
|
|
10
11
|
PIP_CONF_SECRET_MOUNT_AS_ENV,
|
|
12
|
+
UV_CONF_BUILDKIT_SECRET_MOUNT,
|
|
13
|
+
UV_CONF_SECRET_MOUNT_AS_ENV,
|
|
11
14
|
)
|
|
12
15
|
from truefoundry.deploy.v2.lib.patched_models import CUDAVersion
|
|
13
16
|
|
|
@@ -22,8 +25,8 @@ RUN ${apt_install_command}
|
|
|
22
25
|
% if requirements_path is not None:
|
|
23
26
|
COPY ${requirements_path} ${requirements_destination_path}
|
|
24
27
|
% endif
|
|
25
|
-
% if
|
|
26
|
-
RUN ${
|
|
28
|
+
% if python_packages_install_command is not None:
|
|
29
|
+
RUN ${package_manager_config_secret_mount} ${python_packages_install_command}
|
|
27
30
|
% endif
|
|
28
31
|
COPY . /app
|
|
29
32
|
WORKDIR /app
|
|
@@ -114,44 +117,91 @@ def generate_pip_install_command(
|
|
|
114
117
|
mount_pip_conf_secret: bool = False,
|
|
115
118
|
) -> Optional[str]:
|
|
116
119
|
upgrade_pip_command = "python -m pip install -U pip setuptools wheel"
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
envs = []
|
|
121
|
+
if mount_pip_conf_secret:
|
|
122
|
+
envs.append(PIP_CONF_SECRET_MOUNT_AS_ENV)
|
|
123
|
+
|
|
124
|
+
command = ["python", "-m", "pip", "install", "--use-pep517", "--no-cache-dir"]
|
|
125
|
+
args = []
|
|
119
126
|
if requirements_path:
|
|
120
|
-
|
|
127
|
+
args.append("-r")
|
|
128
|
+
args.append(requirements_path)
|
|
121
129
|
|
|
122
130
|
if pip_packages:
|
|
123
|
-
|
|
124
|
-
final_pip_install_command or pip_install_base_command
|
|
125
|
-
)
|
|
126
|
-
final_pip_install_command += " " + " ".join(
|
|
127
|
-
f"'{package}'" for package in pip_packages
|
|
128
|
-
)
|
|
131
|
+
args.extend(pip_packages)
|
|
129
132
|
|
|
130
|
-
if not
|
|
133
|
+
if not args:
|
|
131
134
|
return None
|
|
132
135
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
final_pip_install_command = shlex.join(envs + command + args)
|
|
137
|
+
final_docker_run_command = " && ".join(
|
|
138
|
+
[upgrade_pip_command, final_pip_install_command]
|
|
139
|
+
)
|
|
140
|
+
return final_docker_run_command
|
|
137
141
|
|
|
138
|
-
|
|
142
|
+
|
|
143
|
+
def generate_uv_pip_install_command(
|
|
144
|
+
requirements_path: Optional[str],
|
|
145
|
+
pip_packages: Optional[List[str]],
|
|
146
|
+
mount_uv_conf_secret: bool = False,
|
|
147
|
+
) -> Optional[str]:
|
|
148
|
+
upgrade_pip_command = "python -m pip install -U pip setuptools wheel"
|
|
149
|
+
uv_mount = f"--mount=from={ENV_VARS.TFY_PYTHON_BUILD_UV_IMAGE_URI},source=/uv,target=/usr/local/bin/uv"
|
|
150
|
+
envs = [
|
|
151
|
+
"UV_SYSTEM_PYTHON=true",
|
|
152
|
+
"UV_LINK_MODE=copy",
|
|
153
|
+
"UV_PYTHON_DOWNLOADS=never",
|
|
154
|
+
"UV_INDEX_STRATEGY=unsafe-best-match",
|
|
155
|
+
]
|
|
156
|
+
if mount_uv_conf_secret:
|
|
157
|
+
envs.append(UV_CONF_SECRET_MOUNT_AS_ENV)
|
|
158
|
+
|
|
159
|
+
command = ["uv", "pip", "install", "--no-cache-dir"]
|
|
160
|
+
|
|
161
|
+
args = []
|
|
162
|
+
|
|
163
|
+
if requirements_path:
|
|
164
|
+
args.append("-r")
|
|
165
|
+
args.append(requirements_path)
|
|
166
|
+
|
|
167
|
+
if pip_packages:
|
|
168
|
+
args.extend(pip_packages)
|
|
169
|
+
|
|
170
|
+
if not args:
|
|
171
|
+
return None
|
|
172
|
+
|
|
173
|
+
uv_pip_install_command = shlex.join(envs + command + args)
|
|
174
|
+
shell_commands = " && ".join([upgrade_pip_command, uv_pip_install_command])
|
|
175
|
+
final_docker_run_command = " ".join([uv_mount, shell_commands])
|
|
176
|
+
|
|
177
|
+
return final_docker_run_command
|
|
139
178
|
|
|
140
179
|
|
|
141
180
|
def generate_dockerfile_content(
|
|
142
181
|
build_configuration: PythonBuild,
|
|
143
|
-
|
|
182
|
+
package_manager: str = ENV_VARS.TFY_PYTHON_BUILD_PACKAGE_MANAGER,
|
|
183
|
+
mount_python_package_manager_conf_secret: bool = False,
|
|
144
184
|
) -> str:
|
|
145
185
|
# TODO (chiragjn): Handle recursive references to other requirements files e.g. `-r requirements-gpu.txt`
|
|
146
186
|
requirements_path = resolve_requirements_txt_path(build_configuration)
|
|
147
187
|
requirements_destination_path = (
|
|
148
188
|
"/tmp/requirements.txt" if requirements_path else None
|
|
149
189
|
)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
190
|
+
if package_manager == PythonPackageManager.PIP.value:
|
|
191
|
+
python_packages_install_command = generate_pip_install_command(
|
|
192
|
+
requirements_path=requirements_destination_path,
|
|
193
|
+
pip_packages=build_configuration.pip_packages,
|
|
194
|
+
mount_pip_conf_secret=mount_python_package_manager_conf_secret,
|
|
195
|
+
)
|
|
196
|
+
elif package_manager == PythonPackageManager.UV.value:
|
|
197
|
+
python_packages_install_command = generate_uv_pip_install_command(
|
|
198
|
+
requirements_path=requirements_destination_path,
|
|
199
|
+
pip_packages=build_configuration.pip_packages,
|
|
200
|
+
mount_uv_conf_secret=mount_python_package_manager_conf_secret,
|
|
201
|
+
)
|
|
202
|
+
else:
|
|
203
|
+
raise ValueError(f"Unsupported package manager: {package_manager}")
|
|
204
|
+
|
|
155
205
|
apt_install_command = generate_apt_install_command(
|
|
156
206
|
apt_packages=build_configuration.apt_packages
|
|
157
207
|
)
|
|
@@ -161,13 +211,22 @@ def generate_dockerfile_content(
|
|
|
161
211
|
"apt_install_command": apt_install_command,
|
|
162
212
|
"requirements_path": requirements_path,
|
|
163
213
|
"requirements_destination_path": requirements_destination_path,
|
|
164
|
-
"
|
|
214
|
+
"python_packages_install_command": python_packages_install_command,
|
|
165
215
|
}
|
|
166
216
|
|
|
167
|
-
if
|
|
168
|
-
|
|
217
|
+
if mount_python_package_manager_conf_secret:
|
|
218
|
+
if package_manager == PythonPackageManager.PIP.value:
|
|
219
|
+
template_args["package_manager_config_secret_mount"] = (
|
|
220
|
+
PIP_CONF_BUILDKIT_SECRET_MOUNT
|
|
221
|
+
)
|
|
222
|
+
elif package_manager == PythonPackageManager.UV.value:
|
|
223
|
+
template_args["package_manager_config_secret_mount"] = (
|
|
224
|
+
UV_CONF_BUILDKIT_SECRET_MOUNT
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
raise ValueError(f"Unsupported package manager: {package_manager}")
|
|
169
228
|
else:
|
|
170
|
-
template_args["
|
|
229
|
+
template_args["package_manager_config_secret_mount"] = ""
|
|
171
230
|
|
|
172
231
|
if build_configuration.cuda_version:
|
|
173
232
|
template = CUDA_DOCKERFILE_TEMPLATE
|
|
@@ -5,3 +5,11 @@ PIP_CONF_BUILDKIT_SECRET_MOUNT = (
|
|
|
5
5
|
PIP_CONF_SECRET_MOUNT_AS_ENV = (
|
|
6
6
|
f"PIP_CONFIG_FILE=/run/secrets/{BUILDKIT_SECRET_MOUNT_PIP_CONF_ID}"
|
|
7
7
|
)
|
|
8
|
+
|
|
9
|
+
BUILDKIT_SECRET_MOUNT_UV_CONF_ID = "uv.toml"
|
|
10
|
+
UV_CONF_BUILDKIT_SECRET_MOUNT = (
|
|
11
|
+
f"--mount=type=secret,id={BUILDKIT_SECRET_MOUNT_UV_CONF_ID}"
|
|
12
|
+
)
|
|
13
|
+
UV_CONF_SECRET_MOUNT_AS_ENV = (
|
|
14
|
+
f"UV_CONFIG_FILE=/run/secrets/{BUILDKIT_SECRET_MOUNT_UV_CONF_ID}"
|
|
15
|
+
)
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
from typing import List, Optional
|
|
2
2
|
|
|
3
|
-
from truefoundry.deploy.builder.constants import
|
|
3
|
+
from truefoundry.deploy.builder.constants import (
|
|
4
|
+
BUILDKIT_SECRET_MOUNT_PIP_CONF_ID,
|
|
5
|
+
BUILDKIT_SECRET_MOUNT_UV_CONF_ID,
|
|
6
|
+
)
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
def _get_id_from_buildkit_secret_value(value: str) -> Optional[str]:
|
|
@@ -19,14 +22,16 @@ def _get_id_from_buildkit_secret_value(value: str) -> Optional[str]:
|
|
|
19
22
|
return None
|
|
20
23
|
|
|
21
24
|
|
|
22
|
-
def
|
|
25
|
+
def has_python_package_manager_conf_secret(docker_build_extra_args: List[str]) -> bool:
|
|
23
26
|
args = [arg.strip() for arg in docker_build_extra_args]
|
|
24
27
|
for i, arg in enumerate(docker_build_extra_args):
|
|
25
28
|
if (
|
|
26
29
|
arg == "--secret"
|
|
27
30
|
and i + 1 < len(args)
|
|
28
|
-
and
|
|
29
|
-
|
|
31
|
+
and (
|
|
32
|
+
_get_id_from_buildkit_secret_value(args[i + 1])
|
|
33
|
+
in (BUILDKIT_SECRET_MOUNT_PIP_CONF_ID, BUILDKIT_SECRET_MOUNT_UV_CONF_ID)
|
|
34
|
+
)
|
|
30
35
|
):
|
|
31
36
|
return True
|
|
32
37
|
return False
|
|
@@ -2,9 +2,9 @@ from typing import List, Tuple
|
|
|
2
2
|
|
|
3
3
|
import rich_click as click
|
|
4
4
|
|
|
5
|
-
from truefoundry.
|
|
6
|
-
from truefoundry.
|
|
7
|
-
from truefoundry.
|
|
5
|
+
from truefoundry.cli.console import console
|
|
6
|
+
from truefoundry.cli.const import GROUP_CLS
|
|
7
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
8
8
|
from truefoundry.deploy.lib.clients.servicefoundry_client import (
|
|
9
9
|
ServiceFoundryServiceClient,
|
|
10
10
|
)
|
|
@@ -30,13 +30,20 @@ from truefoundry.deploy.lib.model.entity import ApplyResult
|
|
|
30
30
|
required=True,
|
|
31
31
|
multiple=True,
|
|
32
32
|
)
|
|
33
|
+
@click.option(
|
|
34
|
+
"--dry-run",
|
|
35
|
+
"--dry_run",
|
|
36
|
+
is_flag=True,
|
|
37
|
+
show_default=True,
|
|
38
|
+
help="Simulate the process without actually applying the manifest",
|
|
39
|
+
)
|
|
33
40
|
@handle_exception_wrapper
|
|
34
|
-
def apply_command(files: Tuple[str, ...]):
|
|
41
|
+
def apply_command(files: Tuple[str, ...], dry_run: bool = False):
|
|
35
42
|
apply_results: List[ApplyResult] = []
|
|
36
43
|
client = ServiceFoundryServiceClient()
|
|
37
44
|
for file in files:
|
|
38
45
|
with console.status(PROMPT_APPLYING_MANIFEST.format(file), spinner="dots"):
|
|
39
|
-
for apply_result in apply_lib.apply_manifest_file(file, client):
|
|
46
|
+
for apply_result in apply_lib.apply_manifest_file(file, client, dry_run):
|
|
40
47
|
if apply_result.success:
|
|
41
48
|
console.print(f"[green]\u2714 {apply_result.message}[/]")
|
|
42
49
|
else:
|
|
@@ -2,10 +2,10 @@ import json
|
|
|
2
2
|
|
|
3
3
|
import rich_click as click
|
|
4
4
|
|
|
5
|
+
from truefoundry.cli.console import console
|
|
6
|
+
from truefoundry.cli.const import GROUP_CLS
|
|
7
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
5
8
|
from truefoundry.deploy import builder
|
|
6
|
-
from truefoundry.deploy.cli.console import console
|
|
7
|
-
from truefoundry.deploy.cli.const import GROUP_CLS
|
|
8
|
-
from truefoundry.deploy.cli.util import handle_exception_wrapper
|
|
9
9
|
from truefoundry.version import __version__
|
|
10
10
|
|
|
11
11
|
|
|
@@ -2,8 +2,8 @@ from typing import Optional
|
|
|
2
2
|
|
|
3
3
|
import rich_click as click
|
|
4
4
|
|
|
5
|
-
from truefoundry.
|
|
6
|
-
from truefoundry.
|
|
5
|
+
from truefoundry.cli.const import COMMAND_CLS
|
|
6
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
7
7
|
from truefoundry.deploy.io.rich_output_callback import RichOutputCallBack
|
|
8
8
|
from truefoundry.deploy.lib.clients.servicefoundry_client import (
|
|
9
9
|
ServiceFoundryServiceClient,
|
|
@@ -2,9 +2,9 @@ from typing import Optional
|
|
|
2
2
|
|
|
3
3
|
import rich_click as click
|
|
4
4
|
|
|
5
|
-
from truefoundry.
|
|
6
|
-
from truefoundry.
|
|
7
|
-
from truefoundry.
|
|
5
|
+
from truefoundry.cli.const import COMMAND_CLS, GROUP_CLS
|
|
6
|
+
from truefoundry.cli.display_util import print_obj
|
|
7
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
8
8
|
from truefoundry.deploy.lib.dao import workspace as workspace_lib
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import rich_click as click
|
|
2
2
|
|
|
3
|
-
from truefoundry.
|
|
4
|
-
from truefoundry.
|
|
5
|
-
from truefoundry.
|
|
6
|
-
from truefoundry.
|
|
3
|
+
from truefoundry.cli.config import CliConfig
|
|
4
|
+
from truefoundry.cli.const import COMMAND_CLS, GROUP_CLS
|
|
5
|
+
from truefoundry.cli.display_util import print_json
|
|
6
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
7
7
|
from truefoundry.deploy.io.rich_output_callback import RichOutputCallBack
|
|
8
8
|
from truefoundry.deploy.lib.dao import application as application_lib
|
|
9
9
|
from truefoundry.deploy.lib.dao import workspace as workspace_lib
|
|
@@ -9,8 +9,8 @@ from click.exceptions import ClickException
|
|
|
9
9
|
|
|
10
10
|
from truefoundry.autodeploy.cli import cli as autodeploy_cli
|
|
11
11
|
from truefoundry.autodeploy.exception import InvalidRequirementsException
|
|
12
|
-
from truefoundry.
|
|
13
|
-
from truefoundry.
|
|
12
|
+
from truefoundry.cli.const import COMMAND_CLS, GROUP_CLS
|
|
13
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def _get_default_spec_file():
|
|
@@ -6,11 +6,11 @@ import rich_click as click
|
|
|
6
6
|
import yaml
|
|
7
7
|
from rich.pretty import pprint
|
|
8
8
|
|
|
9
|
-
from truefoundry.
|
|
10
|
-
from truefoundry.
|
|
11
|
-
from truefoundry.
|
|
12
|
-
from truefoundry.
|
|
13
|
-
from truefoundry.
|
|
9
|
+
from truefoundry.cli.config import CliConfig
|
|
10
|
+
from truefoundry.cli.console import console
|
|
11
|
+
from truefoundry.cli.const import COMMAND_CLS, GROUP_CLS
|
|
12
|
+
from truefoundry.cli.display_util import print_entity_obj, print_json
|
|
13
|
+
from truefoundry.cli.util import handle_exception_wrapper
|
|
14
14
|
from truefoundry.deploy.lib.dao import application as application_lib
|
|
15
15
|
from truefoundry.deploy.lib.dao import version as version_lib
|
|
16
16
|
from truefoundry.deploy.lib.dao import workspace as workspace_lib
|