|
@@ -93,13 +93,17 @@ class DockerImage:
|
|
|
return '{}(id={!r}, tags={!r})'.format(type(self).__name__, self._id, self._tags)
|
|
|
|
|
|
@classmethod
|
|
|
- def build(cls, dockerfile):
|
|
|
+ def build(cls, dockerfile_or_path):
|
|
|
out = io.BytesIO()
|
|
|
with StdoutTee(out) as tee:
|
|
|
- p = subprocess.Popen(['sudo', 'docker', 'build', '-'],
|
|
|
- stdin=subprocess.PIPE, stdout=tee)
|
|
|
- p.stdin.write(dockerfile.encode())
|
|
|
- p.stdin.close()
|
|
|
+ if os.path.exists(dockerfile_or_path):
|
|
|
+ p = subprocess.Popen(['sudo', 'docker', 'build', dockerfile_or_path],
|
|
|
+ stdin=None, stdout=tee)
|
|
|
+ else:
|
|
|
+ p = subprocess.Popen(['sudo', 'docker', 'build', '-'],
|
|
|
+ stdin=subprocess.PIPE, stdout=tee)
|
|
|
+ p.stdin.write(dockerfile_or_path.encode())
|
|
|
+ p.stdin.close()
|
|
|
assert p.wait() == 0, 'docker build failed'
|
|
|
image_id, = re.search(rb'^Successfully built (\S+)$', out.getvalue(), re.MULTILINE).groups()
|
|
|
return cls(image_id.decode(sys.stdout.encoding))
|