Skip to content

Instantly share code, notes, and snippets.

@padusumilli
Created September 17, 2020 08:47
Show Gist options
  • Save padusumilli/3a264a14c31a9a608aa7b5ab3c4670ff to your computer and use it in GitHub Desktop.
Save padusumilli/3a264a14c31a9a608aa7b5ab3c4670ff to your computer and use it in GitHub Desktop.
Script to delete old docker images from artifactory
def clean_docker():
import requests
base_url = 'http://artifactory.local/artifactory/'
headers = {
'content-type': 'text/plain',
}
# Delete from 'docker-snapshots' repo all images older than 4 weeks and image name starts with 'vcloud' and does not end with 'RELEASE'
data = 'items.find({"repo":{"$eq":"docker-snaphots"},"path":{"$nmatch":"*RELEASE"},"path":{"$match":"vcloud*"},"stat.downloaded":{"$before":"4w"}})'
myResp = requests.post(base_url + 'api/search/aql', auth=('admin', $PWD), headers=headers, data=data)
for result in eval(myResp.text)["results"]:
artifact_url = base_url + result['repo'] + '/' + result['path']
print("Deleting " + artifact_url)
requests.delete(artifact_url, auth=('admin', $PWD))
if __name__ == '__main__':
clean_docker()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment