def Build(self):
        lyr_imgs = []
        lyr_imgs.append(self._base_image)
        if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx):
            layer_builder = node_builder.LayerBuilder(
                ctx=self._ctx,
                descriptor_files=self._descriptor_files,
                destination_path=self._args.destination_path)
            cached_pkg_img = None
            if self._args.cache:
                with ftl_util.Timing("checking cached pkg layer"):
                    key = layer_builder.GetCacheKey()
                    cached_pkg_img = self._cache.Get(key)
            if cached_pkg_img is not None:
                layer_builder.SetImage(cached_pkg_img)
            else:
                with ftl_util.Timing("building pkg layer"):
                    layer_builder.BuildLayer()
                if self._args.cache:
                    with ftl_util.Timing("uploading pkg layer"):
                        self._cache.Set(layer_builder.GetCacheKey(),
                                        layer_builder.GetImage())
            lyr_imgs.append(layer_builder)

        app = base_builder.AppLayerBuilder(self._ctx,
                                           self._args.destination_path,
                                           self._args.entrypoint,
                                           self._args.exposed_ports)
        with ftl_util.Timing("builder app layer"):
            app.BuildLayer()
        lyr_imgs.append(app)
        with ftl_util.Timing("stitching lyrs into final image"):
            ftl_image = self.AppendLayersIntoImage(lyr_imgs)
        with ftl_util.Timing("uploading final image"):
            self.StoreImage(ftl_image)
示例#2
0
    def setUp(self, mock_from):
        mock_from.return_value.__enter__.return_value = None
        self._tmpdir = tempfile.mkdtemp()
        self.ctx = context.Memory()
        self.ctx.AddFile("app.js", _APP)
        args = mock.Mock()
        args.name = 'gcr.io/test/test:latest'
        args.base = 'gcr.io/google-appengine/python:latest'
        args.tar_base_image_path = None
        self.builder = builder.Node(self.ctx, args)
        self.layer_builder = layer_builder.LayerBuilder(
            ctx=self.builder._ctx,
            descriptor_files=self.builder._descriptor_files,
            destination_path="/app")

        # Mock out the calls to package managers for speed.
        self.layer_builder._gen_npm_install_tar = mock.Mock()
        self.layer_builder._gen_npm_install_tar.return_value = ('layer', 'sha')
示例#3
0
    def Build(self):
        lyr_imgs = []
        lyr_imgs.append(self._base_image)
        if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx):
            layer_builder = node_builder.LayerBuilder(
                ctx=self._ctx,
                descriptor_files=self._descriptor_files,
                destination_path=self._args.destination_path,
                cache=self._cache)
            layer_builder.BuildLayer()
            lyr_imgs.append(layer_builder.GetImage())

        app = base_builder.AppLayerBuilder(self._ctx,
                                           self._args.destination_path,
                                           self._args.entrypoint,
                                           self._args.exposed_ports)
        app.BuildLayer()
        lyr_imgs.append(app.GetImage())
        ftl_image = ftl_util.AppendLayersIntoImage(lyr_imgs)
        self.StoreImage(ftl_image)
示例#4
0
    def Build(self):
        lyr_imgs = []
        lyr_imgs.append(self._base_image)
        # delete any existing files in node_modules folder
        if self._args.directory:
            modules_dir = os.path.join(self._args.directory, "node_modules")
            rm_cmd = ['rm', '-rf', modules_dir]
            ftl_util.run_command('rm_node_modules', rm_cmd)
            os.makedirs(os.path.join(modules_dir))

        if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx):
            layer_builder = node_builder.LayerBuilder(
                ctx=self._ctx,
                descriptor_files=self._descriptor_files,
                directory=self._args.directory,
                destination_path=self._args.destination_path,
                should_use_yarn=self._should_use_yarn,
                cache_key_version=self._args.cache_key_version,
                cache=self._cache)
            layer_builder.BuildLayer()
            lyr_imgs.append(layer_builder.GetImage())

        app = base_builder.AppLayerBuilder(
            directory=self._args.directory,
            destination_path=self._args.destination_path,
            entrypoint=self._args.entrypoint,
            exposed_ports=self._args.exposed_ports)
        app.BuildLayer()
        lyr_imgs.append(app.GetImage())
        if self._args.additional_directory:
            additional_directory = base_builder.AppLayerBuilder(
                directory=self._args.additional_directory,
                destination_path=self._args.additional_directory,
                entrypoint=self._args.entrypoint,
                exposed_ports=self._args.exposed_ports)
            additional_directory.BuildLayer()
            lyr_imgs.append(additional_directory.GetImage())
        ftl_image = ftl_util.AppendLayersIntoImage(lyr_imgs)
        self.StoreImage(ftl_image)