Fix the garbage collect method to remove unused old images.
This commit is contained in:
		
							parent
							
								
									e7064f1191
								
							
						
					
					
						commit
						7428d2aa50
					
				
					 1 changed files with 7 additions and 3 deletions
				
			
		|  | @ -1011,15 +1011,19 @@ def garbage_collect_repository(namespace_name, repository_name): | ||||||
|     uuids_to_check_for_gc = set() |     uuids_to_check_for_gc = set() | ||||||
|     for image_id_to_remove in to_remove: |     for image_id_to_remove in to_remove: | ||||||
|       image_to_remove = all_images[image_id_to_remove] |       image_to_remove = all_images[image_id_to_remove] | ||||||
|       image_to_remove.delete_instance() |  | ||||||
| 
 | 
 | ||||||
|       if not image_to_remove.storage: |       if not image_to_remove.storage or not image_to_remove.storage.id: | ||||||
|         image_path = store.image_path(namespace_name, repository_name, |         image_path = store.image_path(namespace_name, repository_name, | ||||||
|                                       image_to_remove.docker_image_id, None) |                                       image_to_remove.docker_image_id, None) | ||||||
|         logger.debug('Deleting image storage: %s', image_path) |         logger.debug('Deleting image storage: %s', image_path) | ||||||
|  |         store.remove(image_path) | ||||||
|       else: |       else: | ||||||
|  |         logger.debug('Adding image storage to the gc list: %s', | ||||||
|  |                      image_to_remove.storage.uuid) | ||||||
|         uuids_to_check_for_gc.add(image_to_remove.storage.uuid) |         uuids_to_check_for_gc.add(image_to_remove.storage.uuid) | ||||||
| 
 | 
 | ||||||
|  |       image_to_remove.delete_instance() | ||||||
|  | 
 | ||||||
|     storage_to_remove = (ImageStorage |     storage_to_remove = (ImageStorage | ||||||
|       .select() |       .select() | ||||||
|       .join(Image, JOIN_LEFT_OUTER) |       .join(Image, JOIN_LEFT_OUTER) | ||||||
|  | @ -1139,7 +1143,7 @@ def delete_all_repository_tags(namespace_name, repository_name): | ||||||
|   except Repository.DoesNotExist: |   except Repository.DoesNotExist: | ||||||
|     raise DataModelException('Invalid repository \'%s/%s\'' % |     raise DataModelException('Invalid repository \'%s/%s\'' % | ||||||
|                              (namespace_name, repository_name)) |                              (namespace_name, repository_name)) | ||||||
|   RepositoryTag.delete().where(RepositoryTag.repository == repo).execute() |   RepositoryTag.delete().where(RepositoryTag.repository == repo.id).execute() | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def __entity_permission_repo_query(entity_id, entity_table, | def __entity_permission_repo_query(entity_id, entity_table, | ||||||
|  |  | ||||||
		Reference in a new issue