diff --git a/package b/package index de6ab43..6bc6969 100755 --- a/package +++ b/package @@ -17,7 +17,9 @@ def create_args_parser(): parser.add_argument("-o", "--output", help="The path to the generated packages destination directory", default=".") parser.add_argument("-p", "--profile", help="The profile to use to package this project (default: debian)", choices=profile_names, default='debian') parser.add_argument("-a", "--architecture", help="The target architecture for the package (default: amd64)", default='amd64') + parser.add_argument("-b", "--base", help="Use the specified image instead of the profile's one", default='') 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) return parser @@ -49,7 +51,7 @@ def get_cached_image_path(profile): def build_image(build_workspace, aci_file, base_image, profile): - acbuild_flags = ["--modify", aci_file, "--work-path", build_workspace] + acbuild_flags = ["--work-path", build_workspace] # Find and export base image from rkt' store name_pattern = base_image.split('/')[-1] + '$' @@ -57,6 +59,7 @@ def build_image(build_workspace, aci_file, base_image, profile): rkt.export_image(image['id'], aci_file, rkt_flags=rkt_flags); # Build image + tamarin.run_acbuild(acbuild_flags+["begin", aci_file]) tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)]) tamarin.run_acbuild(acbuild_flags+["mount", "add", "src", "/src", "--read-only"]) tamarin.run_acbuild(acbuild_flags+["mount", "add", "dist", "/dist"]) @@ -73,6 +76,9 @@ def build_image(build_workspace, aci_file, base_image, profile): # Run hooks tamarin.run_profile_hooks(profile, 'containerbuild', cwd=build_workspace, env=hooks_env) + tamarin.run_acbuild(acbuild_flags+["write", "--overwrite", aci_file]) + tamarin.run_acbuild(acbuild_flags+["end"]) + return aci_file def cleanup(build_workspace, rkt_flags): @@ -126,7 +132,7 @@ if __name__ == "__main__": rkt_store = tamarin.get_workspace_subdir('store') rkt_flags = ["--dir={:s}".format(rkt_store)] - base_image = profile['profile']['default_image'] + base_image = args.base if args.base != '' else profile['profile']['default_image'] # If the base image is Docker-based, download it if base_image.startswith('docker://'): @@ -147,23 +153,30 @@ if __name__ == "__main__": # Cache image shutil.copyfile(aci_file, cached_image_file) + # rkt run arguments + rkt_args = [ + "run", + "--insecure-options=image", + aci_file, "--net=host", + "--volume=src,kind=host,source={:s}".format(project_dir), + "--volume=dist,kind=host,source={:s}".format(output_dir), + "--volume=tamarin-hooks,kind=host,source={:s}".format(tamarin.get_hooks_dir()), + "--volume=tamarin-lib,kind=host,source={:s}".format(tamarin.get_lib_dir()), + "--volume=tamarin-profiles,kind=host,source={:s}".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: + rkt_args += ["--set-env={:s}={:s}".format(proxy_var, os.environ[proxy_var])] + + if args.debug: + rkt_args += ["--interactive", "--exec", "/bin/bash"] + else: + rkt_args += ["--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py", args.profile, args.architecture] + # Start container - rkt.run(rkt_flags+[ - "run", - "--insecure-options=image", - aci_file, "--net=host", - "--volume=src,kind=host,source={:s}".format(project_dir), - "--volume=dist,kind=host,source={:s}".format(output_dir), - "--volume=tamarin-hooks,kind=host,source={:s}".format(tamarin.get_hooks_dir()), - "--volume=tamarin-lib,kind=host,source={:s}".format(tamarin.get_lib_dir()), - "--volume=tamarin-profiles,kind=host,source={:s}".format(tamarin.get_profiles_dir()), - "--set-env=HTTP_PROXY={:s}".format(os.environ['HTTP_PROXY']), - "--set-env=HTTPS_PROXY={:s}".format(os.environ['HTTP_PROXY']), - "--set-env=http_proxy={:s}".format(os.environ['http_proxy']), - "--set-env=https_proxy={:s}".format(os.environ['https_proxy']), - #"--interactive", "--exec", "/bin/bash" - "--exec", "/usr/bin/python3", "--", "/tamarin/lib/build.py", args.profile, args.architecture - ], as_root=True) + rkt.run(rkt_flags+rkt_args, as_root=True) # Cleanup cleanup(build_workspace, rkt_flags)