Пример #1
0
    def clone_library(self):
        if self.library:
            return self.library

        try:
            rep, library = git.clone_branch(self.repository, self.branch)
            self.library = library
        except git.GitException as e:
            raise StackbrewError(
                'Source repository could not be fetched. Ensure '
                'the address is correct and the branch exists.', e)
Пример #2
0
    def clone_library(self):
        if self.library:
            return self.library

        try:
            rep, library = git.clone_branch(self.repository, self.branch)
            self.library = library
        except git.GitException as e:
            raise StackbrewError(
                "Source repository could not be fetched. Ensure " "the address is correct and the branch exists.", e
            )
Пример #3
0
def build_library(repository=None,
                  branch=None,
                  namespace=None,
                  push=False,
                  debug=False,
                  prefill=True,
                  registry=None,
                  targetlist=None,
                  repos_folder=None,
                  logger=None):
    ''' Entrypoint method build_library.
        repository:     Repository containing a library/ folder. Can be a
                        local path or git repository
        branch:         If repository is a git repository, checkout this branch
                        (default: DEFAULT_BRANCH)
        namespace:      Created repositories will use the following namespace.
                        (default: no namespace)
        push:           If set to true, push images to the repository
        debug:          Enables debug logging if set to True
        prefill:        Retrieve images from public repository before building.
                        Serves to prefill the builder cache.
        registry:       URL to the private registry where results should be
                        pushed. (only if push=True)
        targetlist:     String indicating which library files are targeted by
                        this build. Entries should be comma-separated. Default
                        is all files.
        repos_folder:   Fixed location where cloned repositories should be
                        stored. Default is None, meaning folders are temporary
                        and cleaned up after the build finishes.
        logger:         Logger instance to use. Default is None, in which case
                        build_library will create its own logger.
    '''
    dst_folder = None
    summary = Summary()
    if logger is None:
        logger = logging.getLogger(__name__)
        logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                            level='INFO')

    if repository is None:
        repository = DEFAULT_REPOSITORY
    if branch is None:
        branch = DEFAULT_BRANCH
    if debug:
        logger.setLevel('DEBUG')
    if targetlist is not None:
        targetlist = targetlist.split(',')

    if not repository.startswith(('https://', 'git://')):
        logger.info('Repository provided assumed to be a local path')
        dst_folder = repository

    try:
        client.version()
    except Exception as e:
        logger.error('Could not reach the docker daemon. Please make sure it '
                     'is running.')
        logger.warning('Also make sure you have access to the docker UNIX '
                       'socket (use sudo)')
        return

    if not dst_folder:
        logger.info('Cloning docker repo from {0}, branch: {1}'.format(
            repository, branch))
        try:
            rep, dst_folder = git.clone_branch(repository, branch)
        except Exception as e:
            logger.exception(e)
            logger.error('Source repository could not be fetched. Check '
                         'that the address is correct and the branch exists.')
            return
    try:
        dirlist = os.listdir(os.path.join(dst_folder, 'library'))
    except OSError as e:
        logger.error('The path provided ({0}) could not be found or didn\'t'
                     'contain a library/ folder.'.format(dst_folder))
        return
    for buildfile in dirlist:
        if buildfile == 'MAINTAINERS':
            continue
        if (targetlist and buildfile not in targetlist):
            continue
        f = open(os.path.join(dst_folder, 'library', buildfile))
        linecnt = 0
        for line in f:
            linecnt += 1
            if not line or line.strip() == '':
                continue
            elif line.lstrip().startswith('#'):  # # It's a comment!
                continue
            logger.debug('{0} ---> {1}'.format(buildfile, line))
            try:
                tag, url, ref, dfile = parse_line(line, logger)
                if prefill:
                    logger.debug('Pulling {0} from official repository (cache '
                                 'fill)'.format(buildfile))
                    try:
                        client.pull(buildfile)
                    except:
                        # Image is not on official repository, ignore prefill
                        pass

                img, commit = build_repo(url, ref, buildfile, dfile, tag,
                                         namespace, push, registry,
                                         repos_folder, logger)
                summary.add_success(buildfile, (linecnt, line), img, commit)
            except Exception as e:
                logger.exception(e)
                summary.add_exception(buildfile, (linecnt, line), e)

        f.close()
    cleanup(dst_folder, dst_folder != repository, repos_folder is None)
    summary.print_summary(logger)
    return summary
Пример #4
0
def build_library(repository=None, branch=None, namespace=None, push=False,
                  debug=False, prefill=True, registry=None, targetlist=None,
                  repos_folder=None, logger=None):
    ''' Entrypoint method build_library.
        repository:     Repository containing a library/ folder. Can be a
                        local path or git repository
        branch:         If repository is a git repository, checkout this branch
                        (default: DEFAULT_BRANCH)
        namespace:      Created repositories will use the following namespace.
                        (default: no namespace)
        push:           If set to true, push images to the repository
        debug:          Enables debug logging if set to True
        prefill:        Retrieve images from public repository before building.
                        Serves to prefill the builder cache.
        registry:       URL to the private registry where results should be
                        pushed. (only if push=True)
        targetlist:     String indicating which library files are targeted by
                        this build. Entries should be comma-separated. Default
                        is all files.
        repos_folder:   Fixed location where cloned repositories should be
                        stored. Default is None, meaning folders are temporary
                        and cleaned up after the build finishes.
        logger:         Logger instance to use. Default is None, in which case
                        build_library will create its own logger.
    '''
    dst_folder = None
    summary = Summary()
    if logger is None:
        logger = logging.getLogger(__name__)
        logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                            level='INFO')

    if repository is None:
        repository = DEFAULT_REPOSITORY
    if branch is None:
        branch = DEFAULT_BRANCH
    if debug:
        logger.setLevel('DEBUG')
    if targetlist is not None:
        targetlist = targetlist.split(',')

    if not repository.startswith(('https://', 'git://')):
        logger.info('Repository provided assumed to be a local path')
        dst_folder = repository

    try:
        client.version()
    except Exception as e:
        logger.error('Could not reach the docker daemon. Please make sure it '
                     'is running.')
        logger.warning('Also make sure you have access to the docker UNIX '
                       'socket (use sudo)')
        return

    if not dst_folder:
        logger.info('Cloning docker repo from {0}, branch: {1}'.format(
            repository, branch))
        try:
            rep, dst_folder = git.clone_branch(repository, branch)
        except Exception as e:
            logger.exception(e)
            logger.error('Source repository could not be fetched. Check '
                         'that the address is correct and the branch exists.')
            return
    try:
        dirlist = os.listdir(os.path.join(dst_folder, 'library'))
    except OSError as e:
        logger.error('The path provided ({0}) could not be found or didn\'t'
                     'contain a library/ folder.'.format(dst_folder))
        return
    for buildfile in dirlist:
        if buildfile == 'MAINTAINERS':
            continue
        if (targetlist and buildfile not in targetlist):
            continue
        f = open(os.path.join(dst_folder, 'library', buildfile))
        linecnt = 0
        for line in f:
            linecnt += 1
            if not line or line.strip() == '':
                continue
            elif line.lstrip().startswith('#'):  # # It's a comment!
                continue
            logger.debug('{0} ---> {1}'.format(buildfile, line))
            try:
                tag, url, ref, dfile = parse_line(line, logger)
                if prefill:
                    logger.debug('Pulling {0} from official repository (cache '
                                 'fill)'.format(buildfile))
                    try:
                        client.pull(buildfile)
                    except:
                        # Image is not on official repository, ignore prefill
                        pass

                img, commit = build_repo(url, ref, buildfile, dfile, tag,
                                         namespace, push, registry,
                                         repos_folder, logger)
                summary.add_success(buildfile, (linecnt, line), img, commit)
            except Exception as e:
                logger.exception(e)
                summary.add_exception(buildfile, (linecnt, line), e)

        f.close()
    cleanup(dst_folder, dst_folder != repository, repos_folder is None)
    summary.print_summary(logger)
    return summary
Пример #5
0
def build_library(repository=None, branch=None, namespace=None, push=False,
        debug=False, prefill=True, registry=None):
    dst_folder = None
    summary = Summary()
    if repository is None:
        repository = DEFAULT_REPOSITORY
    if branch is None:
        branch = DEFAULT_BRANCH
    if debug:
        logger.setLevel('DEBUG')

    if not (repository.startswith('https://') or repository.startswith('git://')):
        logger.info('Repository provided assumed to be a local path')
        dst_folder = repository

    #FIXME: set destination folder and only pull latest changes instead of
    # cloning the whole repo everytime
    if not dst_folder:
        logger.info('Cloning docker repo from {0}, branch: {1}'.format(
            repository, branch))
        try:
            dst_folder = git.clone_branch(repository, branch)
        except Exception as e:
            logger.exception(e)
            logger.error('Source repository could not be fetched. Check '
                'that the address is correct and the branch exists.')
            return
    for buildfile in os.listdir(os.path.join(dst_folder, 'library')):
        if buildfile == 'MAINTAINERS':
            continue
        f = open(os.path.join(dst_folder, 'library', buildfile))
        linecnt = 0
        for line in f:
            linecnt = linecnt + 1
            logger.debug('{0} ---> {1}'.format(buildfile, line))
            args = line.split()
            try:
                if len(args) > 3:
                    raise RuntimeError('Incorrect line format, '
                        'please refer to the docs')

                url = None
                ref = 'refs/heads/master'
                tag = None
                if len(args) == 1:  # Just a URL, simple mode
                    url = args[0]
                elif len(args) == 2 or len(args) == 3:  # docker-tag   url
                    url = args[1]
                    tag = args[0]

                if len(args) == 3:  # docker-tag  url     B:branch or T:tag
                    ref = None
                    if args[2].startswith('B:'):
                        ref = 'refs/heads/' + args[2][2:]
                    elif args[2].startswith('T:'):
                        ref = 'refs/tags/' + args[2][2:]
                    elif args[2].startswith('C:'):
                        ref = args[2][2:]
                    else:
                        raise RuntimeError('Incorrect line format, '
                            'please refer to the docs')
                if prefill:
                    logger.debug('Pulling {0} from official repository (cache '
                        'fill)'.format(buildfile))
                    client.pull(buildfile)
                img = build_repo(url, ref, buildfile, tag, namespace, push,
                    registry)
                summary.add_success(buildfile, (linecnt, line), img)
                processed['{0}@{1}'.format(url, ref)] = img
            except Exception as e:
                logger.exception(e)
                summary.add_exception(buildfile, (linecnt, line), e)

        f.close()
    if dst_folder != repository:
        rmtree(dst_folder, True)
    summary.print_summary(logger)
Пример #6
0
def build_library(repository=None, branch=None, namespace=None, push=False,
        debug=False, prefill=True, registry=None):
    dst_folder = None
    summary = Summary()
    if repository is None:
        repository = DEFAULT_REPOSITORY
    if branch is None:
        branch = DEFAULT_BRANCH
    if debug:
        logger.setLevel('DEBUG')

    if not (repository.startswith('https://') or repository.startswith('git://')):
        logger.info('Repository provided assumed to be a local path')
        dst_folder = repository

    try:
        client.version()
    except Exception as e:
        logger.error('Could not reach the docker daemon. Please make sure it '
            'is running.')
        logger.warning('Also make sure you have access to the docker UNIX '
            'socket (use sudo)')
        return

    #FIXME: set destination folder and only pull latest changes instead of
    # cloning the whole repo everytime
    if not dst_folder:
        logger.info('Cloning docker repo from {0}, branch: {1}'.format(
            repository, branch))
        try:
            rep, dst_folder = git.clone_branch(repository, branch)
        except Exception as e:
            logger.exception(e)
            logger.error('Source repository could not be fetched. Check '
                'that the address is correct and the branch exists.')
            return
    try:
        dirlist = os.listdir(os.path.join(dst_folder, 'library'))
    except OSError as e:
        logger.error('The path provided ({0}) could not be found or didn\'t'
            'contain a library/ folder.'.format(dst_folder))
        return
    for buildfile in dirlist:
        if buildfile == 'MAINTAINERS':
            continue
        f = open(os.path.join(dst_folder, 'library', buildfile))
        linecnt = 0
        for line in f:
            linecnt = linecnt + 1
            logger.debug('{0} ---> {1}'.format(buildfile, line))
            args = line.split()
            try:
                if len(args) > 3:
                    raise RuntimeError('Incorrect line format, '
                        'please refer to the docs')

                url = None
                ref = 'refs/heads/master'
                tag = None
                if len(args) == 1:  # Just a URL, simple mode
                    url = args[0]
                elif len(args) == 2 or len(args) == 3:  # docker-tag   url
                    url = args[1]
                    tag = args[0]

                if len(args) == 3:  # docker-tag  url     B:branch or T:tag
                    ref = None
                    if args[2].startswith('B:'):
                        ref = 'refs/heads/' + args[2][2:]
                    elif args[2].startswith('T:'):
                        ref = 'refs/tags/' + args[2][2:]
                    elif args[2].startswith('C:'):
                        ref = args[2][2:]
                    else:
                        raise RuntimeError('Incorrect line format, '
                            'please refer to the docs')
                if prefill:
                    logger.debug('Pulling {0} from official repository (cache '
                        'fill)'.format(buildfile))
                    client.pull(buildfile)
                img = build_repo(url, ref, buildfile, tag, namespace, push,
                    registry)
                summary.add_success(buildfile, (linecnt, line), img)
                processed['{0}@{1}'.format(url, ref)] = img
            except Exception as e:
                logger.exception(e)
                summary.add_exception(buildfile, (linecnt, line), e)

        f.close()
    if dst_folder != repository:
        rmtree(dst_folder, True)
    for d in processed_folders:
        rmtree(d, True)
    summary.print_summary(logger)