instantiate docker client on startup in image cleaner
ensures that it will fail promptly if it can't talk to docker
rather than waiting until the first image-purging
@@ -11,6 +11,7 @@ def get_inodes_available_fraction(path):
stat = os.statvfs(path)
return float(stat.f_favail) / float(stat.f_files)
+
def get_docker_images(client):
"""
Return list of docker images, sorted by size
@@ -19,6 +20,7 @@ def get_docker_images(client):
images.sort(key=lambda i: i.attrs['Size'], reverse=True)
return images
+
def main():
if 'PATH_TO_CHECK' not in os.environ:
print(
@@ -36,6 +38,7 @@ def main():
path_to_check = os.environ['PATH_TO_CHECK']
inode_avail_threshold = float(os.environ['INODE_AVAIL_THRESHOLD'])
+ client = docker.from_env()
print(f'Pruning docker images when {path_to_check} has less than {inode_avail_threshold}% inodes free')
@@ -47,7 +50,6 @@ def main():
time.sleep(60)
continue
else:
- client = docker.from_env()
images = get_docker_images(client)
while get_inodes_available_fraction(path_to_check) < inode_avail_threshold:
@@ -64,5 +66,6 @@ def main():
else:
raise
+
if __name__ == '__main__':
main()
