コード例 #1
0
ファイル: stoic.py プロジェクト: dtsukiyama/stoic
def push():
    """
    This pushes Docker model image to ECR and also build a local Docker image for testing.
    """
    current_dir = os.getcwd()
    target = current_dir + "/" + 'models'
    dirs = dirWalk(target)
    try:
        if len(dirs) == 0:
            click.echo("There currently are no models")

        else:
            answers = prompt(questions)
            pprint.pprint(answers)
            docker_model = answers['docker model']
            model = [
                b for b in dirWalk(target + '/' + docker_model)
                if b != 'local_test'
            ][0]
            createModel((docker_model, model))
            with changeDirectory(target + '/' + docker_model):
                command = './build_and_push.sh {}'.format(model)
                subprocess.run([command], shell=True)
            raise Exception('ECR push...')

    except Exception as e:
        print(e)
コード例 #2
0
ファイル: stoic.py プロジェクト: dtsukiyama/stoic
def predictlocal(payload, content_type):
    answers = prompt(repos)
    pprint.pprint(answers)
    image = answers['image']
    container, _ = image.split(':')
    current_dir = os.getcwd()
    target = current_dir + "/" + 'models'
    try:
        with changeDirectory(target + '/' + container + '/local_test'):
            command = './predict.sh {} {}'.format(payload, content_type)
            subprocess.run([command], shell=True)
        raise Exception('local prediction complete')

    except Exception as e:
        print(e)
コード例 #3
0
ファイル: stoic.py プロジェクト: dtsukiyama/stoic
def servelocal():
    answers = prompt(repos)
    pprint.pprint(answers)
    image = answers['image']
    container, model = image.split(':')
    current_dir = os.getcwd()
    target = current_dir + "/" + 'models'
    try:
        with changeDirectory(target + '/' + container + '/local_test'):
            command = './serve_local.sh {} > outlog.log'.format(model)
            subprocess.run([command], shell=True)
        raise Exception('Local server')

    except Exception as e:
        print(e)
コード例 #4
0
ファイル: customdata.py プロジェクト: sivaavkd/cvereport
def runnpmaudit(pkgjsonfolder, cvedate, createAuditReport=True):
    bChangedDir = utils.changeDirectory(pkgjsonfolder)
    cvesfound = []
    pkglockcmd, auditcmd = consts.getnpmauditCmd()
    if packageLockExits() == False:
        print('Generating package lock file...')
        pkglocktext = os.popen(pkglockcmd).read()
    print('Running npm audit...')
    auditresult = json.loads(os.popen(auditcmd).read())
    for audititem in auditresult['advisories']:
        for cveitem in auditresult['advisories'][audititem]['cves']:
            cvesfound.append(cveitem)
    if createAuditReport:
        with open(consts.getNPMAuditReportName(), 'w') as outfile:
            json.dump(auditresult, outfile, indent=4)
    if bChangedDir:
        utils.MoveUpDir()
        utils.MoveUpDir()
    return cvesfound
コード例 #5
0
ファイル: stoic.py プロジェクト: dtsukiyama/stoic
def trainlocal():
    answers = prompt(repos)
    pprint.pprint(answers)
    image = answers['image']
    container, model = image.split(':')
    current_dir = os.getcwd()
    target = current_dir + "/" + 'models'
    executables = ['predict.sh', 'serve_local.sh', 'train_local.sh']
    try:
        with changeDirectory(target + '/' + container + '/local_test'):
            for _file in executables:
                st = os.stat(_file)
                os.chmod(_file, st.st_mode | stat.S_IEXEC)
                command = './train_local.sh {}'.format(model)
                subprocess.run([command], shell=True)

            raise Exception('local train complete')

    except Exception as e:
        print(e)
コード例 #6
0
ファイル: stoic.py プロジェクト: dtsukiyama/stoic
def build():
    """
    This builds a Docker image from a model container.
    """
    current_dir = os.getcwd()
    target = current_dir + "/" + 'models'
    dirs = dirWalk(target)
    try:
        if len(dirs) == 0:
            click.echo("There currently are no models")
        else:
            answers = prompt(questions)
            pprint.pprint(answers)
            # create build_and_push executable
            # check if train, serve and build_and_push are executables
            # chmod +x {model}/train
            # chmod +x {model}/serve
            # chmod +x build_and_push.sh
            docker_model = answers['docker model']
            print('Create executables for {}.'.format(docker_model))
            # model
            model = [
                b for b in dirWalk(target + '/' + docker_model)
                if b != 'local_test'
            ]

            train = model[0] + '/train'
            serve = model[0] + '/serve'
            executables = ['build_and_push.sh', train, serve]
            print(executables)

            with changeDirectory(target + '/' + docker_model):
                for _file in executables:
                    st = os.stat(_file)
                    os.chmod(_file, st.st_mode | stat.S_IEXEC)
                raise Exception('Container executables finished')
            print('done')

    except Exception as e:
        print(e)