@@ -66,6 +66,28 @@ def build(self, **kwargs) -> tuple[Image, Iterator[bytes]]:
6666 layers (bool) - Cache intermediate layers during build.
6767 output (str) - specifies if any custom build output is selected for following build.
6868 outputformat (str) - The format of the output image's manifest and configuration data.
69+ volumes (dict[str, dict[str, Union[str, list]]])
70+ Mount a host directory into containers when executing RUN instructions during the build.
71+ The key is the host path and the value is a dictionary with the keys:
72+
73+ - bind: The path to mount the volume inside the container
74+ - mode: One or multiple of [ro|rw],[z|Z|O],[U],[[r]shared|[r]slave|[r]private]
75+ By default, the volumes are mounted read-write
76+
77+ For example:
78+
79+ {
80+
81+ '/etc/host':
82+
83+ {'bind': '/etc/host', 'mode': 'ro'},
84+
85+ '/tmp/cache':
86+
87+ {'bind': '/var/cache/libdnf5', 'mode': ['rw', 'z']},
88+
89+ }
90+
6991
7092 Returns:
7193 first item is the podman.domain.images.Image built
@@ -184,6 +206,7 @@ def _render_params(kwargs) -> dict[str, list[Any]]:
184206 "layers" : kwargs .get ("layers" ),
185207 "output" : kwargs .get ("output" ),
186208 "outputformat" : kwargs .get ("outputformat" ),
209+ "volume" : [],
187210 }
188211
189212 if "buildargs" in kwargs :
@@ -215,5 +238,17 @@ def default(value, def_value):
215238 params ["dockerfile" ], f".containerfile.{ random .getrandbits (160 ):x} "
216239 )
217240
241+ volumes = kwargs .get ("volumes" )
242+ if volumes is not None :
243+ for hostdir , target in volumes .items ():
244+ mode = target .get ('mode' , [])
245+ binddir = target .get ('bind' )
246+ if binddir is None :
247+ raise ValueError ("'bind' value not defined" )
248+ if not isinstance (mode , list ):
249+ raise ValueError ("'mode' value should be a list" )
250+ mode_str = "," .join (mode )
251+ params ["volume" ].append (f"{ hostdir } :{ target ['bind' ]} :{ mode_str } " )
252+
218253 # Remove any unset parameters
219254 return dict (filter (lambda i : i [1 ] is not None , params .items ()))
0 commit comments