fix(handlers): ensure tags are always deleted during a manifest delete
Context
Currently, the manifest delete handler removes the manifest, and then iterates through a list of it tags to remove them: https://gitlab.com/gitlab-org/container-registry/-/blob/6d2ec3d18f912e140278a2ee235fac229e4a4eda/registry/handlers/manifests.go#L1364
If there is an issue looking up the tags, or unlinking one of the tags, the operation will stop and the endpoint will return with error. If the client retries the operation, they'll encounter a 404
error since that manifest is not present, leaving the dangling tags unreachable for delete through this endpoint.
Solutions
Untag then Delete
This simply involves switching the order around, such that the manifest is only delete after all the tags have been unlinked, allowing retries on partial failures.
Check for Dangling Tags
By inspecting the errors on manifest delete, we can continue on down the logic if there is a not found error and use the provided digest to lookup any tag references and delete them if found, only returning 404
if both the manifest is not present and there are no tags associated with its digest.