Пример #1
0
    def build(self):
        # only initiate the build if the current spec is different than the last spec built
        if self._json != self.last_build:

            try:
                # clean up the old build
                build_path = os.path.join(self.path, "build")
                make_dir(build_path, clean=True)

                # copy new file and replace all template placeholders with parameters
                build_dirs = ["components", "deployments", "images"]
                for bd in build_dirs:
                    bd_path = os.path.join(build_path, bd)
                    shutil.copytree(os.path.join(self.path, bd), bd_path)
                    for root, dirs, files in os.walk(
                            os.path.join(build_path, bd)):
                        for f in files:
                            fill_template(os.path.join(root, f),
                                          self.parameters)

                # now that all templates are filled, build/upload images
                for image in self.images:
                    try:
                        image_name = MainSettings.REGISTRY_NAME + "/" + self.full_name + "-" + image[
                            "name"]
                        image_path = os.path.join(build_path, "images",
                                                  image["name"])
                        subprocess.check_call(
                            ['docker', 'build', '-t', image_name, image_path])
                        info_log(
                            self.TAG,
                            "Squashing and pushing {} to private registry...".
                            format(image_name))
                        subprocess.check_call([
                            os.path.join(MainSettings.ROOT, "util",
                                         "squash-and-push"), image_name
                        ])
                    except subprocess.CalledProcessError as e:
                        raise Service.BuildFailedException(
                            "could not build service {0}: {1}".format(
                                self.full_name, e))
            except Service.BuildFailedException as e:
                error_log(
                    self.TAG, "could not build service: {0}: {1}".format(
                        self.full_name, e))
                return False

            info_log(self.TAG, "Successfully built {0}".format(self.full_name))
            # write latest build parameters
            self.index.save_service(self)
            return True
        else:
            info_log(
                self.TAG,
                "Image {0} not changed since last build. Not rebuilding.".
                format(self.full_name))
            return True
Пример #2
0
 def _fill_templates(self, build_path):
     print "Copying files and filling templates..."
     images_path = os.path.join(ROOT, "images")
     for img in os.listdir(images_path):
         img_path = os.path.join(images_path, img)
         bd_path = os.path.join(build_path, img)
         shutil.copytree(img_path, bd_path)
         for root, dirs, files in os.walk(bd_path):
             for f in files:
                 fill_template(os.path.join(root, f), self._json)
Пример #3
0
 def _fill_templates(self, build_path):
     info_log(self.TAG, "Copying files and filling templates...", app=self.name)
     images_path = os.path.join(MainSettings.ROOT, "images")
     for img in os.listdir(images_path):
         img_path = os.path.join(images_path, img)
         bd_path = os.path.join(build_path, img)
         shutil.copytree(img_path, bd_path)
         for root, dirs, files in os.walk(bd_path):
             for f in files:
                 fill_template(os.path.join(root, f), self._json)
Пример #4
0
 def _fill_templates(self, build_path):
     print "Copying files and filling templates..."
     images_path = os.path.join(ROOT, "images")
     for img in os.listdir(images_path):
         img_path = os.path.join(images_path, img)
         bd_path = os.path.join(build_path, img)
         shutil.copytree(img_path, bd_path)
         for root, dirs, files in os.walk(bd_path):
             for f in files:
                 fill_template(os.path.join(root, f), self._json)
Пример #5
0
    def build(self):
        # only initiate the build if the current spec is different than the last spec built
        if self._json != self.last_build:

            try:
                # clean up the old build
                build_path = os.path.join(self.path, "build")
                make_dir(build_path, clean=True)

                # copy new file and replace all template placeholders with parameters
                build_dirs = ["components", "deployments", "images"]
                for bd in build_dirs:
                    bd_path = os.path.join(build_path, bd)
                    shutil.copytree(os.path.join(self.path, bd), bd_path)
                    for root, dirs, files in os.walk(os.path.join(build_path, bd)):
                        for f in files:
                            fill_template(os.path.join(root, f), self.parameters)

                # now that all templates are filled, build/upload images
                for image in self.images:
                    try:
                        image_name = REGISTRY_NAME + "/" + self.full_name + "-" + image["name"]
                        image_path = os.path.join(build_path, "images", image["name"])
                        subprocess.check_call(['docker', 'build', '-t', image_name, image_path])
                        print("Squashing and pushing {} to private registry...".format(image_name))
                        subprocess.check_call([os.path.join(ROOT, "util", "squash-and-push"), image_name])
                    except subprocess.CalledProcessError as e:
                        raise Service.BuildFailedException("could not build service {0}: {1}".format(self.full_name, e))
            except Service.BuildFailedException as e:
                print("could not build service: {0}: {1}".format(self.full_name, e))
                return False

            print("Successfully built {0}".format(self.full_name))
            # write latest build parameters
            self.index.save_service(self)
            return True
        else:
            print("Image {0} not changed since last build. Not rebuilding.".format(self.full_name))
            return True