Merge branch 'feature/docker-args' into develop
This commit is contained in:
commit
71f2bb767f
|
@ -52,8 +52,9 @@ def get_workspace_subdir(subdir):
|
||||||
def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
|
def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
|
||||||
"""Execute an arbitrary command on the system"""
|
"""Execute an arbitrary command on the system"""
|
||||||
if debug:
|
if debug:
|
||||||
print(" ".join(cmd))
|
print(" ".join(cmd) if isinstance(cmd, list) else cmd)
|
||||||
stdin=subprocess.PIPE
|
stdin=subprocess.PIPE
|
||||||
|
kwargs['shell'] = False if isinstance(cmd, list) else True
|
||||||
if pty:
|
if pty:
|
||||||
kwargs['stdin'] = sys.stdin
|
kwargs['stdin'] = sys.stdin
|
||||||
if captureOutput:
|
if captureOutput:
|
||||||
|
@ -62,4 +63,8 @@ def run(cmd, captureOutput=False, pty=False, debug=False, **kwargs):
|
||||||
return subprocess.check_call(cmd, **kwargs)
|
return subprocess.check_call(cmd, **kwargs)
|
||||||
|
|
||||||
def run_docker(args, captureOutput=False, **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
26
package
|
@ -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("--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("--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("--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
|
return parser
|
||||||
|
|
||||||
|
@ -63,8 +64,6 @@ if __name__ == "__main__":
|
||||||
parser = create_args_parser()
|
parser = create_args_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
validate_args(args)
|
|
||||||
|
|
||||||
if args.cleanup:
|
if args.cleanup:
|
||||||
cleanup(debug=args.debug)
|
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)
|
image_tag = build_image(build_workspace, base_image, args.profile, profile, debug=args.debug, rebuild=args.rebuild)
|
||||||
|
|
||||||
# rkt run arguments
|
kwargs = dict()
|
||||||
docker_args = [
|
kwargs['debug'] = args.debug
|
||||||
"run",
|
|
||||||
"--rm",
|
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}:/src:ro".format(project_dir),
|
||||||
"-v", "{:s}:/dist".format(output_dir),
|
"-v", "{:s}:/dist".format(output_dir),
|
||||||
"-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()),
|
"-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()),
|
||||||
|
@ -100,9 +111,6 @@ if __name__ == "__main__":
|
||||||
if proxy_var in os.environ:
|
if proxy_var in os.environ:
|
||||||
docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])]
|
docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])]
|
||||||
|
|
||||||
kwargs = dict()
|
|
||||||
kwargs['debug'] = args.debug
|
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
kwargs['pty'] = True
|
kwargs['pty'] = True
|
||||||
docker_args += ["-it", image_tag, "/bin/sh"]
|
docker_args += ["-it", image_tag, "/bin/sh"]
|
||||||
|
|
Loading…
Reference in New Issue