def cli(project, base_image, base_deps, add_deps, requirements): closest_scrapy_cfg = shub_utils.closest_file('scrapy.cfg') scrapy_config = shub_utils.get_config() if not closest_scrapy_cfg or not scrapy_config.has_option( 'settings', project): raise shub_exceptions.BadConfigException( 'Cannot find Scrapy project settings. Please ensure that current directory ' 'contains scrapy.cfg with settings section, see example at ' 'https://doc.scrapy.org/en/latest/topics/commands.html#default-structure-of-scrapy-projects' ) # NOQA project_dir = os.path.dirname(closest_scrapy_cfg) dockefile_path = os.path.join(project_dir, 'Dockerfile') if os.path.exists(dockefile_path): raise shub_exceptions.ShubException( 'Found a Dockerfile in the project directory, aborting') settings_module = scrapy_config.get('settings', 'default') shub_utils.create_default_setup_py(settings=settings_module) values = { 'base_image': base_image, 'system_deps': _format_system_deps(base_deps, add_deps), 'system_env': _format_system_env(settings_module), 'requirements': _format_requirements(project_dir, requirements), } values = {key: value if value else '' for key, value in values.items()} source = Template(DOCKERFILE_TEMPLATE) results = source.substitute(values) results = results.replace('\n\n', '\n') with open(dockefile_path, 'w') as dockerfile: dockerfile.write(results) click.echo("Dockerfile is saved to {}".format(dockefile_path))
def cli(project, base_image, base_deps, add_deps, requirements): closest_scrapy_cfg = shub_utils.closest_file('scrapy.cfg') scrapy_config = shub_utils.get_config() if not closest_scrapy_cfg or not scrapy_config.has_option('settings', project): raise shub_exceptions.BadConfigException( 'Cannot find Scrapy project settings. Please ensure that current directory ' 'contains scrapy.cfg with settings section, see example at ' 'https://doc.scrapy.org/en/latest/topics/commands.html#default-structure-of-scrapy-projects') # NOQA project_dir = os.path.dirname(closest_scrapy_cfg) dockefile_path = os.path.join(project_dir, 'Dockerfile') if os.path.exists(dockefile_path): raise shub_exceptions.ShubException('Found a Dockerfile in the project directory, aborting') settings_module = scrapy_config.get('settings', 'default') shub_utils.create_default_setup_py(settings=settings_module) values = { 'base_image': base_image, 'system_deps': _format_system_deps(base_deps, add_deps), 'system_env': _format_system_env(settings_module), 'requirements': _format_requirements(project_dir, requirements), } values = {key: value if value else '' for key, value in values.items()} source = Template(DOCKERFILE_TEMPLATE) results = source.substitute(values) results = results.replace('\n\n', '\n') with open(dockefile_path, 'w') as dockerfile: dockerfile.write(results) click.echo("Dockerfile is saved to {}".format(dockefile_path))
def _build_egg(): if not inside_project(): raise NotFoundException("No Scrapy project found in this location.") create_default_setup_py() d = tempfile.mkdtemp(prefix="shub-deploy-") run_python(['setup.py', 'clean', '-a', 'bdist_egg', '-d', d]) egg = glob.glob(os.path.join(d, '*.egg'))[0] return egg, d
def test_deploy_with_custom_setup_py(self, mock_deploy_req): with self.runner.isolated_filesystem(): # This scrapy.cfg contains no "settings" section, so creating a # default setup.py would fail (because we can't find the settings # module) open('scrapy.cfg', 'w').close() # However, we already have a setup.py... create_default_setup_py(settings='some_module') # ... so shub should not fail while trying to create one result = self.runner.invoke(deploy.cli) self.assertEqual(result.exit_code, 0)