|
@@ -96,14 +96,17 @@ class DockerImage:
|
|
|
return '{}(id={!r}, tags={!r})'.format(type(self).__name__, self._id, self._tags)
|
|
|
|
|
|
@classmethod
|
|
|
- def build(cls, dockerfile_or_path):
|
|
|
+ def build(cls, dockerfile_or_path, tag=None):
|
|
|
out = io.BytesIO()
|
|
|
+ args = ['sudo', 'docker', 'build']
|
|
|
+ if tag:
|
|
|
+ args.extend(['--tag', tag])
|
|
|
with StdoutTee(out) as tee:
|
|
|
if os.path.exists(dockerfile_or_path):
|
|
|
- p = subprocess.Popen(['sudo', 'docker', 'build', dockerfile_or_path],
|
|
|
+ p = subprocess.Popen(args + [dockerfile_or_path],
|
|
|
stdin=None, stdout=tee)
|
|
|
else:
|
|
|
- p = subprocess.Popen(['sudo', 'docker', 'build', '-'],
|
|
|
+ p = subprocess.Popen(args + ['-'],
|
|
|
stdin=subprocess.PIPE, stdout=tee)
|
|
|
p.stdin.write(dockerfile_or_path.encode())
|
|
|
p.stdin.close()
|