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

Layer order got reversed in v1.1.3, resulted in squashing parent layer instead of top layer. #134

Closed
dingp opened this issue Dec 22, 2024 · 1 comment

Comments

@dingp
Copy link
Collaborator

dingp commented Dec 22, 2024

Appending to the list layers got moved outside of the if block, resulted in a reversed list of layers than the previous version v1.1.0.

This would require subsequent change of top_id = rld[-1]["id"] to top_id = rld[0]["id"].

This is the root cause of why running squashed images for multi-layer images such as ubuntu:16.04 will get something like:
Error: crun: executable file /bin/bash not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found. Looking at the directory structure of $SCRATCH/storage, one would find the squash file pointing to the parent layer, not the top layer.

The version in v1.1.3

        def _add_parent(layer, layer_map, layers=None, layer_ids=None):
            """
            Recrusive function to walk up parent graph.
            Inputs:
            layer: layer to walk
            layer_map: dictionary of layers by ID
            layers: list of layers that are being accumulated.
            layer_ids: accumulated dictionary of layers by ID
            """
            if not layer_ids:
                layer_ids = set()
            if not layers:
                layers = []
            logging.debug(f"Adding layer {layer['id']}")
            layers.append(layer)
            layer_ids.add(layer["id"])
            if "parent" in layer and layer["parent"] not in layer_ids:
                parent = layer_map[layer["parent"]]
                _add_parent(parent, layer_map, layers, layer_ids)
            return layers

old version in v1.1.0

        def _add_parent(layer, layers, by_id, layer_ids):
            """
            Recrusive function to walk up parent graph.
            Inputs:
            layer: layer to walk
            layers: list of layers that are being accumulated.
            by_id: dictionary of layers by ID
            layer_ids: accumulated dictionary of layers by ID
            """
            if "parent" in layer and layer["parent"] not in layer_ids:
                parent = by_id[layer["parent"]]
                layers.append(parent)
                layer_ids.add(parent["id"])
                _add_parent(parent, layers, by_id, layer_ids)
@dingp
Copy link
Collaborator Author

dingp commented Dec 22, 2024

Had a second look, actually the e reversed order is not caused by the relocation of append call, but the initialization of layers. Old version didn’t have that initialized explicitly so it got initialized from the inner most add_parent call.

This section in v1.1.0 caused the top layer to be placed at the end the list (the fact layers.append get called after _add_parent).

_add_parent(ld, layers, by_id, layer_ids)

        for layer in md["layers"]:
            ld = by_digest[layer["digest"]]
            layer_ids.add(ld["id"])
            _add_parent(ld, layers, by_id, layer_ids)
            layers.append(ld)

@scanon scanon closed this as completed in 60dfce3 Dec 24, 2024
scanon added a commit that referenced this issue Dec 24, 2024
fix #134 use the trusted top layer id from image info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant