Skip to content

Commit

Permalink
fix: don't remove base image needed for builds
Browse files Browse the repository at this point in the history
fix: add grader prefix for removing image from docker repo
  • Loading branch information
williams-jack committed Aug 5, 2024
1 parent ca7533e commit 8cc195b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion orchestrator/packages/image-build-service/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const removeImageFromDockerIfExists = async (dockerfileSHASum: string) =>

const deleteImage = (dockerfileSHASum: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {
execFile("docker", ["image", "rm", `${dockerfileSHASum}:latest`], (err, _stdout, _stderr) => {
execFile("docker", ["image", "rm", `grader-${dockerfileSHASum}:latest`], (err, _stdout, _stderr) => {
if (err) {
reject(err);
} else {
Expand Down
33 changes: 18 additions & 15 deletions worker/orca_grader/docker_utils/images/clean_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@

# NOTE: Docker image name lists always have a trailing new line, hence
# why the lists generated from string splitting include all but the last string.


def __get_images_used_in_last_day() -> List[str]:
"""
Returns the tags of all docker images used in the last day.
"""
res = subprocess.run(["docker", "events", "--since", "24h", "--until", "0m",
"--filter=\"type=container\"", "--filter=\"event=start\"", "--format", "{{.From}}"],
capture_output=True, check=True)
output = res.stdout.decode()
image_shas = output.split('\n')[:-1]
return image_shas
"""
Returns the tags of all docker images used in the last day.
"""
res = subprocess.run(["docker", "events", "--since", "24h", "--until", "0m",
"--filter=\"type=container\"", "--filter=\"event=start\"", "--format", "{{.From}}"],
capture_output=True, check=True)
output = res.stdout.decode()
image_shas = output.split('\n')[:-1]
return image_shas


def clean_up_unused_images() -> None:
all_images = set(get_all_docker_images())
images_used_in_last_day = set(__get_images_used_in_last_day())
images_to_remove = all_images - images_used_in_last_day
for image in images_to_remove:
subprocess.run(["docker", "image", "rm", image], stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
all_images = set(get_all_docker_images())
images_used_in_last_day = set(__get_images_used_in_last_day())
images_to_remove = all_images - images_used_in_last_day
for image in images_to_remove:
subprocess.run(["docker", "image", "rm", image], stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT)
2 changes: 2 additions & 0 deletions worker/orca_grader/docker_utils/images/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ def get_all_docker_images() -> List[str]:
capture_output=True)
output = res.stdout.decode()
image_names = output.split('\n')[:-1]
if 'orca-grader-base' in image_names:
image_names.remove('orca-grader-base')
return image_names

0 comments on commit 8cc195b

Please sign in to comment.