Skip to content

Commit

Permalink
Prune run containers at one other place (#1102)
Browse files Browse the repository at this point in the history
* Update docker dependency to 3.7.0

* Get rid of non-existent tracked docker images and handle empty str in
local run manager container pruning
  • Loading branch information
Kerem Goksel authored Mar 19, 2019
1 parent 3d54284 commit c782975
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions worker/codalabworker/local_run/docker_image_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def _cleanup(self):
self._docker.images.remove(tag)
# if we successfully removed the image also remove its cache entry
del self._image_cache[entry_to_remove.digest]
except docker.errors.NotFound:
# image doesn't exist anymore for some reason, stop tracking it
del self._image_cache[entry_to_remove.digest]
except docker.errors.APIError as err:
# Maybe we can't delete this image because its container is still running
# (think a run that takes 4 days so this is the oldest image but still in use)
Expand Down
12 changes: 12 additions & 0 deletions worker/codalabworker/local_run/local_run_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ def process_runs(self):
self._runs[bundle_uuid] = self._run_state_manager.transition(run_state)

# filter out finished runs
finished_container_ids = [
run.container
for run in self._runs.values()
if (run.stage == LocalRunStage.FINISHED or run.stage == LocalRunStage.FINALIZING)
and run.container_id is not None
]
for container_id in finished_container_ids:
try:
container = self._docker.containers.get(container_id)
container.remove(force=True)
except (docker.errors.NotFound, docker.errors.NullResource):
pass
self._runs = {k: v for k, v in self._runs.items() if v.stage != LocalRunStage.FINISHED}

def create_run(self, bundle, resources):
Expand Down
2 changes: 1 addition & 1 deletion worker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bottle==0.12.9
docker==3.5.0
docker==3.7.0
marshmallow-jsonapi==0.15.1
marshmallow==2.6.1
setuptools>=40.0.0
Expand Down

0 comments on commit c782975

Please sign in to comment.