def Run(self, args): _EnsureComponentsInstalled(args) settings = local.Settings.FromArgs(args) local_file_generator = local_files.LocalRuntimeFiles(settings) kubernetes_config = six.ensure_text( local_file_generator.KubernetesConfig()) _EnsureDockerRunning() with cross_platform_temp_file.NamedTempFile( kubernetes_config) as kubernetes_file: skaffold_config = six.ensure_text( local_file_generator.SkaffoldConfig(kubernetes_file.name)) skaffold_event_port = (args.skaffold_events_port or portpicker.pick_unused_port()) with cross_platform_temp_file.NamedTempFile(skaffold_config) as skaffold_file, \ self._GetKubernetesEngine(args) as kube_context, \ self._WithKubeNamespace(args.namespace, kube_context.context_name), \ _SetImagePush(skaffold_file, kube_context.shared_docker) as patched_skaffold_file, \ skaffold.Skaffold(patched_skaffold_file.name, kube_context.context_name, args.namespace, kube_context.env_vars, _IsDebug(), skaffold_event_port) as running_process, \ skaffold.PrintUrlThreadContext(settings.service_name, skaffold_event_port): running_process.wait()
def _SetImagePush(skaffold_file, shared_docker): """Set build.local.push value in skaffold file. Args: skaffold_file: Skaffold file handle. shared_docker: Boolean that is true if docker instance is shared between the kubernetes cluster and local docker builder. Yields: Path of skaffold file with build.local.push value set to the proper value. """ # TODO(b/149935260): This function can be removed when # https://github.com/GoogleContainerTools/skaffold/issues/3668 is resolved. if not shared_docker: # If docker is not shared, use the default value (false). There is no need # to rewrite the skaffold file. yield skaffold_file else: skaffold_yaml = yaml.load_path(skaffold_file.name) local_block = yaml_helper.GetOrCreate(skaffold_yaml, ('build', 'local')) local_block['push'] = False with cross_platform_temp_file.NamedTempFile( yaml.dump(skaffold_yaml)) as patched_skaffold_file: yield patched_skaffold_file
def testCanStripWhitespaceAtEnds(self): with cross_platform_temp_file.NamedTempFile( '\none\ntwo\n\n') as multi_line_file: lines = run_subprocess.GetOutputLines( ['cat', multi_line_file.name], timeout_sec=10, strip_output=True) self.assertEqual(lines, ['one', 'two'])
def Run(self, args): settings = local.Settings.FromArgs(args) local_file_generator = local_files.LocalRuntimeFiles(settings) kubernetes_config = six.ensure_text(local_file_generator.KubernetesConfig()) self._EnsureDockerInstalled() with cross_platform_temp_file.NamedTempFile( kubernetes_config) as kubernetes_file: skaffold_config = six.ensure_text( local_file_generator.SkaffoldConfig(kubernetes_file.name)) with cross_platform_temp_file.NamedTempFile(skaffold_config) as skaffold_file, \ self._GetKubernetesEngine(args) as kube_context, \ self._WithKubeNamespace(args.namespace, kube_context.context_name), \ _SetImagePush(skaffold_file, kube_context.shared_docker) as patched_skaffold_file, \ Skaffold(patched_skaffold_file.name, kube_context.context_name, args.namespace, kube_context.env_vars, args.additional_skaffold_flags) as skaffold: skaffold.wait()
def testJsonObjects(self): objs = [{'one': 'two', 'three': 4}, {'five': {'six': 'seven'}}] text = ''.join(json.dumps(obj) + '\n' for obj in objs) with cross_platform_temp_file.NamedTempFile(text) as multi_line_file: cmd = ['cat', multi_line_file.name] self.assertSequenceEqual( tuple( run_subprocess.StreamOutputJson(cmd, event_timeout_sec=10)), objs)
def testReturnsCommandOutputLines(self): with cross_platform_temp_file.NamedTempFile( 'one\ntwo') as multi_line_file: lines = run_subprocess.GetOutputLines( ['cat', multi_line_file.name], timeout_sec=10) self.assertEqual(lines, ['one', 'two'])
def _DeployTempFile(kubernetes_config): return cross_platform_temp_file.NamedTempFile(kubernetes_config, prefix='deploy_', suffix='.yaml', delete=not _IsDebug())
def _SkaffoldTempFile(skaffold_config): return cross_platform_temp_file.NamedTempFile(skaffold_config, prefix='skaffold_', suffix='.yaml', delete=not _IsDebug())