Beispiel #1
0
def build():
    emojize = bootstrap()
    clean_up(('build', 'dist'))
    success = execute_command('pipenv lock')
    if success:
        LOGGER.info('Successfully created lock file %s %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors creating lock file! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
        raise SystemExit(1)
    save_requirements()
    for file in BUILD_REQUIRED_FILES:
        shutil.copy(file, os.path.join(f'{PROJECT_SLUG}', file))
    success = execute_command('python setup.py sdist bdist_egg')
    if success:
        LOGGER.info('%s Successfully built artifact %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors building artifact! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    clean_up([
        os.path.join(f'{PROJECT_SLUG}', file) for file in BUILD_REQUIRED_FILES
    ])
    return emojize if success else None
Beispiel #2
0
def build():
    bootstrap()
    # clean_up(('build', 'dist'))
    success = execute_command('pipenv lock')
    if success:
        LOGGER.info('Successfully created lock file %s %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors creating lock file! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
        raise SystemExit(1)

    save_requirements(get_venv_parent_path(), [], True)

    [
        save_requirements('./src/containers/' + folder, [], False)
        for folder in os.listdir('./src/containers/')
        if os.path.isdir('./src/containers/' +
                         folder) and '__pycache__' not in folder
    ]
    environment = get_environment()
    ref_name = os.environ.get('CI_COMMIT_REF_NAME')
    if ref_name:
        ref_name = ref_name.replace("/", "-")
    ecr_repo = os.environ.get('ECR_REPOSITORY')
    if not ecr_repo:
        ecr_repo = PROJECT_PREFIX
    version = os.environ.get('CI_COMMIT_TAG')
    base_name = ecr_repo + '/' + PROJECT_PREFIX + environment + '-' + PROJECT_SLUG + '-' + ref_name
    for folder in os.listdir('./src/containers/'):
        if os.path.isdir('./src/containers/' +
                         folder) and '__pycache__' not in folder:
            docker_build = 'docker build -t ' + base_name + '-' + folder + ':latest'
            if version:
                docker_build += ' -t ' + base_name + '-' + folder + ':' + version
            docker_build += ' ./src/containers/' + folder
            success = execute_command(docker_build)
        if not success:
            break

    [
        save_requirements('./src/functions/' + folder, ['boto3'], False)
        for folder in os.listdir('./src/functions/')
        if os.path.isdir('./src/functions/' +
                         folder) and '__pycache__' not in folder
    ]
    if success:
        success = execute_command('sam build --template template.yml')

    # success = execute_command('python setup.py sdist bdist_egg')
    if success:
        LOGGER.info('%s Successfully built artifact %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors building artifact! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    return True if success else False
def initialize_template_environment():
    from configuration import (LOGGING_LEVEL, ENVIRONMENT_VARIABLES,
                               PREREQUISITES)
    from library import (setup_logging, validate_binary_prerequisites,
                         validate_environment_variable_prerequisites,
                         is_venv_created, execute_command,
                         load_environment_variables, load_dot_env_file,
                         activate_virtual_environment)
    load_environment_variables(ENVIRONMENT_VARIABLES)
    load_dot_env_file()
    if not validate_binary_prerequisites(PREREQUISITES.get('executables', [])):
        LOGGER.error('Prerequisite binary missing, cannot continue.')
        raise SystemExit(1)
    if not validate_environment_variable_prerequisites(
            PREREQUISITES.get('environment_variables', [])):
        LOGGER.error(
            'Prerequisite environment variable missing, cannot continue.')
        raise SystemExit(1)

    if not is_venv_created():
        LOGGER.debug('Trying to create virtual environment.')
        success = execute_command('pipenv install --dev  --ignore-pipfile')
        if success:
            activate_virtual_environment()
            from emoji import emojize
            LOGGER.info(
                '%s Successfully created virtual environment and loaded it! %s',
                emojize(':white_heavy_check_mark:'), emojize(':thumbs_up:'))
        else:
            LOGGER.error(
                'Creation of virtual environment failed, cannot continue, '
                'please clean up .venv directory and try again...')
            raise SystemExit(1)
    setup_logging(os.environ.get('LOGGING_LEVEL') or LOGGING_LEVEL)
Beispiel #4
0
def bootstrap():
    setup_logging(os.environ.get("LOGGING_LEVEL") or LOGGING_LEVEL)
    load_environment_variables(ENVIRONMENT_VARIABLES)
    load_dot_env_file()
    if not validate_binary_prerequisites(PREREQUISITES.get('executables', [])):
        LOGGER.error('Prerequisite binary missing, cannot continue.')
        raise SystemExit(1)
    if not validate_environment_variable_prerequisites(PREREQUISITES.get('environment_variables', [])):
        LOGGER.error('Prerequisite environment variable missing, cannot continue.')
        raise SystemExit(1)
    if not is_venv_created():
        LOGGER.debug('Trying to create virtual environment.')
        skip_lock = '--skip-lock' if os.environ.get('PIPENV_SKIP_LOCK') else ''
        exit_code = execute_command(f'pipenv install --dev --ignore-pipfile {skip_lock}')
        success = not exit_code
        if success:
            activate_virtual_environment()
            emojize = get_emojize()
            LOGGER.info('%s Successfully created virtual environment and loaded it! %s',
                        emojize(':white_heavy_check_mark:'),
                        emojize(':thumbs_up:'))
        else:
            LOGGER.error('Creation of virtual environment failed, cannot continue, '
                         'please clean up .venv directory and try again...')
            raise SystemExit(1)
    return get_emojize()
def build():
    emojize = bootstrap()
    clean_up(('build', 'dist'))
    # exit_code = execute_command('pipenv lock')
    # success = not exit_code
    # if success:
    #     LOGGER.info('Successfully created lock file %s',
    #                  emojize(':white_heavy_check_mark:'),
    #                  emojize(':thumbs_up:'))
    # else:
    #     LOGGER.error('%s Errors creating lock file! %s',
    #                   emojize(':cross_mark:'),
    #                   emojize(':crying_face:'))
    #     raise SystemExit(1)
    save_requirements()
    for file in BUILD_REQUIRED_FILES:
        shutil.copy(file, os.path.join('{{cookiecutter.project_slug}}', file))
    exit_code = execute_command('python setup.py sdist bdist_egg')
    success = not exit_code
    if success:
        LOGGER.info('%s Successfully built artifact %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors building artifact! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    clean_up([
        os.path.join('pythonlibproject', file) for file in BUILD_REQUIRED_FILES
    ])
    return emojize if success else None
def test():
    emojize = bootstrap()
    clean_up('test-output')
    os.mkdir('test-output')
    # exit_code = execute_command('pipenv lock')
    # success = not exit_code
    # if success:
    #     LOGGER.info('Successfully created lock file %s',
    #                  emojize(':white_heavy_check_mark:'),
    #                  emojize(':thumbs_up:'))
    # else:
    #     LOGGER.error('%s Errors creating lock file! %s',
    #                   emojize(':cross_mark:'),
    #                   emojize(':crying_face:'))
    #     raise SystemExit(1)
    save_requirements()
    exit_code = execute_command('tox')
    success = not exit_code
    if success:
        open_file(os.path.join('test-output', 'coverage', 'index.html'))
        sleep(0.5)
        open_file(os.path.join('test-output', 'nosetests.html'))
        LOGGER.info('%s No testing errors found! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Testing errors found! %s',
                     emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(exit_code)
Beispiel #7
0
def _test(type_, stage):
    template = os.path.abspath('.')
    context_file = os.path.abspath('cookiecutter.json')
    context = json.loads(open(context_file).read())
    test_types = ALL_TEST_TYPES if type_ == 'all' else [type_]
    test_stages = ALL_STAGES if stage == 'all' else [stage]
    result = {}
    status = True
    for test_type in test_types:
        context['project_type'] = test_type
        LOGGER.info(
            '%s Executing testing for template "%s" for stages "%s"! %s',
            emojize(':fire:'), test_type, test_stages, emojize(':fire:'))
        with tempdir():
            cookiecutter(template, extra_context=context, no_input=True)
            os.chdir(os.listdir('.')[0])
            try:
                del os.environ['PIPENV_PIPFILE']
            except KeyError:
                pass
            result[test_type] = [
                execute_command(os.path.join('_CI', 'scripts',
                                             f'{command}.py'))
                for command in test_stages
            ]
    for type_, results in result.items():
        for success, stage in zip(results, test_stages):
            if not success:
                status = False
                LOGGER.error(
                    '%s Errors found testing stage "%s" for template type "%s"! %s',
                    emojize(':cross_mark:'), stage, type_,
                    emojize(':crying_face:'))
    return status
Beispiel #8
0
def upload():
    emojize = build()
    if not emojize:
        LOGGER.error('Errors caught on building the artifact, bailing out...')
        raise SystemExit(1)
    if not validate_environment_variable_prerequisites(
            PREREQUISITES.get('upload_environment_variables', [])):
        LOGGER.error(
            'Prerequisite environment variable for upload missing, cannot continue.'
        )
        raise SystemExit(1)
    upload_command = ('twine upload dist/* '
                      f'-u {os.environ.get("PYPI_UPLOAD_USERNAME")} '
                      f'-p {os.environ.get("PYPI_UPLOAD_PASSWORD")} '
                      '--skip-existing '
                      f'--repository-url {os.environ.get("PYPI_URL")}')
    LOGGER.info('Trying to upload built artifact...')
    success = execute_command(upload_command)
    if success:
        LOGGER.info('%s Successfully uploaded artifact! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors found in uploading artifact! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)
Beispiel #9
0
def lint():
    bootstrap()
    success = execute_command('prospector -DFM')
    if success:
        success = execute_command('sam validate --template template.yml')
    if success:
        success = execute_command('sam validate --template tests/integration/test-template.yml')
    if success:
        success = execute_command('sam validate --template tests/integration/source-template.yml')
    if success:
        LOGGER.info('%s No linting errors found! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Linting errors found! %s',
                     emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)
Beispiel #10
0
def lint():
    emojize = bootstrap()
    success = execute_command('prospector -DFM')
    if success:
        LOGGER.info('%s No linting errors found! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Linting errors found! %s', emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)
Beispiel #11
0
def graph():
    bootstrap()
    os.chdir('graphs')
    create_graph_command = ('pyreverse '
                            '-o png '
                            '-A '
                            '-f PUB_ONLY '
                            '-p graphs {}').format(
                                os.path.join('..', f'{PROJECT_SLUG}'))
    success = execute_command(create_graph_command)
    if success:
        LOGGER.info('%s Successfully created graph images %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors in creation of graph images found! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)
Beispiel #12
0
def document():
    emojize = bootstrap()
    clean_up(
        ('_build', os.path.join('docs', '_build'),
         os.path.join('docs',
                      'test_docs.rst'), os.path.join('docs', 'modules.rst')))
    exit_code = execute_command('make -C docs html')
    success = not exit_code
    if success:
        shutil.move(os.path.join('docs', '_build'), '_build')
        path = os.path.join('_build', 'html', 'index.html')
        open_file(path)
        LOGGER.info('%s Successfully built documentation %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Documentation creation errors found! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    raise SystemExit(exit_code)
Beispiel #13
0
def upload():
    emojize = build()
    if not emojize:
        LOGGER.error('Errors caught on building the artifact, bailing out...')
        raise SystemExit(1)
    upload_command = ('twine upload dist/* '
                      '--skip-existing '
                      '--repository-url https://upload.pypi.org/legacy/')
    LOGGER.info('Trying to upload built artifact...')
    exit_code = execute_command(upload_command)
    success = not exit_code
    if success:
        LOGGER.info('%s Successfully uploaded artifact! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors found in uploading artifact! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    raise SystemExit(exit_code)
def graph():
    emojize = bootstrap()
    os.chdir('graphs')
    create_graph_command = ('pyreverse '
                            '-o png '
                            '-A '
                            '-f PUB_ONLY '
                            '-p graphs {}').format(
                                os.path.join('..',
                                             '{{cookiecutter.project_slug}}'))
    exit_code = execute_command(create_graph_command)
    success = not exit_code
    if success:
        LOGGER.info('%s Successfully created graph images %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Errors in creation of graph images found! %s',
                     emojize(':cross_mark:'), emojize(':crying_face:'))
    raise SystemExit(exit_code)
Beispiel #15
0
def test():
    bootstrap()
    clean_up('test-output')
    os.mkdir('test-output')
    save_requirements()
    success = execute_command('tox')
    try:
        open_file(os.path.join('test-output', 'coverage', 'index.html'))
        sleep(0.5)
        open_file(os.path.join('test-output', 'nosetests.html'))
    except Exception:
        LOGGER.warning('Could not execute UI portion. Maybe running headless?')
    if success:
        LOGGER.info('%s No testing errors found! %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Testing errors found! %s', emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)
Beispiel #16
0
def document():
    emojize = bootstrap()
    clean_up(('_build',
              os.path.join('docs', '_build'),
              os.path.join('docs', 'test_docs.rst'),
              os.path.join('docs', 'modules.rst')))
    success = execute_command('make -C docs html')
    if success:
        shutil.move(os.path.join('docs', '_build'), '_build')
        try:
            open_file(os.path.join('_build', 'html', 'index.html'))
        except Exception:
            LOGGER.warning('Could not execute UI portion. Maybe running headless?')
        LOGGER.info('%s Successfully built documentation %s',
                    emojize(':white_heavy_check_mark:'),
                    emojize(':thumbs_up:'))
    else:
        LOGGER.error('%s Documentation creation errors found! %s',
                     emojize(':cross_mark:'),
                     emojize(':crying_face:'))
    raise SystemExit(0 if success else 1)