Browse Source

DockerImage.build: added arg 'tag'

Fabian Peter Hammerle 5 years ago
parent
commit
4deabb33f6
1 changed files with 6 additions and 3 deletions
  1. 6 3
      rc.xsh

+ 6 - 3
rc.xsh

@@ -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()