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

Name the cached images to make it easier to clean up the cached images #208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,10 @@ It will process the same as `docker`'s `--volume` option, `rocker --volume` take
- 2nd field: (optional) the path where the file or directory is mounted in the container.
- If only the 1st field is supplied, same value as the 1st field will be populated as the 2nd field.
- 3rd field: (optional) bind propagation as `ro`, `z`, and `Z`. See [docs.docker.com](https://docs.docker.com/storage/bind-mounts/) for further detail.


## Helpful tips

Clean up the rocker cache

`docker images | grep rocker_cache | awk '{ printf $1":"$2; print"" }' | xargs docker rmi`
19 changes: 18 additions & 1 deletion src/rocker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from collections import OrderedDict
import io
from hashlib import md5
import os
import re
import sys
Expand Down Expand Up @@ -225,8 +226,15 @@ def build(self, **kwargs):
arguments['pull'] = kwargs.get('pull', False)
image_name = kwargs.get('image_name', None)
if image_name:
print(f"Running docker tag {self.image_id} {image_name}")
arguments['tag'] = image_name
else:
kwhash = self.get_argument_hash(kwargs)
#TODO(tfoote) Only flag extensions in the image (aka skip runtime only)
tag = 'rocker_cache:' + kwargs.get('image', '').replace(':', '_') + '_extensions__' + '_'.join([x.name for x in self.active_extensions]) + '__arghash' + str(kwhash)
arguments['tag'] = tag

print(f"{kwargs} Generated Image Tagged: {tag}")

print("Building docker file with arguments: ", arguments)
try:
self.image_id = docker_build(
Expand All @@ -243,6 +251,15 @@ def build(self, **kwargs):
print("Docker build failed\n", ex)
return 1

def get_argument_hash(self, kwargs):
""" Compute the has of the arguments excluding elements not included
in the image such as the command
"""
# TODO(tfoote) flag specific keywords as being in the image vs only runtime
invariant = kwargs
invariant.pop('command')
return md5(str(invariant).encode()).hexdigest()

def get_operating_mode(self, args):
operating_mode = args.get('mode')
# Default to non-interactive if unset
Expand Down