Merge branch 'feature/docker-args' into develop

This commit is contained in:
wpetit 2017-07-24 17:18:53 +02:00
commit 71f2bb767f
2 changed files with 39 additions and 26 deletions

View File

@ -52,8 +52,9 @@ def get_workspace_subdir(subdir):
def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
"""Execute an arbitrary command on the system"""
if debug:
print(" ".join(cmd))
print(" ".join(cmd) if isinstance(cmd, list) else cmd)
stdin=subprocess.PIPE
kwargs['shell'] = False if isinstance(cmd, list) else True
if pty:
kwargs['stdin'] = sys.stdin
if captureOutput:
@ -62,4 +63,8 @@ def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
return subprocess.check_call(cmd, **kwargs)
def run_docker(args, captureOutput=False, **kwargs):
return run(["docker"] + args, captureOutput=captureOutput, **kwargs)
if isinstance(args, list):
cmd = ["docker"] + args
else:
cmd = "docker " + args
return run(cmd, captureOutput=captureOutput, **kwargs)

26
package
View File

@ -21,6 +21,7 @@ def create_args_parser():
parser.add_argument("--rebuild", help="Ignore cache and rebuild container's image", action="store_true", default=False)
parser.add_argument("--debug", help="Will add extra output and start the container in interactive mode", action="store_true", default=False)
parser.add_argument("--cleanup", help="Clear the workspace and remove obsolete Docker images before build", action="store_true", default=False)
parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. Use '[IMAGE_TAG]', '[PROFILE]' and '[ARCH]' to insert the corresponding values into your command.", default="")
return parser
@ -63,8 +64,6 @@ if __name__ == "__main__":
parser = create_args_parser()
args = parser.parse_args()
validate_args(args)
if args.cleanup:
cleanup(debug=args.debug)
@ -84,10 +83,22 @@ if __name__ == "__main__":
image_tag = build_image(build_workspace, base_image, args.profile, profile, debug=args.debug, rebuild=args.rebuild)
# rkt run arguments
docker_args = [
"run",
"--rm",
kwargs = dict()
kwargs['debug'] = args.debug
docker_args = []
# Append custom arguments
if args.override_docker_args != "":
docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag)
docker_args = docker_args.replace('[PROFILE]', args.profile)
docker_args = docker_args.replace('[ARCH]', args.architecture)
else:
docker_args += [ "run", "--rm" ]
# volumes definition
docker_args += [
"-v", "{:s}:/src:ro".format(project_dir),
"-v", "{:s}:/dist".format(output_dir),
"-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()),
@ -100,9 +111,6 @@ if __name__ == "__main__":
if proxy_var in os.environ:
docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])]
kwargs = dict()
kwargs['debug'] = args.debug
if args.debug:
kwargs['pty'] = True
docker_args += ["-it", image_tag, "/bin/sh"]