Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: versionchooser: cleanup dangling docker images when starting up #1005

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/services/versionchooser/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"aiohttp-jinja2 == 1.4.2",
"aiohttp == 3.7.4",
"aiodocker == 0.21.0",
"docker == 5.0.3",
"jsonschema == 3.2.0",
"pyrsistent == 0.16.0",
"connexion[swagger-ui, aiohttp] @ https://github.com/zalando/[email protected]",
Expand Down
11 changes: 11 additions & 0 deletions core/services/versionchooser/utils/chooser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import json
import logging
import pathlib
import sys
from dataclasses import asdict
from datetime import datetime
from typing import Dict, List, Optional, Tuple, Union

import aiodocker
import appdirs
import docker
from aiohttp import web

from utils.dockerhub import TagFetcher, TagMetadata
Expand All @@ -24,6 +26,15 @@
class VersionChooser:
def __init__(self, client: aiodocker.Docker):
self.client = client
self.cleanup()

@staticmethod
def cleanup() -> None:
if "pytest" in sys.modules: # don't run this in testing environment
return
# TODO: migrate this to aiodocker once https://github.com/aio-libs/aiodocker/issues/696 is fixed
client = docker.from_env()
client.images.prune({"dangling": True})

@staticmethod
def index() -> web.FileResponse:
Expand Down