瀏覽代碼

DockerImage.build: added arg 'tag'

Fabian Peter Hammerle 5 年之前
父節點
當前提交
4deabb33f6
共有 1 個文件被更改,包括 6 次插入3 次删除
  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()