コード例 #1
0
ファイル: app.py プロジェクト: kaecloud/console
    def create(cls, name, app, specs_text, comment=''):
        """app must be an App instance"""
        appname = app.name

        # check the format of specs text(ignore the result)
        app_specs_schema.load(yaml.safe_load(specs_text))

        try:
            new_yaml = cls(name=name, app_id=app.id, specs_text=specs_text, comment=comment)
            db.session.add(new_yaml)
            db.session.commit()
        except IntegrityError:
            logger.warn('Fail to create AppYaml %s %s, duplicate', appname, name)
            db.session.rollback()
            raise

        return new_yaml
コード例 #2
0
ファイル: app.py プロジェクト: kaecloud/console
    def update(self, specs_text, image=None, build_status=False, branch='', author='', commit_message=''):
        """app must be an App instance"""
        # check the format of specs text(ignore the result)
        app_specs_schema.load(yaml.safe_load(specs_text))
        misc = {
            'author': author,
            'commit_message': commit_message,
            'git': self.git,
        }

        try:
            # self.specs_text = specs_text
            super(Release, self).update(specs_text=specs_text, image=image, build_status=build_status, misc=json.dumps(misc))
        except:
            logger.warn('Fail to update Release %s %s', self.appname, self.tag)
            db.session.rollback()
            # raise
        return self
コード例 #3
0
    def create(cls, app, tag, specs_text):
        """app must be an App instance"""
        if isinstance(specs_text, Dict):
            specs_text = yaml.dump(specs_text.to_dict())
        elif isinstance(specs_text, dict):
            specs_text = yaml.dump(specs_text)
        else:
            # check the format of specs text(ignore the result)
            app_specs_schema.load(yaml.load(specs_text))

        try:
            new_release = cls(tag=tag, app_id=app.id, specs_text=specs_text)
            db.session.add(new_release)
            db.session.commit()
        except IntegrityError:
            logger.warn('Fail to create SpecVersion %s %s, duplicate', app.name, tag)
            db.session.rollback()
            raise

        return new_release
コード例 #4
0
ファイル: app.py プロジェクト: kaecloud/console
    def create(cls, app, tag, yaml_name, specs_text, parent_id, cluster, config_id=None):
        """app must be an App instance"""
        if isinstance(specs_text, Dict):
            specs_text = yaml.dump(specs_text.to_dict())
        elif isinstance(specs_text, dict):
            specs_text = yaml.dump(specs_text)
        else:
            # check the format of specs text(ignore the result)
            app_specs_schema.load(yaml.safe_load(specs_text))

        try:
            ver = cls(tag=tag, app_id=app.id, parent_id=parent_id, cluster=cluster,
                      config_id=config_id, yaml_name=yaml_name, specs_text=specs_text)
            db.session.add(ver)
            db.session.commit()
        except IntegrityError:
            logger.warn('Fail to create SpecVersion %s %s, duplicate', app.name, tag)
            db.session.rollback()
            raise

        return ver
コード例 #5
0
ファイル: app.py プロジェクト: kaecloud/console
    def create(cls, app, tag, specs_text, image=None, build_status=False, branch='', author='', commit_message=''):
        """app must be an App instance"""
        appname = app.name

        # check the format of specs text(ignore the result)
        app_specs_schema.load(yaml.safe_load(specs_text))
        misc = {
            'author': author,
            'commit_message': commit_message,
            'git': app.git,
        }

        try:
            new_release = cls(tag=tag, app_id=app.id, image=image, build_status=build_status, specs_text=specs_text, misc=json.dumps(misc))
            db.session.add(new_release)
            db.session.commit()
        except IntegrityError:
            logger.warn('Fail to create Release %s %s, duplicate', appname, tag)
            db.session.rollback()
            raise

        return new_release
コード例 #6
0
ファイル: test.py プロジェクト: kaecloud/cli
def test(appname, tag, f, literal):
    """build test image and run test script in app.yaml"""
    repo_dir = os.getcwd()
    if f:
        repo_dir = os.path.dirname(os.path.abspath(f))

    appname = get_appname(cwd=repo_dir, appname=appname)
    tag = get_git_tag(cwd=repo_dir, git_tag=tag, required=False)
    if tag is None:
        tag = 'latest'

    specs_text = get_specs_text(f, literal)
    if specs_text is None:
        errmsg = [
            "specs_text is required, please use one of the instructions to specify it.",
            "1. specify --literal or -f in coomand line",
            "2. make the current workdir in the source code dir which contains app.yaml"
        ]
        fatal('\n'.join(errmsg))
    try:
        yaml_dict = yaml.load(specs_text)
    except yaml.YAMLError as e:
        fatal('specs text is invalid yaml {}'.format(str(e)))
    try:
        specs = app_specs_schema.load(yaml_dict).data
    except Exception as e:
        fatal('specs text is invalid: {}'.format(str(e)))
    if "test" not in specs:
        fatal("no test specified in app.yaml")
    builds = specs['test']['builds']
    if len(builds) == 0:
        builds = specs["builds"]
    for build in builds:
        image_tag = build.tag if build.tag else tag
        dockerfile = build.get('dockerfile', None)
        if dockerfile is None:
            dockerfile = os.path.join(repo_dir, "Dockerfile")
        full_image_name = "{}:{}".format(build.name, image_tag)
        build_image(full_image_name, repo_dir, None, dockerfile=dockerfile)

    default_image_name = "{}:{}".format(appname, tag)
    for entrypoint in specs['test']['entrypoints']:
        image = entrypoint.image if entrypoint.image else default_image_name
        cmd = entrypoint.script
        volumes = entrypoint.get('volumes', [])
        run_container(image, volumes, cmd)
コード例 #7
0
ファイル: prepare.py プロジェクト: kaecloud/console
def make_specs(appname=default_appname,
               container_user=None,
               builds=default_builds,
               volumes=['/tmp:/home/{}/tmp'.format(default_appname)],
               base='python:latest',
               subscribers='#platform',
               crontab=[],
               **kwargs):
    specs_dict = locals()
    kwargs = specs_dict.pop('kwargs')
    for k, v in kwargs.items():
        specs_dict[k] = v

    specs_dict = {
        k: copy.deepcopy(v)
        for k, v in specs_dict.items() if v is not None
    }
    specs_string = yaml.dump(specs_dict)
    unmarshal_result = app_specs_schema.load(specs_dict)
    return unmarshal_result.data
コード例 #8
0
ファイル: app.py プロジェクト: kaecloud/console
 def specs(self):
     dic = yaml.safe_load(self.specs_text)
     unmarshal_result = app_specs_schema.load(dic)
     return unmarshal_result.data