diff --git a/lib/tamarin.py b/lib/tamarin.py index 5d31b16..8123dd5 100644 --- a/lib/tamarin.py +++ b/lib/tamarin.py @@ -1,9 +1,23 @@ -import os, glob, subprocess +import os, glob, subprocess, configparser import web, system +def load_profile(profile_name): + profile_filename = profile_name+".conf" + for profile_file in get_available_profiles(): + if profile_filename == os.path.basename(profile_file): + config = configparser.ConfigParser() + config.read(profile_file) + return config + return None + +def get_profiles_dir(): + return os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../profiles") + def get_available_profiles(): - profiles_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../profiles") - profile_files = glob.glob(profiles_dir + '/*.conf') + return glob.glob(get_profiles_dir() + '/*.conf') + +def get_available_profile_names(): + profile_files = get_available_profiles() return [os.path.splitext(os.path.basename(f))[0] for f in profile_files] def get_workspace_dir(): diff --git a/package b/package index effee82..6946135 100755 --- a/package +++ b/package @@ -1,66 +1,64 @@ #!/usr/bin/env python3 -import argparse, sys, shutil -from os import path +import argparse, sys, shutil, os -sys.path.append(path.dirname(__file__) + '/lib') +sys.path.append(os.path.dirname(__file__) + '/lib') import tamarin, system def configure_args_parser(): - profiles = tamarin.get_available_profiles() + profile_names = tamarin.get_available_profile_names() parser = argparse.ArgumentParser(description="Generate packages for various GNU/Linux distribution") # Define available/required arguments and flags parser.add_argument("project_path", help="The path to your project to package") - parser.add_argument("-p", "--profile", help="The profile to use to package this project", choices=profiles) + parser.add_argument("-p", "--profile", help="The profile to use to package this project (default: debian)", choices=profile_names, default='debian') return parser if __name__ == "__main__": parser = configure_args_parser() - parser.parse_args() + args = parser.parse_args() - # sys.path.append(os.path.dirname(__file__) + '/lib') - # - # import tamarin, system - # - # workspace = tamarin.get_workspace_dir() - # workspace_tmp = tamarin.get_workspace_subdir('tmp') - # - # local_rkt_dir = tamarin.get_workspace_subdir('rkt') - # if not system.which('rkt', local_rkt_dir): - # # Download and extract rkt - # rkt_archive_path = tamarin.download_rkt() - # system.extract_tar(rkt_archive_path, workspace_tmp) - # rkt_archive_dir = tamarin.get_rkt_achive_dest_dir() - # shutil.rmtree(local_rkt_dir, ignore_errors=True) - # os.rename(rkt_archive_dir, local_rkt_dir) - # - # local_acbuild_dir = tamarin.get_workspace_subdir('acbuild') - # if not system.which('acbuild', local_acbuild_dir): - # # Download and extract acbuild - # acbuild_archive_path = tamarin.download_acbuild() - # system.extract_tar(acbuild_archive_path, workspace_tmp) - # acbuild_archive_dir = tamarin.get_acbuild_achive_dest_dir() - # shutil.rmtree(local_acbuild_dir, ignore_errors=True) - # os.rename(acbuild_archive_dir, local_acbuild_dir) - # - # acbuild_workspace = tamarin.get_acbuild_workspace_dir() - # image_name = "image_{:d}.aci".format(os.getpid()) - # image_path = os.path.join(os.sep, acbuild_workspace, 'image.aci') - # acbuild_flags = ["--work-path", acbuild_workspace] - # - # # Start building image - # tamarin.run_acbuild(acbuild_flags+["begin"]) - # tamarin.run_acbuild(acbuild_flags+["set-name", "test"]) - # tamarin.run_acbuild(acbuild_flags+["set-exec", "--", "/bin/sh", "-c", "ping 8.8.8.8"]) - # tamarin.run_acbuild(acbuild_flags+["dependency", "add", "quay.io/coreos/alpine-sh"]) - # tamarin.run_acbuild(acbuild_flags+["write", image_path]) - # tamarin.run_acbuild(acbuild_flags+["end"]) - # - # # rkt run --insecure-options=image ./nginx.aci --volume html,kind=host,source=/path/to/test --net=host - # tamarin.run_rkt(["run", "--insecure-options=image", image_path, "--net=host"]) + profile = tamarin.load_profile(args.profile) + + workspace = tamarin.get_workspace_dir() + workspace_tmp = tamarin.get_workspace_subdir('tmp') + + local_rkt_dir = tamarin.get_workspace_subdir('rkt') + if not system.which('rkt', local_rkt_dir): + # Download and extract rkt + rkt_archive_path = tamarin.download_rkt() + system.extract_tar(rkt_archive_path, workspace_tmp) + rkt_archive_dir = tamarin.get_rkt_achive_dest_dir() + shutil.rmtree(local_rkt_dir, ignore_errors=True) + os.rename(rkt_archive_dir, local_rkt_dir) + + local_acbuild_dir = tamarin.get_workspace_subdir('acbuild') + if not system.which('acbuild', local_acbuild_dir): + # Download and extract acbuild + acbuild_archive_path = tamarin.download_acbuild() + system.extract_tar(acbuild_archive_path, workspace_tmp) + acbuild_archive_dir = tamarin.get_acbuild_achive_dest_dir() + shutil.rmtree(local_acbuild_dir, ignore_errors=True) + os.rename(acbuild_archive_dir, local_acbuild_dir) + + acbuild_workspace = tamarin.get_acbuild_workspace_dir() + pid = os.getpid() + image_name = "image_{:d}.aci".format(pid) + image_path = os.path.join(os.sep, acbuild_workspace, image_name) + acbuild_flags = ["--work-path", acbuild_workspace] + + # Start building image + tamarin.run_acbuild(acbuild_flags+["begin"]) + tamarin.run_acbuild(acbuild_flags+["set-name", "image_{:d}".format(pid)]) + # tamarin.run_acbuild(acbuild_flags+["dependency", "add", profile['profile']['default_image']]) + tamarin.run_acbuild(acbuild_flags+["set-exec", "--", "/bin/sh", "-c", "echo Hello World"]) + tamarin.run_acbuild(acbuild_flags+["write", image_path]) + tamarin.run_acbuild(acbuild_flags+["end"]) + + # rkt run --insecure-options=image ./nginx.aci --volume html,kind=host,source=/path/to/test --net=host + tamarin.run_rkt(["run", "--insecure-options=image", "--dir={:s}".format(workspace_tmp), "--stage1-name={:s}".format(profile['profile']['default_image']), image_path, "--net=host"]) diff --git a/profiles/debian.conf b/profiles/debian.conf index e69de29..ccd8216 100644 --- a/profiles/debian.conf +++ b/profiles/debian.conf @@ -0,0 +1,22 @@ +# Configuration générale du profil +[profile] +# Image Docker par défaut +default_image=docker://debian:jessie + +# Configuration de l'étape de pré-construction du conteneur +[containerprebuild] +hooks=install-git-containerbuild + +# Configuration de l'étape de pré-construction du paquet +[prebuild] +hooks=05-create-changelog-prebuild,06-create-dummy-changelog-prebuild,07-add-version-suffix-prebuild,10-install-build-depends-prebuild + +# Configuration de l'étape de post-construction du paquet +[postbuild] +hooks=99-export-dist-postbuild + +[preinstall] +hooks= + +[postinstall] +hooks=