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.php", _APP) args = mock.Mock() args.name = 'gcr.io/test/test:latest' args.base = 'gcr.io/google-appengine/php:latest' args.tar_base_image_path = None self.builder = builder.PHP(self.ctx, args) self.layer_builder = layer_builder.PhaseOneLayerBuilder( self.builder._ctx, self.builder._descriptor_files, "/app") # Mock out the calls to package managers for speed. self.layer_builder._gen_composer_install_tar = mock.Mock() self.layer_builder._gen_composer_install_tar.return_value = ('layer', 'sha')
def Build(self): lyr_imgs = [] lyr_imgs.append(self._base_image) if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx): if self._ctx.Contains(constants.COMPOSER_LOCK): pkgs = self._parse_composer_lock_pkgs() else: pkgs = self._parse_composer_pkgs() # due to image layers limits, we revert to using phase 1 if over # the threshold if len(pkgs) > 41: # phase 1 logging.info('Building package layer') layer_builder = php_builder.PhaseOneLayerBuilder( 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()) else: # phase 2 for pkg_txt in pkgs: logging.info('Building package layer: {0} {1}'.format( pkg_txt[0], pkg_txt[1])) layer_builder = php_builder.PhaseTwoLayerBuilder( ctx=self._ctx, descriptor_files=self._descriptor_files, pkg_descriptor=pkg_txt, destination_path=self._args.destination_path, cache=self._cache) layer_builder.BuildLayer() lyr_imgs.append(layer_builder.GetImage()) app = base_builder.AppLayerBuilder( ctx=self._ctx, destination_path=self._args.destination_path, entrypoint=self._args.entrypoint, exposed_ports=self._args.exposed_ports) app.BuildLayer() lyr_imgs.append(app.GetImage()) ftl_image = ftl_util.AppendLayersIntoImage(lyr_imgs) self.StoreImage(ftl_image)
def Build(self): lyr_imgs = [] lyr_imgs.append(self._base_image) if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx): if self._ctx.Contains(constants.COMPOSER_LOCK): pkgs = self._parse_composer_lock_pkgs() else: pkgs = self._parse_composer_pkgs() # due to image layers limits, we revert to using phase 1 if over # the threshold if len(pkgs) > 41: # phase 1 logging.info('Building package layer') layer_builder = php_builder.PhaseOneLayerBuilder( 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()) else: # phase 2 with ftl_util.Timing('uploading_all_package_layers'): with concurrent.futures.ThreadPoolExecutor( max_workers=constants.THREADS) as executor: future_to_params = {executor.submit( self._build_pkg, pkg_txt, lyr_imgs): pkg_txt for pkg_txt in pkgs } for future in concurrent.futures.as_completed( future_to_params): future.result() app = base_builder.AppLayerBuilder( ctx=self._ctx, destination_path=self._args.destination_path, entrypoint=self._args.entrypoint, exposed_ports=self._args.exposed_ports) app.BuildLayer() lyr_imgs.append(app.GetImage()) ftl_image = ftl_util.AppendLayersIntoImage(lyr_imgs) self.StoreImage(ftl_image)
def Build(self): lyr_imgs = [] lyr_imgs.append(self._base_image) # delete any existing files in vendor folder if self._args.directory: vendor_dir = os.path.join(self._args.directory, 'vendor') rm_cmd = ['rm', '-rf', vendor_dir] ftl_util.run_command('rm_vendor_dir', rm_cmd) os.makedirs(os.path.join(vendor_dir)) if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx): self._gen_composer_lock() layer_builder = php_builder.PhaseOneLayerBuilder( ctx=self._ctx, descriptor_files=self._descriptor_files, directory=self._args.directory, destination_path=self._args.destination_path, 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)
def Build(self): lyr_imgs = [] lyr_imgs.append(self._base_image) if ftl_util.has_pkg_descriptor(self._descriptor_files, self._ctx): logging.info('Building package layer') layer_builder = php_builder.PhaseOneLayerBuilder( ctx=self._ctx, descriptor_files=self._descriptor_files, destination_path=self._args.destination_path, directory=self._args.directory, 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()) ftl_image = ftl_util.AppendLayersIntoImage(lyr_imgs) self.StoreImage(ftl_image)