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
17 changes: 17 additions & 0 deletions instill/helpers/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The .dockerignore file excludes files from the container build process.
#
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

# Exclude Git files
.git
.github
.gitignore

# Exclude Python cache files
__pycache__
.mypy_cache
.pytest_cache
.ruff_cache

# Exclude Python virtual environment
/venv
3 changes: 1 addition & 2 deletions instill/helpers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ ARG TARGET_ARCH_SUFFIX

FROM rayproject/ray:${RAY_VERSION}-py${PYTHON_VERSION}${CUDA_SUFFIX}${TARGET_ARCH_SUFFIX}

ARG PACKAGES

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

ARG PACKAGES
RUN for package in ${PACKAGES}; do \
pip install --default-timeout=1000 --no-cache-dir $package; \
done;
Expand Down
54 changes: 34 additions & 20 deletions instill/helpers/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
import platform
import shutil
import subprocess
import tempfile

import docker
import ray
import yaml

Expand Down Expand Up @@ -34,7 +34,6 @@
required=False,
)

client = docker.from_env()
try:
args = parser.parse_args()

Expand Down Expand Up @@ -69,31 +68,46 @@
shutil.copyfile(
__file__.replace("build.py", "Dockerfile"), f"{tmpdir}/Dockerfile"
)
shutil.copyfile(
__file__.replace("build.py", ".dockerignore"), f"{tmpdir}/.dockerignore"
)
shutil.copytree(os.getcwd(), tmpdir, dirs_exist_ok=True)

target_arch_suffix = "-aarch64" if args.target_arch == "arm64" else ""

Logger.i("[Instill Builder] Building model image...")
img, logs = client.images.build(
path=tmpdir,
rm=True,
pull=True,
nocache=args.no_cache,
platform=f"linux/{args.target_arch}",
tag=f"{repo}:{tag}",
buildargs={
"TARGET_ARCH_SUFFIX": target_arch_suffix,
"RAY_VERSION": ray_version,
"PYTHON_VERSION": python_version,
"CUDA_SUFFIX": cuda_suffix,
"PACKAGES": packages_str,
},
quiet=False,
command = [
"docker",
"buildx",
"build",
"--build-arg",
f"TARGET_ARCH_SUFFIX={target_arch_suffix}",
"--build-arg",
f"RAY_VERSION={ray_version}",
"--build-arg",
f"PYTHON_VERSION={python_version}",
"--build-arg",
f"CUDA_SUFFIX={cuda_suffix}",
"--build-arg",
f"PACKAGES={packages_str}",
"--platform",
f"linux/{args.target_arch}",
"-t",
f"{repo}:{tag}",
tmpdir,
"--load",
]
if args.no_cache:
command.append("--no-cache")
subprocess.run(
command,
check=True,
)
for line in logs:
print(*line.values())
Logger.i(f"[Instill Builder] {repo}:{tag} built")
except Exception as e:
except subprocess.CalledProcessError as e:
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")
28 changes: 8 additions & 20 deletions instill/helpers/push.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import argparse
import types
import subprocess

import docker
import yaml

from instill.utils.logger import Logger

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

parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -31,26 +29,16 @@
repo = config["repo"]
tag = config["tag"]

img = client.images.get(name=f"{repo}:{tag}")
img.tag(f"{registry}/{repo}", tag)
subprocess.run(
["docker", "tag", f"{repo}:{tag}", f"{registry}/{repo}:{tag}"], check=True
)
Logger.i("[Instill Builder] Pushing model image...")
logs = client.images.push(f"{registry}/{repo}", tag=tag)
if isinstance(logs, types.GeneratorType):
for line in logs:
print(*line.values())
elif isinstance(logs, list):
for line in logs:
if "errorDetail" in line:
raise RuntimeError(line["errorDetail"]["message"])
print(line)
else:
if "errorDetail" in logs:
err = logs.split('{"errorDetail":{"message":', 1)[1][1:-4]
raise RuntimeError(err)
print(logs)
subprocess.run(["docker", "push", f"{registry}/{repo}:{tag}"], check=True)
Logger.i(f"[Instill Builder] {registry}/{repo}:{tag} pushed")
except Exception as e:
except subprocess.CalledProcessError as e:
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")
36 changes: 7 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pydantic = ">=1.10.13"
pillow = "^10.1.0"
ray = {version = "2.9.3", extras = ["serve"]}
jsonschema = "^4.20.0"
docker = "^7.0.0"

[tool.poetry.dev-dependencies]

Expand Down