20
20
"""Image building."""
21
21
22
22
23
- import json
23
+ import subprocess # nosec
24
24
from pathlib import Path
25
- from typing import Dict , Optional , Tuple
25
+ from typing import Optional , Tuple
26
26
27
27
from aea .cli .utils .config import get_default_author_from_cli_config
28
28
from aea .configurations .data_types import Dependency , PublicId
35
35
)
36
36
from autonomy .data import DATA_DIR
37
37
from autonomy .deploy .constants import DOCKERFILES
38
- from autonomy .deploy .generators .docker_compose .base import get_docker_client
39
38
40
39
41
40
def generate_dependency_flag_var (dependencies : Tuple [Dependency , ...]) -> str :
@@ -64,20 +63,13 @@ def build_image( # pylint: disable=too-many-arguments,too-many-locals
64
63
image_author : Optional [str ] = None ,
65
64
extra_dependencies : Optional [Tuple [Dependency , ...]] = None ,
66
65
dockerfile : Optional [Path ] = None ,
66
+ platform : Optional [str ] = None ,
67
+ push : bool = False ,
67
68
) -> None :
68
69
"""Command to build images from for skaffold deployment."""
69
70
70
71
tag : str
71
72
path : str
72
- buildargs : Dict [str , str ]
73
- docker_client = get_docker_client ()
74
- buildargs = {
75
- "AUTONOMY_IMAGE_NAME" : AUTONOMY_IMAGE_NAME ,
76
- "AUTONOMY_IMAGE_VERSION" : AUTONOMY_IMAGE_VERSION ,
77
- "AEA_AGENT" : str (agent ),
78
- "AUTHOR" : get_default_author_from_cli_config (),
79
- "EXTRA_DEPENDENCIES" : generate_dependency_flag_var (extra_dependencies or ()),
80
- }
81
73
82
74
image_version = version or agent .hash
83
75
path = str (DATA_DIR / DOCKERFILES / "agent" )
@@ -90,30 +82,35 @@ def build_image( # pylint: disable=too-many-arguments,too-many-locals
90
82
version = image_version ,
91
83
)
92
84
93
- stream = docker_client .api .build (
94
- path = path ,
95
- tag = tag ,
96
- buildargs = buildargs ,
97
- pull = pull ,
85
+ build_process = subprocess .run ( # nosec # pylint: disable=subprocess-run-check
86
+ [
87
+ "docker" ,
88
+ "build" ,
89
+ "--build-arg" ,
90
+ f"AUTONOMY_IMAGE_NAME={ AUTONOMY_IMAGE_NAME } " ,
91
+ "--build-arg" ,
92
+ f"AUTONOMY_IMAGE_VERSION={ AUTONOMY_IMAGE_VERSION } " ,
93
+ "--build-arg" ,
94
+ f"AUTHOR={ get_default_author_from_cli_config ()} " ,
95
+ "--build-arg" ,
96
+ f"AEA_AGENT={ str (agent )} " ,
97
+ "--build-arg" ,
98
+ f"EXTRA_DEPENDENCIES={ generate_dependency_flag_var (extra_dependencies or ())} " ,
99
+ "--tag" ,
100
+ tag ,
101
+ "--no-cache" ,
102
+ ]
103
+ + (["--platform" , platform ] if platform else [])
104
+ + []
105
+ + (["--push" ] if push else [])
106
+ + []
107
+ + (["--pull" ] if pull else [])
108
+ + [
109
+ path ,
110
+ ]
98
111
)
99
112
100
- for stream_obj in stream :
101
- for line in stream_obj .decode ().split ("\n " ):
102
- line = line .strip ()
103
- if not line :
104
- continue
105
- stream_data = json .loads (line )
106
- if "stream" in stream_data :
107
- print ("[docker]" + stream_data ["stream" ], end = "" )
108
- elif "errorDetail" in stream_data :
109
- raise ImageBuildFailed (
110
- "Image build failed with error "
111
- + stream_data ["errorDetail" ]["message" ]
112
- )
113
- elif "aux" in stream_data :
114
- print ("[docker]" + stream_data ["aux" ]["ID" ], end = "" )
115
- elif "status" in stream_data : # pragma: no cover
116
- print ("[docker]" + stream_data ["status" ], end = "" )
113
+ build_process .check_returncode ()
117
114
118
115
119
116
class ImageBuildFailed (Exception ):
0 commit comments