예제 #1
0
def get_project_deploy_mode(action=None):

    kube_parser = get_kube_parser()
    kube_args = kube_parser.parse_args()

    print(kube_args)

    runtime_env = kube_args.runtime_env
    deploy_env = kube_args.deploy_env

    project_root = get_project_root()

    wield_mode = get_wield_mode(
        project_root=project_root,
        runtime_env=runtime_env,
        deploy_env=deploy_env
    )

    conf = get_conf_context_project(
        project_root=project_root,
        runtime_env=wield_mode.runtime_env,
        deploy_env=wield_mode.deploy_env
    )

    print(conf)

    if not action:
        action = kube_args.wield

    return wield_mode, conf, action
예제 #2
0
def whisperer_image(force_last=True, push=False):

    # TODO tag from git commit in case its not dev
    tag = 'dev'

    project_root = u.get_project_root()
    conf = u.get_conf_context_project(project_root=project_root)
    image_root = u.get_project_image_root()

    pack_image(
        conf,
        name='py37',
        image_root=image_root,
        push=False,
        force=False,
        tag=tag
    )

    pack_image(
        conf,
        name='flask',
        image_root=image_root,
        push=False,
        force=False,
        tag=tag
    )

    super_project_root = u.get_super_project_root()
    origin_path = f'{super_project_root}/micros/flask/whisperer'
    origin_regex = 'package_py.bash'

    module_root = u.get_module_root(__file__)
    image_root = f'{module_root}image'
    destination_path = f'{image_root}/whisperer'

    replace_dir_contents(
        origin_path,
        origin_regex,
        destination_path=destination_path,
        destination_dir_name='artifacts'
    )

    pack_image(
        conf,
        name='whisperer',
        image_root=image_root,
        push=False,
        force=force_last,
        tag=tag
    )

    gcp_conf = conf.providers.gcp

    if push:
        push_image(gcp_conf, name='whisperer', group='wielder', tag=tag)
예제 #3
0
def boot_image(force_last=True, push=False):

    # TODO tag from git commit in case its not dev
    image_name = 'boot'

    tag = 'dev'

    project_root = u.get_project_root()
    conf = u.get_conf_context_project(project_root=project_root)

    pack_image(conf=conf,
               name='py_base',
               image_root=u.get_project_image_root(),
               push=False,
               force=False,
               tag=tag)

    pack_image(conf=conf,
               name='j11_py',
               image_root=u.get_project_image_root(),
               push=False,
               force=False,
               tag=tag)

    super_project_root = u.get_super_project_root()
    # TODO get the suffix from module config
    origin_path = f'{super_project_root}/micros/boot/eve/build/libs'
    origin_regex = 'eve*.jar'
    #
    module_root = u.get_module_root(__file__)
    image_root = f'{module_root}image'
    destination_path = f'{image_root}/{image_name}'

    # TODO compile conditional on cli or config ( ./gradlew build && java -jar build/libs/eve-0.1.0.jar)
    origin_jar = replace_dir_contents(origin_path,
                                      origin_regex,
                                      destination_path=destination_path,
                                      destination_dir_name=ARTIFACT_DIR)

    old_name = origin_jar.split('/')[-1]

    os.rename(f'{destination_path}/{ARTIFACT_DIR}/{old_name}',
              f'{destination_path}/{ARTIFACT_DIR}/app.jar')

    pack_image(conf,
               name=image_name,
               image_root=image_root,
               push=False,
               force=force_last,
               tag=tag)

    gcp_conf = conf.providers.gcp

    if push:
        push_image(gcp_conf, name=image_name, group='wielder', tag=tag)
예제 #4
0
def t_runtime_env():

    project_root = get_project_root()
    env_gcp = get_conf_context_project(project_root=project_root,
                                       runtime_env='gcp')
    env_docker = get_conf_context_project(project_root=project_root,
                                          runtime_env='docker')

    if env_gcp.food == 'falafel' and env_docker.food == 'schnitzel':
        print('cool')
    else:
        print('aww')
예제 #5
0
def t_override():

    project_root = get_project_root()
    env_dev = get_conf_context_project(project_root=project_root,
                                       deploy_env='dev')

    account = env_dev.providers.gcp.service_account

    if 'dev' in account:
        print('\noverride cool')
    else:
        print('\noverride aww')
예제 #6
0
def t_deploy_env():

    project_root = get_project_root()
    env_dev = get_conf_context_project(project_root=project_root,
                                       deploy_env='dev')

    env_int = get_conf_context_project(project_root=project_root,
                                       deploy_env='int')

    if env_dev.kube_context == 'docker-for-desktop' and env_int.kube_context == 'int-gke':
        print('\ndeploy_env cool')
    else:
        print('\ndeploy_env aww')
예제 #7
0
def slate_image(force_last=True, push=False):

    # TODO tag from git commit in case its not dev
    tag = 'dev'

    project_root = u.get_project_root()
    conf = u.get_conf_context_project(project_root=project_root)

    pack_image(conf=conf,
               name='py37',
               image_root=u.get_project_image_root(),
               push=False,
               force=True,
               tag=tag)

    module_root = u.get_module_root(__file__)

    origin_path = f'{module_root}image/code_path'
    origin_regex = 'app.py'

    image_root = f'{module_root}image'
    destination_path = f'{image_root}/slate'

    replace_dir_contents(origin_path,
                         origin_regex,
                         destination_path=destination_path,
                         destination_dir_name='artifacts')

    pack_image(conf,
               name='slate',
               image_root=image_root,
               push=False,
               force=force_last,
               tag=tag)

    gcp_conf = conf.providers.gcp

    if push:
        push_image(gcp_conf, name='slate', group='wielder', tag=tag)
예제 #8
0
def pep_image(force_last=True, push=False):

    locale = get_locale(__file__)

    action, mode, enable_debug, local_mount, service_mode = replace_none_vars_from_args(
        action=None,
        mode=None,
        enable_debug=None,
        local_mount=None,
        service_mode=None,
        project_override=None
    )

    service = WieldService(
        name='pep',
        locale=locale,
        mode=mode,
        service_mode=service_mode,
    )

    plan = service.plan.module_conf.packaging

    image_name = plan.image_name

    tag = plan.git.branch

    project_root = u.get_project_root()
    conf = u.get_conf_context_project(project_root=project_root)

    image_root = u.get_project_image_root()

    pack_image(
        conf=conf,
        name='perl',
        image_root=image_root,
        push=False,
        force=True,
        tag=tag
    )

    pack_image(
        conf=conf,
        name='perl_py',
        image_root=image_root,
        push=False,
        force=True,
        tag=tag
    )

    try:
        origin_path = plan.origin_path
        origin_regex = plan.origin_regex
    except AttributeError:
        super_project_root = u.get_super_project_root()
        origin_path = f'{super_project_root}/micros/perl/pep'
        origin_regex = 'pep.pl'

    module_root = u.get_module_root(__file__)
    image_root = f'{module_root}image'
    destination_path = f'{image_root}/{image_name}'

    artifacts_dir = f'{destination_path}/artifacts'

    artifact_method = plan.artifact_method

    if artifact_method == ArtifactMethod.GET_DIR.value or artifact_method == ArtifactMethod.INIT_REPO.value:
        rmtree(artifacts_dir, ignore_errors=True)

    if artifact_method == ArtifactMethod.GET_DIR.value:

        replace_dir_contents(
            origin_path,
            origin_regex,
            destination_path=destination_path,
            destination_dir_name='artifacts'
        )
    else:
        clone_or_update(source=origin_path, destination=artifacts_dir, branch=plan.git.branch)

        if artifact_method == ArtifactMethod.INIT_REPO.value:

            for art in plan.artifacts:

                os.makedirs(f"{artifacts_dir}/{art[0]}", exist_ok=True)

                try:
                    copyfile(src=f"{origin_path}/{art[0]}/{art[1]}", dst=f"{artifacts_dir}/{art[0]}/{art[1]}")

                except Exception as e:
                    logging.error(str(e))

            _cmd = f'{artifacts_dir}/pypep/prepare.bash'

            a = async_cmd(_cmd)

            for b in a:
                print(b)

    pack_image(
        conf,
        name=image_name,
        image_root=image_root,
        push=False,
        force=force_last,
        tag=tag
    )

    gcp_conf = conf.providers.gcp

    if push:
        push_image(gcp_conf, name=image_name, group='wielder', tag=tag)