Gcrane / List Untagged Images
List Untagged Images
Identifies and lists untagged images within a specified GCR repository.
gcrane gc <repository> gcrane gc <repository> #!/bin/bash
# List Untagged Images
gcrane gc {{repository}} import subprocess
# List Untagged Images
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"gcrane",
"gc",
"<repository>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: gcrane not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
When clearing up space or preparing for image tagging and retention policies.
Pro Tip
Combine with manual audits to ensure untagged images identified are indeed obsolete before deletion.
Anatomy of Output
Understanding the result
UNTAGGED IMAGES: gcr.io/my-repo/image1 Untagged Image Image lacking a tag in the specified repository.
UNTAGGED IMAGES: gcr.io/my-repo/image2 Untagged Image Additional untagged image found.
TOTAL UNTAGGED IMAGES: 5 Count Total number of untagged images in the repository.
Power User Variants
Optimized versions
gcrane gc gcr.io/my-repo --dry-run Simulate untagged image listing without deletion.
gcrane gc gcr.io/my-repo --all List untagged images across all hierarchies.
Troubleshooting
Common pitfalls
Error: repository 'gcr.io/my-repo' is empty.
Solution: Verify the repository contains images or correct the specified name.
Error: unable to access GCR for untagged images.
Solution: Inspect IAM permissions for necessary read access.
Error: invalid repository name format.
Solution: Ensure proper GCR naming conventions are followed.
Command Breakdown
What each part is doing
-
gcrane - Base Command
- The executable that performs this operation. Here it runs Gcrane before the shell applies any redirect operators.
-
<repository> - repository
- The value supplied for repository.
Alternative Approaches
Comparable commands in other tools
Alternative version control tools for the same job.