Skip to content

Commit

Permalink
short circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed Jan 1, 2021
1 parent 9f588bd commit 152b369
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion WDL/runtime/task_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,13 @@ def build_inline_dockerfile(
assert maxtag2 > 0
tag = tag_part1 + tag_part2 + tag_part3

# TODO: short-circuit if image with this digest tag already exists
# short-circuit if digest-tagged image already exists
try:
existing = client.images.get(tag)
logger.notice(_("docker build cached", tag=tag, id=existing.id)) # pyre-ignore
return tag
except docker.errors.ImageNotFound:
pass

# prepare to tee docker build log to logger.verbose and a file
build_logfile = os.path.join(self.host_dir, "inlineDockerfile.log.txt")
Expand Down
16 changes: 12 additions & 4 deletions tests/test_7runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import shutil
import json
import time
import docker
from testfixtures import log_capture
from .context import WDL
Expand Down Expand Up @@ -769,7 +770,8 @@ def test_weird_filenames(self):


class TestInlineDockerfile(RunnerTestCase):
def test1(self):
@log_capture()
def test1(self, capture):
wdl = """
version development
workflow w {
Expand All @@ -778,6 +780,7 @@ def test1(self):
task t {
input {
Array[String]+ apt_pkgs
Float timestamp
}
command <<<
set -euxo pipefail
Expand All @@ -792,14 +795,19 @@ def test1(self):
runtime {
inlineDockerfile: [
"FROM ubuntu:20.04",
"RUN apt-get -qq update && apt-get install -y ${sep(' ', apt_pkgs)}"
"RUN apt-get -qq update && apt-get install -y ${sep(' ', apt_pkgs)}",
"RUN touch ${timestamp}"
]
maxRetries: 1
}
}
"""
self._run(wdl, {"t.apt_pkgs": ["samtools", "tabix"]})
self._run(wdl, {"t.apt_pkgs": ["bogusfake123"]}, expected_exception=docker.errors.BuildError)
t = time.time() # to ensure the image is built anew on every test run
self._run(wdl, {"t.apt_pkgs": ["samtools", "tabix"], "t.timestamp": t})
self._run(wdl, {"t.apt_pkgs": ["samtools", "tabix"], "t.timestamp": t})
logs = [str(record.msg) for record in capture.records if str(record.msg).startswith("docker build cached")]
self.assertEqual(len(logs), 1)
self._run(wdl, {"t.apt_pkgs": ["bogusfake123"], "t.timestamp": t}, expected_exception=docker.errors.BuildError)


class TestAbbreviatedCallInput(RunnerTestCase):
Expand Down

0 comments on commit 152b369

Please sign in to comment.