Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions instill/helpers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ FROM rayproject/ray:${RAY_VERSION}-py${PYTHON_VERSION}${CUDA_SUFFIX}${TARGET_ARC

RUN sudo apt-get update && sudo apt-get install curl -y

ARG SYSTEM_PACKAGES
RUN for package in ${SYSTEM_PACKAGES}; do \
sudo apt-get install $package; \
done;

ARG PACKAGES
RUN for package in ${PACKAGES}; do \
pip install --default-timeout=1000 --no-cache-dir $package; \
Expand Down
49 changes: 38 additions & 11 deletions instill/helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,34 @@

import instill
from instill.helpers.const import DEFAULT_DEPENDENCIES
from instill.helpers.errors import ModelConfigException
from instill.utils.logger import Logger

if __name__ == "__main__":
Logger.i("[Instill Builder] Setup docker...")

def config_check_required_fields(c):
if "build" not in c or c["build"] is None:
raise ModelConfigException("build")
if "gpu" not in c["build"] or c["build"]["gpu"] is None:
raise ModelConfigException("gpu")
if "python_version" not in c["build"] or c["build"]["python_version"] is None:
raise ModelConfigException("python_version")
if "repo" not in c or c["repo"] is None:
raise ModelConfigException("repo")


def build_image():
if platform.machine() in ("i386", "AMD64", "x86_64"):
default_platform = "amd64"
else:
default_platform = platform.machine()
parser = argparse.ArgumentParser()
parser.add_argument(
"-t",
"--tag",
help="tag for the model image",
default="",
required=False,
)
parser.add_argument(
"--no-cache",
help="build the image without cache",
Expand All @@ -34,30 +53,32 @@
required=False,
)

args = parser.parse_args()
try:
args = parser.parse_args()

Logger.i("[Instill Builder] Loading config file...")
with open("instill.yaml", "r", encoding="utf8") as f:
Logger.i("[Instill Builder] Parsing config file...")
config = yaml.safe_load(f)

config_check_required_fields(config)

build = config["build"]
repo = config["repo"]
tag = (
config["tag"]
if config["tag"] is not None and config["tag"] != ""
else hashlib.sha256().hexdigest()
)
tag = args.tag if args.tag != "" else hashlib.sha256().hexdigest()

python_version = build["python_version"].replace(".", "")
ray_version = ray.__version__
instill_version = instill.__version__

cuda_suffix = "" if not build["gpu"] else "-cu121"

system_str = ""
if "system_packages" in build and not build["system_packages"] is None:
for p in build["system_packages"]:
system_str += p + " "

packages_str = ""
if not build["python_packages"] is None:
if "python_packages" in build and not build["python_packages"] is None:
for p in build["python_packages"]:
packages_str += p + " "
for p in DEFAULT_DEPENDENCIES:
Expand Down Expand Up @@ -90,6 +111,8 @@
f"CUDA_SUFFIX={cuda_suffix}",
"--build-arg",
f"PACKAGES={packages_str}",
"--build-arg",
f"SYSTEM_PACKAGES={system_str}",
"--platform",
f"linux/{args.target_arch}",
"-t",
Expand All @@ -104,10 +127,14 @@
check=True,
)
Logger.i(f"[Instill Builder] {repo}:{tag} built")
except subprocess.CalledProcessError as e:
except subprocess.CalledProcessError:
Logger.e("[Instill Builder] Build failed")
except Exception as e:
Logger.e("[Instill Builder] Prepare failed")
Logger.e(e)
finally:
Logger.i("[Instill Builder] Done")


if __name__ == "__main__":
build_image()
10 changes: 10 additions & 0 deletions instill/helpers/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ def __str__(self) -> str:
class ModelVramException(Exception):
def __str__(self) -> str:
return "model projected vram usage is more than the GPU can handle"


class ModelConfigException(Exception):
def __init__(self, field):
self.field = field

def __str__(
self,
) -> str:
return f"model config file `instill.yaml` is missing {self.field} field"
23 changes: 16 additions & 7 deletions instill/helpers/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

from instill.utils.logger import Logger

if __name__ == "__main__":
Logger.i("[Instill Builder] Setup docker...")

def push_image():
parser = argparse.ArgumentParser()
parser.add_argument(
"-u",
Expand All @@ -16,6 +15,12 @@
default="docker.io",
required=False,
)
parser.add_argument(
"-t",
"--tag",
help="tag for the model image",
required=True,
)

try:
args = parser.parse_args()
Expand All @@ -27,18 +32,22 @@

registry = args.url
repo = config["repo"]
tag = config["tag"]

subprocess.run(
["docker", "tag", f"{repo}:{tag}", f"{registry}/{repo}:{tag}"], check=True
["docker", "tag", f"{repo}:{args.tag}", f"{registry}/{repo}:{args.tag}"],
check=True,
)
Logger.i("[Instill Builder] Pushing model image...")
subprocess.run(["docker", "push", f"{registry}/{repo}:{tag}"], check=True)
Logger.i(f"[Instill Builder] {registry}/{repo}:{tag} pushed")
except subprocess.CalledProcessError as e:
subprocess.run(["docker", "push", f"{registry}/{repo}:{args.tag}"], check=True)
Logger.i(f"[Instill Builder] {registry}/{repo}:{args.tag} pushed")
except subprocess.CalledProcessError:
Logger.e("[Instill Builder] Push failed")
except Exception as e:
Logger.e("[Instill Builder] Prepare failed")
Logger.e(e)
finally:
Logger.i("[Instill Builder] Done")


if __name__ == "__main__":
push_image()
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ homepage = "https://pypi.org/project/instill-sdk"
documentation = "https://instill-sdk.readthedocs.io"
repository = "https://github.com/instill-ai/python-sdk"

maintainers = ["Heiru Wu <heiru.wu@instill.tech>"]

keywords = []
classifiers = [
"Development Status :: 1 - Planning",
Expand All @@ -37,7 +39,7 @@ googleapis-common-protos = "^1.60.0"
protoc-gen-openapiv2 = "^0.0.1"
pydantic = ">=1.10.13"
pillow = "^10.1.0"
ray = {version = "2.9.3", extras = ["serve"]}
ray = { version = "2.9.3", extras = ["serve"] }
jsonschema = "^4.20.0"

[tool.poetry.dev-dependencies]
Expand Down Expand Up @@ -84,8 +86,8 @@ jsonref = "^1.1.0"
twine = "^4.0.2"

[tool.poetry.scripts]

# python-sdk = "instill.cli:main"
instill_build = "instill.helpers.build:build_image"
instill_push = "instill.helpers.push:push_image"

[tool.black]

Expand Down Expand Up @@ -118,9 +120,7 @@ profile = "black"
skip_glob = ["**/protogen/*", "**/protobufs/*"]

[tool.mypy]
exclude = [
'instill/resources/schema',
]
exclude = ['instill/resources/schema']
ignore_missing_imports = true
no_implicit_optional = true
check_untyped_defs = true
Expand Down