Esempio n. 1
0
 def execute(self, *args, **kwargs):
     try:
         questions = [
             {
                 'type': 'input',
                 'name': 'image_with_tag',
                 'message': 'What\'s your image repo ',
             }
         ]
         answers = prompt(questions)
     except Exception as e:
         Logger.warn("Failed to detect image repo. Windows console don't support prompt action.")
         Logger.warn("Jenkinsfile and docker-compose.yml may not be generated completely.")
         answers = {"image_with_tag": "[IMAGE_WITH_TAG]"}
     return answers
Esempio n. 2
0
 def execute(self, *args, **kwargs):
     try:
         questions = [{
             'type': 'input',
             'name': 'image_with_tag',
             'message': 'What\'s your image repo ',
         }]
         answers = prompt(questions)
     except Exception as e:
         Logger.warn(
             "Failed to detect image repo. Windows console don't support prompt action."
         )
         Logger.warn(
             "Jenkinsfile and docker-compose.yml may not be generated completely."
         )
         answers = {"image_with_tag": "[IMAGE_WITH_TAG]"}
     return answers
Esempio n. 3
0
 def execute(self, *args, **kwargs):
     try:
         questions = [
             {
                 'type': 'input',
                 'name': 'image_with_tag',
                 'message': 'Please input image name with tag (such as "registry.com/user/repo:tag"): ',
             }
         ]
         answers = prompt(questions)
         if len(answers.keys()) is 0:
             sys.exit(0)
     except KeyboardInterrupt:
         sys.exit(0)
     except Exception as e:
         Logger.warn("Failed to detect image repo. Windows console don't support prompt action.")
         Logger.warn("Jenkinsfile and docker-compose.yml may not be generated completely.")
         answers = {"image_with_tag": "[IMAGE_WITH_TAG]"}
     return answers
Esempio n. 4
0
    def render_templates(templates_dir=None, dest_dir=None, compile_dict=None):
        if templates_dir is None or dest_dir is None or compile_dict is None:
            raise ParamsShortageException(
                "compile templates need some more params")
        all_success = True
        for template_name in os.listdir(templates_dir):
            template_path = os.path.join(templates_dir, template_name)
            try:
                Init.render_template(template_path, dest_dir,
                                     compile_dict.get(template_name))
            except Exception as e:
                all_success = False
                Logger.debug(
                    "template_path:%s,dest_dir:%s,content:%s" %
                    (template_path, dest_dir, compile_dict.get(template_name)))
                Logger.warn("Failed to compile template(%s),because of %s" %
                            (template_name, e))

        return all_success
Esempio n. 5
0
    def execute(self, context):
        # TODO add application recorder to record the application platform and other things.

        rigging_manager = Derrick().get_rigging_manager()
        all_rigging = rigging_manager.all()

        detected = False
        handled_rigging = []
        for rigging_name in all_rigging:
            rigging = all_rigging.get(rigging_name)
            try:
                handled, platform = rigging.detect(context)
                if handled is True:
                    detected = True
                    handled_rigging.append({"rigging_name": rigging_name, "rigging": rigging, "platform": platform})
            except Exception as e:
                Logger.error("Failed to detect your application's platform with rigging(%s),because of %s"
                             % (rigging_name, e))

        if detected is True:
            if len(handled_rigging) > 1:
                # TODO when more than one rigging can handle your application.
                Logger.warn("More than one rigging can handle the application.")
                rigging_dict = Init.choose_rigging(handled_rigging)
                if rigging_dict is None:
                    Logger.error("The Rigging you chosen maybe broken.")
                    return
            else:
                rigging_dict = handled_rigging[0]

            rigging = rigging_dict.get("rigging")
            rdi = RiggingDetectInfo(rigging_dict.get("rigging_name"), rigging_dict.get("platform"))
            try:
                results = rigging.compile(context)
                Logger.debug("The platform is %s,the rigging used is %s"
                             % (rigging_dict.get("platform"), rigging_dict.get("rigging_name")))
                Logger.debug("The results is %s" % results)
            except Exception as e:
                Logger.error("Failed to compile your application.because of %s" % e)
                return

            if type(results) is dict:
                try:
                    template_dir = rigging.get_template_dir()
                    dest_dir = context.get(WORKSPACE_ENV)
                    Logger.debug("Ready to render templates and template_dir:%s,dest_dir:%s,compile_dict:%s" % (
                        template_dir, dest_dir, results))
                    Init.render_templates(templates_dir=template_dir, dest_dir=dest_dir, compile_dict=results)
                    Logger.info("Derrick detect your platform is %s and compile successfully."
                                % rigging_dict.get("platform"))
                except Exception as e:
                    Logger.error("Failed to render template with rigging(%s),because of %s"
                                 % (rigging.get_name(), e))
                try:
                    ApplicationRecorder().record(rdi)
                except Exception as e:
                    Logger.debug("Failed to record detected information.because of %s" % e)
            else:
                raise RiggingCompileException("compile results is not a dict.")
        else:
            Logger.warn(
                "Failed to detect your application's platform."
                "Maybe you can upgrade Derrick to get more platforms supported.")
            return