Esempio n. 1
0
    def _generate_platform_dockerfile(self, service_ip_dict, service_info):
        fmlogging.debug("Inside _generate_platform_dockerfile")

        env_vars = ''
        export_vars = ''

        # Generate Dockerfile
        df_fp = open(self.instance_prov_workdir + "/Dockerfile.aws", "w")
        df = ("FROM amazon/aws-eb-python:3.4.2-onbuild-3.5.1\n"
              "RUN apt-get update && apt-get install -y \ \n"
              "    python-setuptools python-pip git\n"
              "ADD requirements.txt /src/requirements.txt \n"
              "RUN cd /src; pip install -r requirements.txt \n"
              "ADD . /src \n"
              "EXPOSE 8080 \n")
        # Generate runapp.sh
        runapp_fp = open(self.instance_prov_workdir + "/runapp.sh", "w")
        runapp = ("#!/bin/sh \n")

        if 'env_variables' in self.task_def.app_data or service_ip_dict:
            if service_ip_dict:
                print_prefix = "export "
                env_key_suffix = "="
                runapp_env_vars = utils.get_env_vars_string(
                    self.task_def, service_ip_dict, self.app_variables,
                    self.services, print_prefix, env_key_suffix)
                runapp = runapp + runapp_env_vars
                print_prefix = "ENV "
                env_key_suffix = " "
                df_env_vars = utils.get_env_vars_string(
                    self.task_def, service_ip_dict, self.app_variables,
                    self.services, print_prefix, env_key_suffix)
                df = df + df_env_vars

            if 'env_variables' in self.task_def.app_data:
                env_var_obj = self.task_def.app_data['env_variables']
                if env_var_obj:
                    for key, value in env_var_obj.iteritems():
                        env_vars = env_vars + (" ENV {key} {value}\n").format(
                            key=key, value=value)
                        export_vars = export_vars + (
                            "export {key}={value}\n").format(key=key,
                                                             value=value)
                    df = df + env_vars
                    runapp = runapp + export_vars

        runapp = runapp + ("python /src/{entry_point}\n").format(
            entry_point=self.entry_point + ".py")
        runapp_fp.write(runapp)
        runapp_fp.close()

        # Setting permission to 555
        permission = s.S_IRUSR | s.S_IRGRP | s.S_IROTH | s.S_IXUSR | s.S_IXGRP | s.S_IXOTH
        os.chmod(self.instance_prov_workdir + "/runapp.sh", permission)

        df = df + ("CMD /src/runapp.sh \n")
        df_fp.write(df)
        df_fp.close()
Esempio n. 2
0
    def _generate_app_yaml(self, app_deploy_dir, service_ip_dict):
        app_yaml = self._get_app_yaml()
        app_yaml = app_yaml + ("  script: {app_entry_point}.app \n"
                               "\n").format(app_entry_point=self.entry_point)

        if service_ip_dict:
            print_prefix = "    "
            env_key_suffix = ": "
            app_yaml_env_vars = utils.get_env_vars_string(self.task_def,
                                                          service_ip_dict,
                                                          self.app_variables,
                                                          self.services,
                                                          print_prefix,
                                                          env_key_suffix)

            app_yaml = app_yaml + ("env_variables:\n") + app_yaml_env_vars

        if 'env_variables' in self.task_def.app_data:
            env_var_obj = self.task_def.app_data['env_variables']
            env_vars = ''
            app_yaml = app_yaml + ("env_variables:\n")
            if env_var_obj:
                for key, value in env_var_obj.iteritems():
                        env_vars = env_vars + ("    {key}: {value}\n").format(key=key, value=value)
                app_yaml = app_yaml + env_vars

        fp = open(app_deploy_dir + "/app.yaml", "w")
        fp.write(app_yaml)
        fp.close()
Esempio n. 3
0
    def _generate_for_python_app(self, service_ip_dict):

        df_env_vars = ''
        serv_ip = ''
        if bool(service_ip_dict):
            print_prefix = "ENV "
            env_key_suffix = " "

            df_env_vars, serv_ip = utils.get_env_vars_string(
                self.task_def, service_ip_dict, self.app_variables,
                self.services, print_prefix, env_key_suffix)

        entry_point = self.task_def.app_data['entry_point']

        df = ''
        if bool(service_ip_dict):
            df = ("FROM ubuntu:14.04\n"
                  "RUN apt-get update -y \ \n"
                  "    && apt-get install -y python-setuptools python-pip\n"
                  "ADD requirements.txt /src/requirements.txt\n"
                  "RUN cd /src; pip install -r requirements.txt\n"
                  "ADD . /src\n"
                  "EXPOSE {app_port}\n").format(app_port=self.app_port)
            import platform

            if platform.system() == 'Darwin':
                parts = serv_ip.split(":")
                serv_port = parts[1].strip()
                df_env_vars = df_env_vars + "\n" + "ENV PORT " + serv_port + "\n"
            df = df + df_env_vars
            df = df + ("CMD [\"python\", \"/src/{entry_point}\"]").format(
                entry_point=entry_point)
        else:
            df = ("FROM ubuntu:14.04\n"
                  "RUN apt-get update -y \ \n"
                  "    && apt-get install -y python-setuptools python-pip\n"
                  "ADD requirements.txt /src/requirements.txt\n"
                  "RUN cd /src; pip install -r requirements.txt\n"
                  "ADD . /src\n"
                  "EXPOSE {app_port}\n").format(app_port=self.app_port)

            if 'env_variables' in self.task_def.app_data:
                env_var_obj = self.task_def.app_data['env_variables']
                env_vars = ''
                if env_var_obj:
                    for key, value in env_var_obj.iteritems():
                        env_vars = env_vars + ("ENV {key} {value}\n").format(
                            key=key, value=value)
                    df = df + env_vars

            df = df + ("CMD [\"python\", \"/src/{entry_point}\"]").format(
                entry_point=entry_point)

        fmlogging.debug("App dir: %s" % self.app_dir)
        docker_file_dir = ("{app_dir}/{app_name}").format(
            app_dir=self.app_dir, app_name=self.app_name)
        fmlogging.debug("Dockerfile dir:%s" % docker_file_dir)
        docker_file = open(docker_file_dir + "/Dockerfile", "w")
        docker_file.write(df)
        docker_file.close()
Esempio n. 4
0
    def _generate_platform_dockerfile_prev(self, service_ip_dict,
                                           service_info):
        fmlogging.debug("Inside _generate_platform_dockerfile")
        if service_info:
            app_dir = ("{app_dir}/{app_name}").format(app_dir=self.app_dir,
                                                      app_name=self.app_name)
            db_name = constants.DEFAULT_DB_NAME
            user = constants.DEFAULT_DB_USER
            password = constants.DEFAULT_DB_PASSWORD
            instance_dns = service_ip_dict[self.instance_name]

        # Generate runapp.sh
        runapp_fp = ''
        env_vars = ''
        export_vars = ''
        df_fp = ''

        if 'env_variables' in self.task_def.app_data or service_ip_dict:
            # Generate Dockerfile
            df_fp = open(self.instance_prov_workdir + "/Dockerfile.aws", "w")
            df = ("FROM ubuntu:14.04\n"
                  "RUN apt-get update && apt-get install -y \ \n"
                  "    python-setuptools python-pip git\n"
                  "ADD requirements.txt /src/requirements.txt \n"
                  "RUN cd /src; pip install -r requirements.txt \n"
                  "ADD . /src \n"
                  "EXPOSE 5000 \n")
            runapp_fp = open(self.instance_prov_workdir + "/runapp.sh", "w")
            runapp = ("#!/bin/sh \n")

            if service_ip_dict:
                print_prefix = "export "
                env_key_suffix = "="
                runapp_env_vars = utils.get_env_vars_string(
                    self.task_def, service_ip_dict, self.app_variables,
                    self.services, print_prefix, env_key_suffix)
                runapp = runapp + runapp_env_vars
                print_prefix = "ENV "
                env_key_suffix = " "
                df_env_vars = utils.get_env_vars_string(
                    self.task_def, service_ip_dict, self.app_variables,
                    self.services, print_prefix, env_key_suffix)
                df = df + df_env_vars

            if 'env_variables' in self.task_def.app_data:
                env_var_obj = self.task_def.app_data['env_variables']
                if env_var_obj:
                    for key, value in env_var_obj.iteritems():
                        env_vars = env_vars + (" ENV {key} {value}\n").format(
                            key=key, value=value)
                        export_vars = export_vars + (
                            "export {key}={value}\n").format(key=key,
                                                             value=value)
                    df = df + env_vars
                    runapp = runapp + export_vars

            runapp = runapp + ("python /src/{entry_point}\n").format(
                entry_point=self.entry_point + ".py")
            runapp_fp.write(runapp)
            runapp_fp.close()

            # Setting permission to 555
            permission = s.S_IRUSR | s.S_IRGRP | s.S_IROTH | s.S_IXUSR | s.S_IXGRP | s.S_IXOTH
            os.chmod(self.instance_prov_workdir + "/runapp.sh", permission)

            df = df + ("CMD /src/runapp.sh \n")
            df_fp.write(df)
            df_fp.close()