Open idontusenumbers opened 5 years ago
@prune998 I have faced the same issue, found out that i am using the wrong digest , you have to use the digest you received from header "Docker-Content-Digest" , then first delete the tags associated with image and then the image would be delete
Following code works fine
def delete_image(service_name,token,tag): # manifest request BASE_URL = "https://gcr.io/v2/"; manifest_url = BASE_URL+'/'+service_name+'/'+'manifests/'+tag headers = {'Authorization': 'Bearer ' + token, "Accept": "application/vnd.docker.distribution.manifest.v2+json" } manifest_get_response = requests.get(manifest_url, headers=headers) if(manifest_get_response.status_code>=400): return "Not deleted error occured with getting manifest" # delete tag del_tag_url = BASE_URL+PROJECT_NAME+'/'+service_name+'/'+'manifests/'+tag tag_delete_response = requests.delete(del_tag, headers=headers) if(tag_response.status_code>=400): return "Not deleted error occured with tag deletion" # delete image manifest_digest = r.headers['Docker-Content-Digest'] del_image_url = BASE_URL+PROJECT_NAME+'/'+service_name+'/'+'manifests/'+manifest_digest image_delete_response = requests.delete(del_url, headers=headers) if(image_delete_response.status_code>=400): return "Not deleted error occured with image deletion" return "Deleted"
I stumbled upon this repo while trying to cleanup some docker images in google cloud repository; not sure if you're still maintaining this but I had luck with the following code: