Skip to content

Commit c6d9990

Browse files
authored
Revert "custom base image support (#268)" (#272)
1 parent 278b4cd commit c6d9990

12 files changed

+90
-173
lines changed

bin/generate_base_images.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import List, Optional, Set
1010

1111
from jinja2 import Environment, FileSystemLoader
12-
from truss.constants import TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME
1312
from truss.contexts.image_builder.util import (
1413
truss_base_image_name,
1514
truss_base_image_tag,
@@ -55,14 +54,12 @@ def _render_dockerfile(
5554
jinja_env = Environment(
5655
loader=FileSystemLoader(str(base_path / "docker" / "base_images")),
5756
)
58-
truss_build_template_path = TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME
5957
template = jinja_env.get_template("base_image.Dockerfile.jinja")
6058
return template.render(
6159
use_gpu=use_gpu,
6260
live_reload=live_reload,
6361
job_type=job_type,
6462
python_version=python_version,
65-
truss_build_template_path=truss_build_template_path,
6663
)
6764

6865

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,74 @@
11
{% if use_gpu %}
2-
FROM nvidia/cuda:11.2.1-base-ubuntu18.04
3-
ENV CUDNN_VERSION=8.1.0.77
4-
ENV CUDA=11.2
5-
ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
6-
7-
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub && \
8-
apt-get update && apt-get install -y --no-install-recommends \
9-
ca-certificates \
10-
cuda-command-line-tools-11-2 \
11-
libcublas-11-2 \
12-
libcublas-dev-11-2 \
13-
libcufft-11-2 \
14-
libcurand-11-2 \
15-
libcusolver-11-2 \
16-
libcusparse-11-2 \
17-
libcudnn8=${CUDNN_VERSION}-1+cuda${CUDA} \
18-
libgomp1 \
19-
&& \
20-
apt-get clean && \
21-
rm -rf /var/lib/apt/lists/*
2+
FROM nvidia/cuda:11.2.1-base-ubuntu18.04
3+
ENV CUDNN_VERSION=8.1.0.77
4+
ENV CUDA=11.2
5+
ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:$LD_LIBRARY_PATH
6+
7+
RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub && \
8+
apt-get update && apt-get install -y --no-install-recommends \
9+
ca-certificates \
10+
cuda-command-line-tools-11-2 \
11+
libcublas-11-2 \
12+
libcublas-dev-11-2 \
13+
libcufft-11-2 \
14+
libcurand-11-2 \
15+
libcusolver-11-2 \
16+
libcusparse-11-2 \
17+
libcudnn8=${CUDNN_VERSION}-1+cuda${CUDA} \
18+
libgomp1 \
19+
&& \
20+
apt-get clean && \
21+
rm -rf /var/lib/apt/lists/*
22+
23+
# Allow statements and log messages to immediately appear in the Knative logs
24+
ENV PYTHONUNBUFFERED True
25+
ENV DEBIAN_FRONTEND=noninteractive
26+
27+
RUN apt update && \
28+
apt install -y bash \
29+
build-essential \
30+
git \
31+
curl \
32+
ca-certificates \
33+
software-properties-common && \
34+
add-apt-repository -y ppa:deadsnakes/ppa && \
35+
apt update -y && \
36+
apt install -y python{{python_version}} && \
37+
apt install -y python{{python_version}}-distutils && \
38+
apt install -y python{{python_version}}-venv && \
39+
rm -rf /var/lib/apt/lists
40+
41+
RUN ln -sf /usr/bin/python{{python_version}} /usr/bin/python3 && \
42+
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
43+
python3 get-pip.py
44+
45+
RUN python3 -m pip install --no-cache-dir --upgrade pip
46+
2247
{% else %}
23-
FROM python:{{python_version}}
48+
FROM python:{{python_version}}
49+
RUN apt update && apt install -y
50+
51+
# Allow statements and log messages to immediately appear in the Knative logs
52+
ENV PYTHONUNBUFFERED True
2453
{% endif %}
2554

26-
{% include truss_build_template_path %}
55+
56+
RUN pip install --no-cache-dir --upgrade pip \
57+
&& rm -rf /root/.cache/pip
58+
59+
COPY ./requirements.txt requirements.txt
60+
RUN pip install --no-cache-dir -r requirements.txt \
61+
&& rm -rf /root/.cache/pip
62+
63+
# This is a hack, kfserving uses table_logger, which doesn't work well with
64+
# numpy 1.24 onwards, where np.float and np.int have been remove.
65+
# https://github.com/AleksTk/table-logger/blob/v0.3.6/table_logger/table_logger.py#L80
66+
# Monkey patch table_logger here. Ultimately we should move away from kfserving,
67+
# perhaps to kserve.
68+
RUN find /usr/local/lib/ -name table_logger.py -exec sed -i '/np\.int:/d;/np\.float:/d' {} \;
69+
70+
{% if live_reload %}
71+
COPY ./control /control
72+
RUN python3 -m venv /control/.env \
73+
&& /control/.env/bin/pip3 install -r /control/requirements.txt
74+
{% endif %}

truss/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
TRAINING_REQUIREMENTS_TXT_FILENAME = "training_requirements.txt"
3636
SYSTEM_PACKAGES_TXT_FILENAME = "system_packages.txt"
3737

38-
TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME = "_truss_build.Dockerfile.jinja"
3938
SERVER_DOCKERFILE_TEMPLATE_NAME = "server.Dockerfile.jinja"
4039
TRAINING_DOCKERFILE_TEMPLATE_NAME = "training.Dockerfile.jinja"
4140
MODEL_DOCKERFILE_NAME = "Dockerfile"

truss/contexts/image_builder/image_builder.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def build_image(
1212
build_dir: Optional[Path] = None,
1313
tag: Optional[str] = None,
1414
labels: Optional[dict] = None,
15-
cache: bool = True,
1615
):
1716
"""Build image.
1817
@@ -28,7 +27,6 @@ def build_image(
2827
str(build_dir_path),
2928
labels=labels if labels else {},
3029
tags=tag or self.default_tag,
31-
cache=cache,
3230
)
3331

3432
@property

truss/contexts/image_builder/serving_image_builder.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
SHARED_SERVING_AND_TRAINING_CODE_DIR_NAME,
1313
SYSTEM_PACKAGES_TXT_FILENAME,
1414
TEMPLATES_DIR,
15-
TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME,
1615
)
1716
from truss.contexts.image_builder.image_builder import ImageBuilder
1817
from truss.contexts.image_builder.util import (
@@ -105,19 +104,15 @@ def _render_dockerfile(
105104
dockerfile_template = read_template_from_fs(
106105
TEMPLATES_DIR, SERVER_DOCKERFILE_TEMPLATE_NAME
107106
)
108-
truss_build_template_path = TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME
107+
base_image_name = truss_base_image_name(job_type="server")
109108
python_version = to_dotted_python_version(config.python_version)
110-
if config.base_image:
111-
base_image_name_and_tag = config.base_image
112-
else:
113-
base_image_name = truss_base_image_name(job_type="server")
114-
tag = truss_base_image_tag(
115-
python_version=python_version,
116-
use_gpu=config.resources.use_gpu,
117-
live_reload=config.live_reload,
118-
version_tag=TRUSS_BASE_IMAGE_VERSION_TAG,
119-
)
120-
base_image_name_and_tag = f"{base_image_name}:{tag}"
109+
tag = truss_base_image_tag(
110+
python_version=python_version,
111+
use_gpu=config.resources.use_gpu,
112+
live_reload=config.live_reload,
113+
version_tag=TRUSS_BASE_IMAGE_VERSION_TAG,
114+
)
115+
base_image_name_and_tag = f"{base_image_name}:{tag}"
121116
should_install_system_requirements = file_is_not_empty(
122117
build_dir / SYSTEM_PACKAGES_TXT_FILENAME
123118
)
@@ -130,9 +125,6 @@ def _render_dockerfile(
130125
should_install_system_requirements=should_install_system_requirements,
131126
should_install_requirements=should_install_python_requirements,
132127
config=config,
133-
truss_build_template_path=truss_build_template_path,
134-
python_version=python_version,
135-
live_reload=config.live_reload,
136128
data_dir_exists=data_dir.exists(),
137129
bundled_packages_dir_exists=bundled_packages_dir.exists(),
138130
truss_hash=directory_content_hash(self._truss_dir),

truss/contexts/image_builder/training_image_builder.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
TRAINING_JOB_WRAPPER_CODE_DIR,
1414
TRAINING_JOB_WRAPPER_CODE_DIR_NAME,
1515
TRAINING_REQUIREMENTS_TXT_FILENAME,
16-
TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME,
1716
)
1817
from truss.contexts.image_builder.image_builder import ImageBuilder
1918
from truss.contexts.image_builder.util import (
@@ -93,32 +92,24 @@ def prepare_image_build_dir(self, build_dir: Optional[Path] = None):
9392
dockerfile_template = template_env.get_template(
9493
TRAINING_DOCKERFILE_TEMPLATE_NAME
9594
)
96-
truss_build_template_path = TRUSS_BUILD_DOCKERFILE_TEMPLATE_NAME
9795
should_install_system_requirements = file_is_not_empty(
9896
build_dir / SYSTEM_PACKAGES_TXT_FILENAME
9997
)
10098
should_install_requirements = file_is_not_empty(
10199
build_dir / REQUIREMENTS_TXT_FILENAME
102100
)
103101
config = self._spec.config
104-
python_version = to_dotted_python_version(config.python_version)
105-
if config.base_image:
106-
base_image_name_and_tag = config.base_image
107-
else:
108-
base_image_name = truss_base_image_name(job_type="training")
109-
tag = truss_base_image_tag(
110-
python_version=python_version,
111-
use_gpu=config.resources.use_gpu,
112-
live_reload=config.live_reload,
113-
version_tag=TRUSS_BASE_IMAGE_VERSION_TAG,
114-
)
115-
base_image_name_and_tag = f"{base_image_name}:{tag}"
102+
base_image_name = truss_base_image_name(job_type="training")
103+
tag = truss_base_image_tag(
104+
python_version=to_dotted_python_version(config.python_version),
105+
use_gpu=config.resources.use_gpu,
106+
live_reload=config.live_reload,
107+
version_tag=TRUSS_BASE_IMAGE_VERSION_TAG,
108+
)
109+
base_image_name_and_tag = f"{base_image_name}:{tag}"
116110
dockerfile_contents = dockerfile_template.render(
117111
base_image_name_and_tag=base_image_name_and_tag,
118112
config=self._spec.config,
119-
truss_build_template_path=truss_build_template_path,
120-
python_version=python_version,
121-
live_reload=config.live_reload,
122113
bundled_packages_dir_exists=bundled_packages_dir_exists,
123114
should_install_system_requirements=should_install_system_requirements,
124115
should_install_requirements=should_install_requirements,

truss/templates/_truss_build.Dockerfile.jinja

Lines changed: 0 additions & 50 deletions
This file was deleted.

truss/templates/base.Dockerfile.jinja

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
ARG PYVERSION={{config.python_version}}
22
FROM {{base_image_name_and_tag}}
33

4-
{% block fail_fast %}
5-
RUN grep -w 'ID=debian\|ID_LIKE=debian' /etc/os-release || { echo "ERROR: Supplied base image is not a debian image"; exit 1; }
6-
RUN which python && python --version | grep -E '3\.[0-9]|10\.[0-9][0-9]' || \
7-
which python3 && python3 --version | grep -E '3\.[0-9]|10\.[0-9][0-9]' || \
8-
{ echo "ERROR: Supplied base image does not have 3.8 <= python <= 3.10"; exit 1; }
9-
{% endblock %}
10-
11-
{% if config.base_image %}
12-
{% include truss_build_template_path %}
13-
{% endif %}
14-
154
RUN pip install --upgrade pip --no-cache-dir \
165
&& rm -rf /root/.cache/pip
176
{% if config.model_framework.value == 'huggingface_transformer' %}

truss/tests/test_truss_handle.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,6 @@ def test_build_docker_image(custom_model_truss_dir_with_pre_and_post):
9494
assert image.repo_tags[0] == tag
9595

9696

97-
@pytest.mark.integration
98-
@pytest.mark.parametrize(
99-
"base_image, expected_fail",
100-
[
101-
("baseten/truss-server-base:3.9-v0.4.3", False),
102-
("baseten/truss-training-base:3.9-v0.4.3", False),
103-
("python:3.8.3", False),
104-
("alpine", True),
105-
("python:2.7-slim", True),
106-
("python:3.5-slim", True),
107-
],
108-
)
109-
def test_build_docker_image_from_user_base_image(
110-
custom_model_truss_dir, base_image, expected_fail
111-
):
112-
th = TrussHandle(custom_model_truss_dir)
113-
th.set_base_image(base_image)
114-
try:
115-
th.build_serving_docker_image(cache=False)
116-
except DockerException as exc:
117-
assert expected_fail is True
118-
assert "It returned with code 1" in str(exc)
119-
120-
121-
@pytest.mark.integration
122-
def test_docker_predict_custom_base_image(custom_model_truss_dir_with_pre_and_post):
123-
th = TrussHandle(custom_model_truss_dir_with_pre_and_post)
124-
th.set_base_image("baseten/truss-server-base:3.9-v0.4.3")
125-
with ensure_kill_all():
126-
result = th.docker_predict([1, 2])
127-
assert result == {"predictions": [4, 5]}
128-
129-
13097
@pytest.mark.integration
13198
def test_build_docker_image_gpu(custom_model_truss_dir_for_gpu, tmp_path):
13299
th = TrussHandle(custom_model_truss_dir_for_gpu)

truss/truss_config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ class TrussConfig:
244244
# spec_version is a version string
245245
spec_version: str = DEFAULT_SPEC_VERSION
246246
train: Train = field(default_factory=Train)
247-
base_image: Optional[str] = None
248247

249248
@property
250249
def canonical_python_version(self) -> str:
@@ -291,7 +290,6 @@ def from_dict(d):
291290
external_data=transform_optional(
292291
d.get("external_data"), ExternalData.from_list
293292
),
294-
base_image=d.get("base_image", None),
295293
)
296294
config.validate()
297295
return config
@@ -329,7 +327,6 @@ def to_dict(self):
329327
"live_reload": self.live_reload,
330328
"spec_version": self.spec_version,
331329
"train": self.train.to_dict(),
332-
"base_image": self.base_image,
333330
}
334331
if self.external_data is not None:
335332
d["external_data"] = transform_optional(

0 commit comments

Comments
 (0)