Ejemplo n.º 1
0
    def _handle_custom_template(self):
        """
        Fetches custom template (if provided) and saves as temporary
        file. This file is removed later in the process.
        """

        if not self.template:
            return

        self.log.info("Using custom provided template file: '%s'" % self.template)

        if Tools.is_url(self.template):
            self.template = self._fetch_file(self.template)

        if not os.path.exists(self.template):
            raise Error("Template file '%s' could not be found. Please make sure you specified correct path or check if the file was successfully fetched." % self.template)
Ejemplo n.º 2
0
    def render_from_template(self):
        if not self.cfg.get('labels'):
            self.cfg['labels'] = []

        labels = {}

        for label in self.cfg.get('labels'):
            labels[label['name']] = label['value']

        # https://github.com/jboss-dockerfiles/dogen/issues/129
        # https://github.com/jboss-dockerfiles/dogen/issues/137
        for label in ['maintainer', 'description']:
            value = self.cfg.get(label)

            if value and not label in labels:
                self.cfg['labels'].append({'name': label, 'value': value})
                labels[label] = value

        # https://github.com/jboss-dockerfiles/dogen/issues/195
        if 'summary' not in labels:
            if 'description' in labels:
                self.cfg['labels'].append({
                    'name': 'summary',
                    'value': labels.get('description')
                })

        if self.template:
            template_file = self.template
        else:
            self.log.debug("Using dogen provided template file")
            template_file = os.path.join(self.pwd, "templates",
                                         "template.jinja")

        self.log.info("Rendering Dockerfile...")
        loader = FileSystemLoader(os.path.dirname(template_file))
        env = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True)
        env.globals['helper'] = TemplateHelper()
        template = env.get_template(os.path.basename(template_file))

        with open(self.dockerfile, 'wb') as f:
            f.write(template.render(self.cfg).encode('utf-8'))
        self.log.debug("Done")

        if self.template and Tools.is_url(self.template):
            self.log.debug("Removing temporary template file...")
            os.remove(self.template)
Ejemplo n.º 3
0
    def _handle_additional_scripts(self):
        self.log.info("Additional scripts provided, installing them...")
        output_scripts = os.path.join(self.output, "scripts")

        if not os.path.exists(output_scripts):
            os.makedirs(output_scripts)

        for f in self.additional_scripts:
            self.log.debug("Handling '%s' file..." % f)
            if Tools.is_url(f):
                self._fetch_file(f, os.path.join(output_scripts, os.path.basename(f)))
            else:
                if not (os.path.exists(f) and os.path.isfile(f)):
                    raise Error("File '%s' does not exist. Please make sure you specified correct path to a file when specifying additional scripts." % f)

                self.log.debug("Copying '%s' file to target scripts directory..." % f)
                shutil.copy(f, output_scripts)
Ejemplo n.º 4
0
 def _download_source(self, artifact, filename, hint=None):
     if Tools.is_url(artifact):
         self.log.warn(
             "Trying to download the '%s' artifact from original location" %
             artifact)
         try:
             self._fetch_file(artifact, filename)
         except Exception as e:
             raise Error(
                 "Could not download artifact from orignal location, reason: %s"
                 % str(e))
     else:
         if hint:
             self.log.info(hint)
         self.log.info(
             "Please download the '%s' artifact manually and save it as '%s'"
             % (artifact, filename))
         raise Error("Artifact '%s' could not be fetched!" % artifact)
Ejemplo n.º 5
0
    def _handle_custom_template(self):
        """
        Fetches custom template (if provided) and saves as temporary
        file. This file is removed later in the process.
        """

        if not self.template:
            return

        self.log.info("Using custom provided template file: '%s'" %
                      self.template)

        if Tools.is_url(self.template):
            self.template = self._fetch_file(self.template)

        if not os.path.exists(self.template):
            raise Error(
                "Template file '%s' could not be found. Please make sure you specified correct path or check if the file was successfully fetched."
                % self.template)
Ejemplo n.º 6
0
    def render_from_template(self):
        if self.template:
            template_file = self.template
        else:
            self.log.debug("Using dogen provided template file")
            template_file = os.path.join(self.pwd, "templates", "template.jinja")

        self.log.info("Rendering Dockerfile...")
        loader = FileSystemLoader(os.path.dirname(template_file))
        env = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True)
        env.globals['helper'] = TemplateHelper()
        template = env.get_template(os.path.basename(template_file))

        with open(self.dockerfile, 'wb') as f:
            f.write(template.render(self.cfg).encode('utf-8'))
        self.log.debug("Done")

        if self.template and Tools.is_url(self.template):
            self.log.debug("Removing temporary template file...")
            os.remove(self.template)
Ejemplo n.º 7
0
    def render_from_template(self):
        if self.template:
            template_file = self.template
        else:
            self.log.debug("Using dogen provided template file")
            template_file = os.path.join(self.pwd, "templates",
                                         "template.jinja")

        self.log.info("Rendering Dockerfile...")
        loader = FileSystemLoader(os.path.dirname(template_file))
        env = Environment(loader=loader, trim_blocks=True, lstrip_blocks=True)
        env.globals['helper'] = TemplateHelper()
        template = env.get_template(os.path.basename(template_file))

        with open(self.dockerfile, 'w') as f:
            f.write(template.render(self.cfg).encode('utf-8'))
        self.log.debug("Done")

        if self.template and Tools.is_url(self.template):
            self.log.debug("Removing temporary template file...")
            os.remove(self.template)
Ejemplo n.º 8
0
    def _handle_additional_scripts(self):
        self.log.info("Additional scripts provided, installing them...")
        output_scripts = os.path.join(self.output, "scripts")

        if not os.path.exists(output_scripts):
            os.makedirs(output_scripts)

        for f in self.additional_scripts:
            self.log.debug("Handling '%s' file..." % f)
            if Tools.is_url(f):
                self._fetch_file(
                    f, os.path.join(output_scripts, os.path.basename(f)))
            else:
                if not (os.path.exists(f) and os.path.isfile(f)):
                    raise Error(
                        "File '%s' does not exist. Please make sure you specified correct path to a file when specifying additional scripts."
                        % f)

                self.log.debug(
                    "Copying '%s' file to target scripts directory..." % f)
                shutil.copy(f, output_scripts)
Ejemplo n.º 9
0
 def test_remote_https_file(self):
     self.assertTrue(Tools.is_url("https://host/file.tmp"))
Ejemplo n.º 10
0
 def test_local_file(self):
     self.assertFalse(Tools.is_url("a_file.tmp"))
Ejemplo n.º 11
0
 def test_remote_https_file(self):
     self.assertTrue(Tools.is_url("https://host/file.tmp"))
Ejemplo n.º 12
0
 def test_local_file(self):
     self.assertFalse(Tools.is_url("a_file.tmp"))