Skip to content

Commit

Permalink
bugfix cache issues (#31)
Browse files Browse the repository at this point in the history
* fix(cache): don't assume type registry is always set

* add arch to cache layer name

* update changelog
  • Loading branch information
razvan authored Jul 3, 2024
1 parent b92bc2f commit a71a808
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Fixed

- Add architecture identifier to the build cache backend ref name ([#31])

[#31]: https://github.com/stackabletech/image-tools/pull/31


## [0.0.9] - 2024-07-02

### Added
Expand Down
12 changes: 8 additions & 4 deletions src/image_tools/bake.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def bakefile_product_version_targets(
}

if args.cache:
result[target_name]["cache-to"] = result[target_name]["cache-from"] = generate_cache_location(cache, target_name)
result[target_name]["cache-to"] = result[target_name]["cache-from"] = generate_cache_location(cache, target_name, args.architecture)

return result

Expand Down Expand Up @@ -163,13 +163,17 @@ def bake_command(args: Namespace, targets: List[str], bakefile) -> Command:
stdin=json.dumps(bakefile),
)

def generate_cache_location(cache: List[Dict[str, str]], target_name: str) -> List[str]:
def generate_cache_location(cache: List[Dict[str, str]], target_name: str, arch: str) -> List[str]:
cache_copy = copy.deepcopy(cache)
result = []

for backend in cache_copy:
backend["ref"] = f"{backend['ref_prefix']}:{target_name}"
del backend["ref_prefix"]
if 'ref_prefix' in backend:
# Need to replace the / from values like linux/amd64 because otherwise
# the cache ref would be invalid.
arch = arch.replace('/', '_')
backend["ref"] = f"{backend['ref_prefix']}:{target_name}-{arch}"
del backend["ref_prefix"]
result.append(",".join([f"{k}={v}" for k, v in backend.items()]))

return result
Expand Down

0 comments on commit a71a808

Please sign in to comment.