From 17d371c804a2e61721a25103c3262ca90563d051 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 10 Jul 2017 17:24:12 +0200 Subject: [PATCH 01/10] Add flag to append custom arguments to the docker run command --- package | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package b/package index 4d95fe7..72f9032 100755 --- a/package +++ b/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("--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("-d", "--docker-arg", help="Additional argument to pass to the Docker execution", default=[], action='append') return parser @@ -63,7 +64,7 @@ if __name__ == "__main__": parser = create_args_parser() args = parser.parse_args() - validate_args(args) + print(args.docker_arg) if args.cleanup: cleanup(debug=args.debug) @@ -111,6 +112,9 @@ if __name__ == "__main__": else: docker_args += [image_tag, "/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture] + # Append custom arguments + docker_args += args.docker_arg + # Start container tamarin.run_docker(docker_args, **kwargs) From 7ead22e8ecdb5ba94c127298d89e46bfe43f8a54 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 10 Jul 2017 17:29:39 +0200 Subject: [PATCH 02/10] Fix arguments order --- package | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/package b/package index 72f9032..412f75d 100755 --- a/package +++ b/package @@ -64,8 +64,6 @@ if __name__ == "__main__": parser = create_args_parser() args = parser.parse_args() - print(args.docker_arg) - if args.cleanup: cleanup(debug=args.debug) @@ -104,6 +102,9 @@ if __name__ == "__main__": kwargs = dict() kwargs['debug'] = args.debug + # Append custom arguments + docker_args += args.docker_arg + if args.debug: kwargs['pty'] = True docker_args += ["-it", image_tag, "/bin/sh"] @@ -112,9 +113,6 @@ if __name__ == "__main__": else: docker_args += [image_tag, "/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture] - # Append custom arguments - docker_args += args.docker_arg - # Start container tamarin.run_docker(docker_args, **kwargs) From 50f578216bc3287c9d49a9b17ce2e154d6216b73 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 11:56:41 +0200 Subject: [PATCH 03/10] Ajout drapeau pour surcharger totalement les drapeaux docker --- package | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/package b/package index 412f75d..c4e3332 100755 --- a/package +++ b/package @@ -21,7 +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("-d", "--docker-arg", help="Additional argument to pass to the Docker execution", default=[], action='append') + parser.add_argument("-f", "--override-run-flags", help="Override 'docker run' flags", default=[], action='append') return parser @@ -83,27 +83,28 @@ 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", - "-v", "{:s}:/src:ro".format(project_dir), - "-v", "{:s}:/dist".format(output_dir), - "-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()), - "-v", "{:s}:/tamarin/lib:ro".format(tamarin.get_lib_dir()), - "-v", "{:s}:/tamarin/profiles:ro".format(tamarin.get_profiles_dir()) - ] - - # Use environment proxy if defined - for proxy_var in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']: - if proxy_var in os.environ: - docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])] - kwargs = dict() kwargs['debug'] = args.debug # Append custom arguments - docker_args += args.docker_arg + if len(args.override_run_flags) > 0: + docker_args += args.override_run_flags + else: + # rkt run arguments + docker_args = [ + "run", + "--rm", + "-v", "{:s}:/src:ro".format(project_dir), + "-v", "{:s}:/dist".format(output_dir), + "-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()), + "-v", "{:s}:/tamarin/lib:ro".format(tamarin.get_lib_dir()), + "-v", "{:s}:/tamarin/profiles:ro".format(tamarin.get_profiles_dir()) + ] + + # Use environment proxy if defined + for proxy_var in ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']: + if proxy_var in os.environ: + docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])] if args.debug: kwargs['pty'] = True From 16b0ef996dc3500bc841f7f94dc976de946a2fbf Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 12:07:00 +0200 Subject: [PATCH 04/10] Correction init docker_args --- package | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package b/package index c4e3332..8d2b3b2 100755 --- a/package +++ b/package @@ -86,12 +86,14 @@ if __name__ == "__main__": kwargs = dict() kwargs['debug'] = args.debug + docker_args = [] + # Append custom arguments if len(args.override_run_flags) > 0: docker_args += args.override_run_flags else: # rkt run arguments - docker_args = [ + docker_args += [ "run", "--rm", "-v", "{:s}:/src:ro".format(project_dir), From 7f8a13bd523e008a775efc73da2f46c022755f56 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 12:14:38 +0200 Subject: [PATCH 05/10] Add default flags --- package | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package b/package index 8d2b3b2..99d5bbd 100755 --- a/package +++ b/package @@ -86,16 +86,17 @@ if __name__ == "__main__": kwargs = dict() kwargs['debug'] = args.debug - docker_args = [] + docker_args = [ + "run", + "--rm", + ] # Append custom arguments if len(args.override_run_flags) > 0: docker_args += args.override_run_flags else: - # rkt run arguments + # volumes definition docker_args += [ - "run", - "--rm", "-v", "{:s}:/src:ro".format(project_dir), "-v", "{:s}:/dist".format(output_dir), "-v", "{:s}:/tamarin/hooks:ro".format(tamarin.get_hooks_dir()), From f1bccc8e23307ede77325229e6393731b9bcb8e8 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 14:36:22 +0200 Subject: [PATCH 06/10] OVerride all --- package | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/package b/package index 99d5bbd..d2b247f 100755 --- a/package +++ b/package @@ -21,7 +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("-f", "--override-run-flags", help="Override 'docker run' flags", default=[], action='append') + parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. You can use this flag multiple times to add custom arguments", default=[], action='append') return parser @@ -86,15 +86,15 @@ if __name__ == "__main__": kwargs = dict() kwargs['debug'] = args.debug - docker_args = [ - "run", - "--rm", - ] + docker_args = [] # Append custom arguments - if len(args.override_run_flags) > 0: - docker_args += args.override_run_flags + if len(args.override_docker_args) > 0: + docker_args += args.override_docker_args else: + + docker_args += [ "run", "--rm" ] + # volumes definition docker_args += [ "-v", "{:s}:/src:ro".format(project_dir), @@ -109,13 +109,13 @@ if __name__ == "__main__": if proxy_var in os.environ: docker_args += ["-e", "{:s}={:s}".format(proxy_var, os.environ[proxy_var])] - if args.debug: - kwargs['pty'] = True - docker_args += ["-it", image_tag, "/bin/sh"] - helper_cmd = " ".join(["/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture]) - print("Executer '{:s}' pour lancer la construction du paquet.".format(helper_cmd)) - else: - docker_args += [image_tag, "/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture] + if args.debug: + kwargs['pty'] = True + docker_args += ["-it", image_tag, "/bin/sh"] + helper_cmd = " ".join(["/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture]) + print("Executer '{:s}' pour lancer la construction du paquet.".format(helper_cmd)) + else: + docker_args += [image_tag, "/usr/bin/python3", "/tamarin/lib/build.py", args.profile, args.architecture] # Start container tamarin.run_docker(docker_args, **kwargs) From 4e27cc8b6eaea780420e8aeb3bde7a733eb7e189 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 14:42:52 +0200 Subject: [PATCH 07/10] IMAGE_TAG templating in arguments --- package | 1 + 1 file changed, 1 insertion(+) diff --git a/package b/package index d2b247f..e6ce889 100755 --- a/package +++ b/package @@ -91,6 +91,7 @@ if __name__ == "__main__": # Append custom arguments if len(args.override_docker_args) > 0: docker_args += args.override_docker_args + docker_args = [a.replace('[IMAGE_TAG]', image_tag) for a in docker_args] else: docker_args += [ "run", "--rm" ] From 110097ec817f017ecd814fe0cf02e27c2fcbdd12 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 11 Jul 2017 17:39:47 +0200 Subject: [PATCH 08/10] String override --- lib/tamarin.py | 9 +++++++-- package | 7 +++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/tamarin.py b/lib/tamarin.py index de1bfb8..0d9d150 100644 --- a/lib/tamarin.py +++ b/lib/tamarin.py @@ -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) diff --git a/package b/package index e6ce889..5a47719 100755 --- a/package +++ b/package @@ -21,7 +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. You can use this flag multiple times to add custom arguments", default=[], action='append') + parser.add_argument("--override-docker-args", help="Override all 'docker run' arguments. Use '[IMAGE_TAG]' to insert the generated image's name.", default="") return parser @@ -89,9 +89,8 @@ if __name__ == "__main__": docker_args = [] # Append custom arguments - if len(args.override_docker_args) > 0: - docker_args += args.override_docker_args - docker_args = [a.replace('[IMAGE_TAG]', image_tag) for a in docker_args] + if args.override_docker_args != "": + docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag) else: docker_args += [ "run", "--rm" ] From 422407a37cd2e51ecdda85fb008b18332343ad90 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 17 Jul 2017 17:54:25 +0200 Subject: [PATCH 09/10] =?UTF-8?q?Ajout=20des=20points=20d'insertions=20[AR?= =?UTF-8?q?CH]=20et=20[PROFILE]=20pour=20la=20commande=20pass=C3=A9e=20au?= =?UTF-8?q?=20drapeau=20override-docker-args?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package b/package index 5a47719..3fe963c 100755 --- a/package +++ b/package @@ -21,7 +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]' to insert the generated image's name.", default="") + 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 @@ -91,6 +91,8 @@ if __name__ == "__main__": # Append custom arguments if args.override_docker_args != "": docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag) + docker_args = args.override_docker_args.replace('[PROFILE]', args.profile) + docker_args = args.override_docker_args.replace('[ARCH]', args.architecture) else: docker_args += [ "run", "--rm" ] From 948745877c06671425ab4b27ea13603f0acc54f4 Mon Sep 17 00:00:00 2001 From: William Petit Date: Mon, 17 Jul 2017 17:59:33 +0200 Subject: [PATCH 10/10] Fix templating --- package | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package b/package index 3fe963c..d02b2ce 100755 --- a/package +++ b/package @@ -91,8 +91,8 @@ if __name__ == "__main__": # Append custom arguments if args.override_docker_args != "": docker_args = args.override_docker_args.replace('[IMAGE_TAG]', image_tag) - docker_args = args.override_docker_args.replace('[PROFILE]', args.profile) - docker_args = args.override_docker_args.replace('[ARCH]', args.architecture) + docker_args = docker_args.replace('[PROFILE]', args.profile) + docker_args = docker_args.replace('[ARCH]', args.architecture) else: docker_args += [ "run", "--rm" ]