Skip to content

Commit cdc190b

Browse files
authored
Merge pull request #290 from dclong/dev
Merge dev into main
2 parents ed63be9 + a7b9535 commit cdc190b

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

dsutil/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from . import git
44
from . import poetry
55

6-
__version__ = "0.63.0"
6+
__version__ = "0.64.0"

dsutil/docker/builder.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import tempfile
77
from pathlib import Path
88
import time
9-
import timeit
109
import datetime
1110
from collections import deque, namedtuple
1211
import shutil
@@ -73,15 +72,6 @@ def _is_image_pushed(msg: dict[str, Any]):
7372
"total"]
7473

7574

76-
def _pull_image_timing(repo: str, tag: str) -> tuple[str, str, str, float]:
77-
client = docker.from_env()
78-
logger.info("Pulling the Docker image {}:{} ...", repo, tag)
79-
seconds = timeit.timeit(
80-
lambda: client.images.pull(repo, tag), timer=time.perf_counter_ns, number=1
81-
) / 1E9
82-
return repo, tag, "pull", seconds
83-
84-
8575
def _ignore_socket(dir_, files):
8676
dir_ = Path(dir_)
8777
return [file for file in files if (dir_ / file).is_socket()]
@@ -244,7 +234,12 @@ def _copy_ssh(self, copy_ssh_to: str):
244234
shutil.copytree(ssh_src, ssh_dst, ignore=_ignore_socket)
245235
logger.info("~/.ssh has been copied to {}", ssh_dst)
246236

247-
def build(self, tag_build: str = None, copy_ssh_to: str = "") -> DockerAction:
237+
def build(
238+
self,
239+
tag_build: str = None,
240+
copy_ssh_to: str = "",
241+
builder: str = "Docker"
242+
) -> DockerAction:
248243
"""Build the Docker image.
249244
250245
:param tag_build: The tag of the Docker image to build.
@@ -266,19 +261,23 @@ def build(self, tag_build: str = None, copy_ssh_to: str = "") -> DockerAction:
266261
tag_build = "latest"
267262
logger.info("Building the Docker image {}:{} ...", self._name, tag_build)
268263
self._update_base_tag(tag_build)
269-
client = docker.APIClient(base_url="unix://var/run/docker.sock")
270264
try:
271-
for msg in client.build(
272-
path=str(self._path),
273-
tag=f"{self._name}:{tag_build}",
274-
rm=True,
275-
pull=self.is_root(),
276-
cache_from=None,
277-
decode=True
278-
):
279-
if "stream" in msg:
280-
print(msg["stream"], end="")
281-
docker.from_env().images.get(f"{self._name}:{tag_build}")
265+
if builder == "Docker":
266+
for msg in docker.APIClient(base_url="unix://var/run/docker.sock"
267+
).build(
268+
path=str(self._path),
269+
tag=f"{self._name}:{tag_build}",
270+
rm=True,
271+
pull=self.is_root(),
272+
cache_from=None,
273+
decode=True
274+
):
275+
if "stream" in msg:
276+
print(msg["stream"], end="")
277+
docker.from_env().images.get(f"{self._name}:{tag_build}")
278+
elif builder == "Kaniko":
279+
cmd = f"/kaniko/executor -c {self._path} -d {self._name}:{tag_build}"
280+
sp.run(cmd, shell=True, check=True)
282281
except docker.errors.BuildError as err:
283282
return DockerAction(
284283
succeed=False,
@@ -380,7 +379,8 @@ class DockerImageBuilder:
380379
def __init__(
381380
self,
382381
branch_urls: Union[dict[str, list[str]], str, Path],
383-
branch_fallback: str = "dev"
382+
branch_fallback: str = "dev",
383+
builder: str = "Docker",
384384
):
385385
if isinstance(branch_urls, (str, Path)):
386386
with open(branch_urls, "r") as fin:
@@ -393,6 +393,7 @@ def __init__(
393393
self._roots = set()
394394
self.failures = []
395395
self._servers = set()
396+
self._builder = builder
396397

397398
def _record_docker_servers(self, deps: deque[DockerImage]):
398399
for dep in deps:
@@ -614,7 +615,7 @@ def _build_image_node(
614615
branch=node.branch,
615616
branch_fallback=self._branch_fallback,
616617
repo_path=self._repo_path
617-
).build(tag_build=tag_build, copy_ssh_to=copy_ssh_to)
618+
).build(tag_build=tag_build, copy_ssh_to=copy_ssh_to, builder=self._builder)
618619
attr = self._graph.nodes[node]
619620
attr["build_succeed"] = succeed
620621
attr["build_err_msg"] = err_msg
@@ -623,7 +624,7 @@ def _build_image_node(
623624
if not succeed:
624625
return
625626
self._tag_image(name, tag, attr)
626-
if push:
627+
if self._builder == "Docker" and push:
627628
self._push_images(name, attr["action_time"])
628629

629630
@staticmethod

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "dsutil"
3-
version = "0.63.0"
3+
version = "0.64.0"
44
description = "A utils Python package for data scientists."
55
authors = ["Benjamin Du <[email protected]>"]
66

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Currently, Python 3.7 and 3.8 are supported.
2525
2626
You can download a copy of the latest release and install it using pip.
2727
```bash
28-
pip3 install --user -U https://github.com/dclong/dsutil/releases/download/v0.63.0/dsutil-0.63.0-py3-none-any.whl
28+
pip3 install --user -U https://github.com/dclong/dsutil/releases/download/v0.64.0/dsutil-0.64.0-py3-none-any.whl
2929
```
3030
Or you can use the following command to install the latest master branch
3131
if you have pip 20.0+.
@@ -35,7 +35,7 @@ pip3 install --user -U git+https://github.com/dclong/dsutil@main
3535
Use one of the following commands if you want to install all components of dsutil.
3636
Available additional components are `cv`, `docker`, `pdf`, `jupyter`, `admin` and `all`.
3737
```bash
38-
pip3 install "dsutil[cv] @ https://github.com/dclong/dsutil/releases/download/v0.63.0/dsutil-0.63.0-py3-none-any.whl"
38+
pip3 install "dsutil[cv] @ https://github.com/dclong/dsutil/releases/download/v0.64.0/dsutil-0.64.0-py3-none-any.whl"
3939
# or
4040
pip3 install --user -U "dsutil[all] @ git+https://github.com/dclong/dsutil@main"
4141
```

0 commit comments

Comments
 (0)