Skip to content

Commit

Permalink
core: versionchooser: cleanup dangling docker images when starting up
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed May 3, 2022
1 parent 2c5e1ef commit 48caf7c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 48caf7c

Please sign in to comment.