def _gen_npm_install_tar(self, pkg_descriptor, app_dir): if self._ctx: if self._ctx.Contains(constants.PACKAGE_JSON): self._check_gcp_build( json.loads(self._ctx.GetFile(constants.PACKAGE_JSON)), app_dir) rm_cmd = ['rm', '-rf', os.path.join(app_dir, 'node_modules')] ftl_util.run_command('rm_node_modules', rm_cmd) if not pkg_descriptor: npm_install_cmd = ['npm', 'install', '--production'] ftl_util.run_command('npm_install', npm_install_cmd, cmd_cwd=app_dir, err_type=ftl_error.FTLErrors.USER()) else: npm_install_cmd = [ 'npm', 'install', '--production', pkg_descriptor ] ftl_util.run_command('npm_install', npm_install_cmd, cmd_cwd=app_dir, err_type=ftl_error.FTLErrors.USER()) modules_dir = os.path.join(app_dir, "node_modules") module_destination = os.path.join(self._destination_path, 'node_modules') return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)
def _gen_composer_install_tar(self, pkg_descriptor, destination_path): # Create temp directory to write package descriptor to pkg_dir = tempfile.mkdtemp() app_dir = os.path.join(pkg_dir, destination_path.strip("/")) print 'app_dir: %s' % app_dir os.makedirs(app_dir) # Copy out the relevant package descriptors to a tempdir. if pkg_descriptor is None: # phase 1 copy whole descriptor ftl_util.descriptor_copy(self._ctx, self._descriptor_files, app_dir) subprocess.check_call(['rm', '-rf', os.path.join(app_dir, 'vendor')]) with ftl_util.Timing("composer_install"): if pkg_descriptor is None: # phase 1 install entire descriptor subprocess.check_call( ['composer', 'install', '--no-dev', '--no-scripts'], cwd=app_dir) else: pkg, version = pkg_descriptor subprocess.check_call( ['composer', 'require', str(pkg), str(version)], cwd=app_dir) return ftl_util.zip_dir_to_layer_sha(pkg_dir)
def _build_layer(self): python_util.setup_venv(self._venv_dir, self._venv_cmd, self._python_cmd) blob, u_blob = ftl_util.zip_dir_to_layer_sha(self._venv_dir, self._venv_dir) overrides = ftl_util.generate_overrides(True, self._venv_dir) self._img = tar_to_dockerimage.FromFSImage([blob], [u_blob], overrides)
def _gen_yarn_install_tar(self, app_dir): yarn_install_cmd = ['yarn', 'install', '--production'] ftl_util.run_command('yarn_install', yarn_install_cmd, cmd_cwd=app_dir, err_type=ftl_error.FTLErrors.USER()) module_destination = os.path.join(self._destination_path, 'node_modules') modules_dir = os.path.join(self._directory, "node_modules") return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)
def _gen_composer_install_tar(self, app_dir, destination_path): composer_install_cmd = [ 'composer', 'install', '--no-dev', '--no-progress', '--no-suggest', '--no-interaction' ] ftl_util.run_command('composer_install', composer_install_cmd, cmd_cwd=app_dir, cmd_env=php_util.gen_composer_env(), err_type=ftl_error.FTLErrors.USER()) vendor_dir = os.path.join(self._directory, 'vendor') vendor_destination = os.path.join(destination_path, 'vendor') return ftl_util.zip_dir_to_layer_sha(vendor_dir, vendor_destination)
def _gen_npm_install_tar(self, app_dir): npm_install_cmd = ['npm', 'install', '--production'] npm_output = ftl_util.run_command('npm_install', npm_install_cmd, cmd_cwd=app_dir, err_type=ftl_error.FTLErrors.USER()) module_destination = os.path.join(self._destination_path, 'node_modules') modules_dir = os.path.join(self._directory, "node_modules") if not os.path.isdir(modules_dir) or os.listdir(modules_dir) == []: if "Invalid name" in npm_output: raise ftl_error.UserError("%s\n%s" % (npm_output, "0")) return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)
def _gen_composer_install_tar(self, destination_path, pkg_descriptor): # Create temp directory to write package descriptor to pkg_dir = tempfile.mkdtemp() app_dir = os.path.join(pkg_dir, destination_path.strip("/")) os.makedirs(app_dir) rm_cmd = ['rm', '-rf', os.path.join(app_dir, 'vendor')] ftl_util.run_command('rm_vendor_dir', rm_cmd) pkg, version = pkg_descriptor composer_install_cmd = ['composer', 'require', str(pkg), str(version)] ftl_util.run_command('composer_require', composer_install_cmd, app_dir, err_type=ftl_error.FTLErrors.USER()) return ftl_util.zip_dir_to_layer_sha(pkg_dir)
def BuildLayer(self): """Override.""" with ftl_util.Timing('Building app layer'): gz, tar = ftl_util.zip_dir_to_layer_sha(self._directory, self._destination_path) overrides_dct = { 'created': str(datetime.date.today()) + 'T00:00:00Z' } if self._entrypoint: overrides_dct['Entrypoint'] = self._entrypoint if self._exposed_ports: overrides_dct['ExposedPorts'] = self._exposed_ports if self._exposed_ports: overrides_dct['ExposedPorts'] = self._exposed_ports logging.info('Finished gzipping tarfile.') self._img = tar_to_dockerimage.FromFSImage([gz], [tar], overrides_dct)
def _gen_yarn_install_tar(self, app_dir): is_gcp_build = False if self._ctx and self._ctx.Contains(constants.PACKAGE_JSON): is_gcp_build = self._is_gcp_build( json.loads(self._ctx.GetFile(constants.PACKAGE_JSON))) if is_gcp_build: self._gcp_build(app_dir, 'yarn', 'run') else: yarn_install_cmd = ['yarn', 'install', '--production'] ftl_util.run_command('yarn_install', yarn_install_cmd, cmd_cwd=app_dir, err_type=ftl_error.FTLErrors.USER()) module_destination = os.path.join(self._destination_path, 'node_modules') modules_dir = os.path.join(self._directory, "node_modules") return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)
def _gen_composer_install_tar(self, destination_path): # Create temp directory to write package descriptor to pkg_dir = tempfile.mkdtemp() app_dir = os.path.join(pkg_dir, destination_path.strip("/")) os.makedirs(app_dir) # Copy out the relevant package descriptors to a tempdir. ftl_util.descriptor_copy(self._ctx, self._descriptor_files, app_dir) rm_cmd = ['rm', '-rf', os.path.join(app_dir, 'vendor')] ftl_util.run_command('rm_vendor_dir', rm_cmd) composer_install_cmd = [ 'composer', 'install', '--no-dev', '--no-scripts' ] ftl_util.run_command('composer_install', composer_install_cmd, app_dir, err_type=ftl_error.FTLErrors.USER()) return ftl_util.zip_dir_to_layer_sha(pkg_dir)
def BuildLayer(self): cached_img = None if self._cache: with ftl_util.Timing('checking_cached_pipfile_pkg_layer'): key = self.GetCacheKey() cached_img = self._cache.Get(key) self._log_cache_result(False if cached_img is None else True) if cached_img: self.SetImage(cached_img) else: self._pip_download_wheels(' '.join(self._pkg_descriptor)) whls = self._resolve_whls() if len(whls) != 1: raise Exception("expected one whl for one installed pkg") pkg_dir = self._whl_to_fslayer(whls[0]) blob, u_blob = ftl_util.zip_dir_to_layer_sha(pkg_dir, "") overrides = ftl_util.generate_overrides(False, self._venv_dir) self._img = tar_to_dockerimage.FromFSImage([blob], [u_blob], overrides) if self._cache: with ftl_util.Timing('uploading_pipfile_pkg_layer'): self._cache.Set(self.GetCacheKey(), self.GetImage())
def _gen_npm_install_tar(self, pkg_descriptor, destination_path): # Create temp directory to write package descriptor to pkg_dir = tempfile.mkdtemp() app_dir = os.path.join(pkg_dir, destination_path.strip("/")) os.makedirs(app_dir) # Copy out the relevant package descriptors to a tempdir. ftl_util.descriptor_copy(self._ctx, self._descriptor_files, app_dir) self._check_gcp_build( json.loads(self._ctx.GetFile(constants.PACKAGE_JSON)), app_dir) subprocess.check_call( ['rm', '-rf', os.path.join(app_dir, 'node_modules')]) with ftl_util.Timing("npm_install"): if pkg_descriptor is None: subprocess.check_call(['npm', 'install', '--production'], cwd=app_dir) else: subprocess.check_call( ['npm', 'install', '--production', pkg_descriptor], cwd=app_dir) return ftl_util.zip_dir_to_layer_sha(pkg_dir)
def BuildLayer(self): self._setup_venv(self._python_version) blob, u_blob = ftl_util.zip_dir_to_layer_sha( os.path.abspath(os.path.join(self._venv_dir, os.pardir))) self._img = tar_to_dockerimage.FromFSImage( [blob], [u_blob], _generate_overrides(True))
def BuildLayer(self): blob, u_blob = ftl_util.zip_dir_to_layer_sha(self._pkg_dir) self._img = tar_to_dockerimage.FromFSImage( [blob], [u_blob], _generate_overrides(False))
def _build_layer(self): blob, u_blob = ftl_util.zip_dir_to_layer_sha(self._pkg_dir, "") overrides = ftl_util.generate_overrides(False) self._img = tar_to_dockerimage.FromFSImage([blob], [u_blob], overrides)