Skip to content

Commit 804852b

Browse files
flixmanp12tic
authored andcommitted
Provide support for cache_from and cache_to fields
Signed-off-by: Felix Rubio <[email protected]>
1 parent 0e3b372 commit 804852b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for cache_from and cache_to fields in build section.

podman_compose.py

+4
Original file line numberDiff line numberDiff line change
@@ -2519,6 +2519,10 @@ def container_to_build_args(compose, cnt, args, path_exists):
25192519
"--build-arg",
25202520
build_arg,
25212521
))
2522+
for cache_img in build_desc.get("cache_from", []):
2523+
build_args.extend(["--cache-from", cache_img])
2524+
for cache_img in build_desc.get("cache_to", []):
2525+
build_args.extend(["--cache-to", cache_img])
25222526
build_args.append(ctx)
25232527
return build_args
25242528

tests/unit/test_container_to_build_args.py

+30
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,33 @@ def test_labels(self):
126126
'.',
127127
],
128128
)
129+
130+
def test_caches(self):
131+
c = create_compose_mock()
132+
133+
cnt = get_minimal_container()
134+
cnt['build']['cache_from'] = ['registry/image1', 'registry/image2']
135+
cnt['build']['cache_to'] = ['registry/image3', 'registry/image4']
136+
args = get_minimal_args()
137+
138+
args = container_to_build_args(c, cnt, args, lambda path: True)
139+
self.assertEqual(
140+
args,
141+
[
142+
'-f',
143+
'./Containerfile',
144+
'-t',
145+
'new-image',
146+
'--no-cache',
147+
'--pull-always',
148+
'--cache-from',
149+
'registry/image1',
150+
'--cache-from',
151+
'registry/image2',
152+
'--cache-to',
153+
'registry/image3',
154+
'--cache-to',
155+
'registry/image4',
156+
'.',
157+
],
158+
)

0 commit comments

Comments
 (0)