Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide support for cache_from and cache_to fields #1092

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/cache-fields-support.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for cache_from and cache_to fields in build section.
4 changes: 4 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2519,6 +2519,10 @@ def container_to_build_args(compose, cnt, args, path_exists):
"--build-arg",
build_arg,
))
for cache_img in build_desc.get("cache_from", []):
build_args.extend(["--cache-from", cache_img])
for cache_img in build_desc.get("cache_to", []):
build_args.extend(["--cache-to", cache_img])
build_args.append(ctx)
return build_args

Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_container_to_build_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,33 @@ def test_labels(self):
'.',
],
)

def test_caches(self):
c = create_compose_mock()

cnt = get_minimal_container()
cnt['build']['cache_from'] = ['registry/image1', 'registry/image2']
cnt['build']['cache_to'] = ['registry/image3', 'registry/image4']
args = get_minimal_args()

args = container_to_build_args(c, cnt, args, lambda path: True)
self.assertEqual(
args,
[
'-f',
'./Containerfile',
'-t',
'new-image',
'--no-cache',
'--pull-always',
'--cache-from',
'registry/image1',
'--cache-from',
'registry/image2',
'--cache-to',
'registry/image3',
'--cache-to',
'registry/image4',
'.',
],
)
Loading