Skip to content

Commit

Permalink
Adding initial code to implement build commands
Browse files Browse the repository at this point in the history
  • Loading branch information
htrivedi99 committed Jun 6, 2024
1 parent 473a06b commit ca7e264
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "truss"
version = "0.9.14"
version = "0.9.15rc16"
description = "A seamless bridge from model development to model delivery"
license = "MIT"
readme = "README.md"
Expand Down
9 changes: 9 additions & 0 deletions truss/contexts/image_builder/serving_image_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ def copy_into_build_dir(from_path: Path, path_in_build_dir: str):
)
)

# User specified build commands
build_commands: list = []
if self._spec.build_commands is not None:
for command in self._spec.build_commands:
build_commands.append(command)

# Download from HuggingFace
model_files, cached_files = update_config_and_gather_files(
config, truss_dir, build_dir
Expand Down Expand Up @@ -450,6 +456,7 @@ def copy_into_build_dir(from_path: Path, path_in_build_dir: str):
use_hf_secret,
cached_files,
external_data_files,
build_commands,
)

def _render_dockerfile(
Expand All @@ -460,6 +467,7 @@ def _render_dockerfile(
use_hf_secret: bool,
cached_files: List[str],
external_data_files: List[Tuple[str, str]],
build_commands: List[str],
):
config = self._spec.config
data_dir = build_dir / config.data_dir
Expand Down Expand Up @@ -512,6 +520,7 @@ def _render_dockerfile(
hf_access_token=hf_access_token,
hf_access_token_file_name=HF_ACCESS_TOKEN_FILE_NAME,
external_data_files=external_data_files,
build_commands=build_commands,
**FILENAME_CONSTANTS_MAP,
)
docker_file_path = build_dir / MODEL_DOCKERFILE_NAME
Expand Down
7 changes: 7 additions & 0 deletions truss/templates/server.Dockerfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ RUN mkdir -p {{ dst.parent }}; curl -L "{{ url }}" -o {{ dst }}
{% endfor %}
{%- endif %}


{%- if build_commands %}
{% for command in build_commands %}
RUN {{ command }}
{% endfor %}
{%- endif %}

# Copy data before code for better caching
{%- if data_dir_exists %}
COPY ./{{config.data_dir}} /app/data
Expand Down
3 changes: 3 additions & 0 deletions truss/truss_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class TrussConfig:
base_image: Optional[BaseImage] = None
model_cache: ModelCache = field(default_factory=ModelCache)
trt_llm: Optional[TRTLLMConfiguration] = None
build_commands: Optional[List[str]] = None

@property
def canonical_python_version(self) -> str:
Expand Down Expand Up @@ -553,6 +554,7 @@ def from_dict(d):
trt_llm=transform_optional(
d.get("trt_llm"), lambda x: TRTLLMConfiguration(**x)
),
build_commands=d.get("build_commands", None),
)
config.validate()
return config
Expand Down Expand Up @@ -613,6 +615,7 @@ def validate(self):
"resources",
"secrets",
"system_packages",
"build_commands",
},
BaseImage: {"image", "python_executable_path"},
}
Expand Down
4 changes: 4 additions & 0 deletions truss/truss_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def data_dir(self) -> Path:
def external_data(self) -> Optional[ExternalData]:
return self._config.external_data

@property
def build_commands(self) -> Optional[List[str]]:
return self._config.build_commands

@property
def model_module_dir(self) -> Path:
return self._truss_dir / self._config.model_module_dir
Expand Down

0 comments on commit ca7e264

Please sign in to comment.