You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Build a Docker image using python_on_whales and Docker Buildx for multi-architecture support.
47
81
48
-
:param docker_client:
49
-
:param path: Build context path (directory with your Dockerfile)
50
-
:param dockerfile: Name or relative path of the Dockerfile within `path`
51
82
:param tag: Image tag (name:tag)
52
-
:param args:
83
+
:param dockerfile: Name or relative path of the Dockerfile within `path`
84
+
:param path: Build context path (directory with your Dockerfile)
85
+
:param args: Build arguments dictionary
86
+
:param push: Whether to push the image after building
87
+
:param platforms: List of target platforms (e.g., ["linux/amd64", "linux/arm64"])
53
88
"""
54
-
89
+
docker=python_on_whales.docker
90
+
55
91
try:
56
-
ifargs:
57
-
args= {k: str(v) fork, vinargs.items()}
58
-
image, logs=docker_client.images.build(
59
-
path=path,
60
-
dockerfile=dockerfile,
61
-
tag=tag,
62
-
pull=False, # set True to always attempt to pull a newer base image
63
-
buildargs=args,
64
-
)
65
-
logger.info(f"Successfully built {tag} (id: {image.id})")
66
-
# Print build output
67
-
forchunkinlogs:
68
-
if"stream"inchunk:
69
-
logger.debug(chunk["stream"])
70
-
exceptdocker.errors.BuildErrorase:
71
-
logger.error("Build failed:")
72
-
forstageine.build_log:
73
-
if"stream"instage:
74
-
logger.debug(stage["stream"])
75
-
elif"error"instage:
76
-
logger.error(stage["error"])
77
-
logger.error(e)
78
-
logger.error(
79
-
"Note that the docker client only surfaces the general error message. For detailed troubleshooting of the build failure, run the equivalent build command locally or use the docker Python API client directly."
92
+
# Convert build args to the format expected by python_on_whales
0 commit comments