Browse Source

new Dockerfile keyword: cmd to set a default runtime command

Solomon Hykes 12 years ago
parent
commit
e7fb7f13d5
1 changed files with 12 additions and 2 deletions
  1. 12 2
      contrib/docker-build/docker-build

+ 12 - 2
contrib/docker-build/docker-build

@@ -50,7 +50,7 @@ def image_exists(img):
 	return docker(["inspect", img]).read().strip() != ""
 	return docker(["inspect", img]).read().strip() != ""
 
 
 def image_config(img):
 def image_config(img):
-	return json.loads(docker(["inspect", img]).read()).get("Config", {})
+	return json.loads(docker(["inspect", img]).read()).get("config", {})
 
 
 def run_and_commit(img_in, cmd, stdin=None, author=None, run=None):
 def run_and_commit(img_in, cmd, stdin=None, author=None, run=None):
 	run_id = docker(["run"] + (["-i", "-a", "stdin"] if stdin else ["-d"]) + [img_in, "/bin/sh", "-c", cmd], stdin=stdin).read().rstrip()
 	run_id = docker(["run"] + (["-i", "-a", "stdin"] if stdin else ["-d"]) + [img_in, "/bin/sh", "-c", cmd], stdin=stdin).read().rstrip()
@@ -111,12 +111,22 @@ def main():
 				print "===> " + base
 				print "===> " + base
 			elif op == "expose":
 			elif op == "expose":
 				config = image_config(base)
 				config = image_config(base)
+				if config.get("PortSpecs") is None:
+					config["PortSpecs"] = []
 				portspec = param.strip()
 				portspec = param.strip()
-				config.setdefault("PortSpecs", []).append(portspec)
+				config["PortSpecs"].append(portspec)
 				result = run_and_commit(base, "# (nop) expose port {}".format(portspec), author=maintainer, run=config)
 				result = run_and_commit(base, "# (nop) expose port {}".format(portspec), author=maintainer, run=config)
 				steps.append(result)
 				steps.append(result)
 				base=result
 				base=result
 				print "===> " + base
 				print "===> " + base
+			elif op == "cmd":
+				config  = image_config(base)
+				cmd = list(json.loads(param))
+				config["Cmd"] = cmd
+				result = run_and_commit(base, "# (nop) set default command to '{}'".format(" ".join(cmd)), author=maintainer, run=config)
+				steps.append(result)
+				base=result
+				print "===> " + base
 			else:
 			else:
 				print "Skipping uknown op " + op
 				print "Skipping uknown op " + op
 	except:
 	except: