Ejemplo n.º 1
0
 def up(self, *args, **kwargs):
     need_build = True
     image_with_tag = ApplicationRecorder().get_record("image_with_tag")
     if image_with_tag is None:
         Logger.warnf(
             "Failed to find your docker image, You should build it by your self."
         )
         need_build = False
     if is_windows() is True:
         try:
             import win32api
             if need_build is True:
                 win32api.WinExec('docker build -t %s .' % image_with_tag)
             win32api.WinExec('kubectl apply -f kubernetes-deployment.yaml')
         except Exception as e:
             Logger.error(
                 "Can not start your application.Have you installed kubelet in path?"
             )
         return
     status = os.system("docker build -t %s ." % image_with_tag)
     if status != 0:
         Logger.info(
             "Failed to build docker image, Have you installed docker in path?"
         )
         sys.exit(-1)
     status = os.system("kubectl apply -f kubernetes-deployment.yaml")
     if status == 0:
         Logger.info(
             "Your application has been up to running! You can run `kubelet get svc` to get exposed ports."
         )
     else:
         Logger.error(
             "Can not start your application.Have you installed kubelet in path?"
         )
Ejemplo n.º 2
0
 def execute(self, *args, **kwargs):
     Logger.info("Detecting PHP version ...")
     version = DEFAULT_VERSION
     try:
         output = subprocess.check_output(["php", "-version"], shell=False, stderr=subprocess.STDOUT)
         version = PhpVersionDetector.get_most_relative_version(output)
     except Exception as e:
         Logger.debug("Failed to detect PHP version,because of %s" % e)
         Logger.debug("Use default PHP version:%s instead ." % DEFAULT_VERSION)
     return {"version": version}
Ejemplo n.º 3
0
    def up(self, *args, **kwargs):
        if is_windows() is True:
            try:
                import win32api

                win32api.WinExec('docker-compose up --build -d ')
            except Exception as e:
                Logger.error(
                    "Can not start your application.Have you installed docker-compose in path?"
                )
            return
        status = os.system("/bin/bash -i -c 'docker-compose up --build -d '")
        if status == 0:
            Logger.info(
                "Your application has been up to running! You can run `docker ps` to get exposed ports."
            )
        else:
            Logger.error(
                "Can not start your application.Have you installed docker-compose in path?"
            )
Ejemplo n.º 4
0
    def execute(self, context):
        if check_application_first_setup() is True:
            Logger.info(
                "Your application haven't been initialized,you can run `derrick init`."
            )
            return

        if check_dockerfile_exists() is False:
            Logger.info(
                "Dockerfile is not exists, Maybe you can rerun `derrick init` to resolve it."
            )
            return
        # if is_windows() is True:
        #     try:
        #         import win32api
        #         win32api.WinExec('docker-compose up --build -d ')
        #     except Exception as e:
        #         Logger.error("Can not start your application.Have you installed docker-compose in path?")
        #     return
        # status = os.system("/bin/bash -i -c 'docker-compose up --build -d '")
        # if status == 0:
        #     Logger.info("Your application has been up to running! You can run `docker ps` to get exposed ports.")
        # else:
        #     Logger.error("Can not start your application.Have you installed docker-compose in path?")
        engine_manager = Derrick().get_engine_manager()
        recorder = Derrick().get_recorder()
        select_engine = recorder.get_record("engine")
        engines = engine_manager.all()
        for engine_name in engines.keys():
            if engine_name.find(select_engine.lower()) != -1:
                Logger.info(select_engine +
                            " is the default Orchestration Engine.")
                engines[engine_name].up()
Ejemplo n.º 5
0
 def pre_load(self):
     os.mkdir(get_derrick_home())
     os.mkdir(get_rigging_home())
     os.mkdir(get_commands_home())
     Logger.info(DERRICK_LOGO)
     Logger.info("This is the first time to run Derrick.\n")
     Logger.info("Successfully create DERRICK_HOME in %s" % (get_derrick_home()))
Ejemplo n.º 6
0
    def execute(self, context):
        if check_application_first_setup() is True:
            Logger.info(
                "Your application haven't been initialized,you can run `derrick init`."
            )
            return

        if check_dockerfile_exists() is False:
            Logger.info(
                "Dockerfile is not exists, Maybe you can rerun `derrick init` to resolve it."
            )
            return
        if is_windows() is True:
            try:
                import win32api
                win32api.WinExec('docker-compose up -d ')
            except Exception as e:
                Logger.error(
                    "Can not start your application.Have you installed docker-compose in path?"
                )
            return
        status = os.system("/bin/bash -i -c 'docker-compose up -d '")
        if status == 0:
            Logger.info(
                "Your application has been up to running! You can run `docker ps` to get exposed ports."
            )
        else:
            Logger.error(
                "Can not start your application.Have you installed docker-compose in path?"
            )
Ejemplo n.º 7
0
 def pre_load(self):
     os.mkdir(get_derrick_home())
     os.mkdir(get_rigging_home())
     os.mkdir(get_commands_home())
     Logger.info(DERRICK_LOGO)
     Logger.info("This is the first time to run Derrick.\n")
     Logger.info("Successfully create DERRICK_HOME in %s" %
                 (get_derrick_home()))
Ejemplo n.º 8
0
    def execute(self, context):
        if check_application_first_setup() is True:
            Logger.info(
                "Your application haven't been initialized,you can run `derrick init`."
            )
            return

        if check_dockerfile_exists() is False:
            Logger.info(
                "Dockerfile is not exists, Maybe you can rerun `derrick init` to resolve it."
            )
            return

        status = os.system("/bin/bash -i -c 'docker-compose up -d '")
        if status == 0:
            Logger.info(
                "Your application has been up to running! You can run `docker ps` to get exposed ports."
            )
Ejemplo n.º 9
0
Archivo: up.py Proyecto: ipaste/derrick
    def execute(self, context):
        if check_application_first_setup() is True:
            Logger.info("Your application haven't been initialized,you can run `derrick init`.")
            return

        if check_dockerfile_exists() is False:
            Logger.info("Dockerfile is not exists, Maybe you can rerun `derrick init` to resolve it.")
            return
        if is_windows() is True:
            try:
                import win32api
                win32api.WinExec('docker-compose up --build -d ')
            except Exception as e:
                Logger.error("Can not start your application.Have you installed docker-compose in path?")
            return
        status = os.system("/bin/bash -i -c 'docker-compose up --build -d '")
        if status == 0:
            Logger.info("Your application has been up to running! You can run `docker ps` to get exposed ports.")
        else:
            Logger.error("Can not start your application.Have you installed docker-compose in path?")
Ejemplo n.º 10
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