예제 #1
0
def info(global_args, verb_args, module, intents):
    base_config = load_config(global_args.base_path, module)

    # TODO this should let users inspect the current pipeline
    # i.e. describe intents

    print 'info:', module
예제 #2
0
def resolve(global_args, verb_args, module, intents):
    base_config = load_config(global_args.base_path, module)
    variants = resolve_variants(verb_args, base_config)

    print 'resolved tags:', module
    for variant in variants:
        print '  %s' % variant['variant_tag']
        for tag in variant['tags']:
            print '    %s' % tag.full
    print ''
예제 #3
0
def images_from_args(global_args, verb_args, module):
    base_config = load_config(global_args.base_path, module)

    variants = resolve_variants(verb_args, base_config)
    logger.debug('Resolved variants: %r', variants)

    images = set()
    for variant in variants:
        for tag in variant['tags']:
            images.add(tag.full_interp)

    return images
예제 #4
0
def readme(global_args, verb_args, module, intents):
    readme_path = os.path.join(global_args.base_path, module, 'README.md')
    if not os.path.exists(readme_path):
        logger.info('no README.md exists for module %s, will not update',
                    module)
        return [Plan('readme', module, execute_plan, intents, {'skip': True})]

    token = get_auth_token()
    if not token:
        logger.warn('could not authenticate to docker hub, '
                    'skipping README update')
        return [Plan('readme', module, execute_plan, intents, {'skip': True})]

    base_config = load_config(global_args.base_path, module)
    variants = resolve_variants(verb_args, base_config, check_tag=False)

    known = set()
    plans = []
    for variant in variants:
        for tag in variant['tags']:
            if tag.repository in known:
                continue

            if tag.registry is not None:
                logger.debug(
                    'Cannot update README for private registries, '
                    'will skip: %r', tag)
                continue

            plans.append(
                Plan(
                    'readme', module, execute_plan, intents, {
                        'token': get_auth_token(),
                        'variant_tag': variant['variant_tag'],
                        'tag': tag,
                        'readme_path': readme_path
                    }))

    if not plans:
        logger.debug('no READMEs can be updated, skipping...')
        return [Plan('readme', module, execute_plan, intents, {'skip': True})]

    return plans
예제 #5
0
def build(global_args, verb_args, module, intents):
    verify_docker_version()

    base_config = load_config(global_args.base_path, module)
    dockerfile = load_dockerfile(global_args.base_path, module)

    build_args = get_proxy_config()
    if 'args' in base_config:
        build_args.update(base_config['args'])

    override_tags = []
    rebuild_targets = []

    for arg in filter(lambda a: a.type == 'build_arg', verb_args):
        k, v = arg.groups
        build_args[k] = v

    for arg in filter(lambda a: a.type == 'rebuild', verb_args):
        rebuild_targets.append(arg.groups[0])

    for arg in filter(lambda a: a.type == 'image_override_tag', verb_args):
        override_tags.append(arg.groups[0])

    logger.debug('Resolved build parameters:')
    logger.debug('build_args: %r', build_args)
    logger.debug('rebuild_targets: %r', rebuild_targets)

    if rebuild_targets:
        valid_targets = get_rebuild_targets(dockerfile)
        if not valid_targets:
            logger.error('Module has no rebuild targets, invalid: %s',
                         rebuild_targets)
            raise VerbException()

        for target in rebuild_targets:
            if target.lower() not in valid_targets:
                logger.error('Invalid rebuild target %s, must be one of: %s',
                             target, ', '.join(valid_targets))
                raise VerbException()

    rebuild_str = datetime.datetime.now().isoformat()
    for target in rebuild_targets:
        build_args['REBUILD_%s' % target.upper()] = rebuild_str

    variants = resolve_variants(verb_args, base_config)
    logger.debug('Resolved variants: %r', variants)

    plans = []
    for variant_args in variants:
        variant = get_variant(base_config, variant_args['variant_tag'])

        if variant and 'args' in variant:
            variant_build_args = variant['args'].copy()
        else:
            variant_build_args = {}
        variant_build_args.update(build_args)
        logger.debug('variant_build_args: %r', variant_build_args)

        # we'll generate a set of images for tasks later in the pipeline, e.g.
        # push - not used for build
        images = set()
        for tag in variant_args['tags']:
            images.add(tag.full)

        variant_intents = intents.copy()
        if 'images' in variant_intents:
            variant_intents['images'].update(images)
        else:
            variant_intents['images'] = images

        if global_args.build_log_dir:
            datestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
            file_name = '%s-%s-%s.log' % (datestamp, module,
                                          variant_args['variant_tag'])
            log_file = os.path.join(global_args.build_log_dir, file_name)
        else:
            log_file = None

        plan = Plan(
            'build', module, execute_plan, variant_intents, {
                'base_path': global_args.base_path,
                'tags': variant_args['tags'],
                'build_args': variant_build_args,
                'build_log': global_args.build_log,
                'log_file': log_file
            })
        plan.status.total = len(dockerfile.structure)
        plans.append(plan)

    return plans