public override async Task RunAsync() { if (!string.IsNullOrEmpty(FolderName)) { var folderPath = Path.Combine(Environment.CurrentDirectory, FolderName); FileSystemHelpers.EnsureDirectory(folderPath); Environment.CurrentDirectory = folderPath; } if (!Platforms.Contains(Platform)) { ColoredConsole.Error.WriteLine(ErrorColor($"platform {Platform} is not supported. Valid options are: {String.Join(",", Platforms)}")); return; } if (!CommandChecker.CommandExists("kubectl")) { ColoredConsole.Error.WriteLine(ErrorColor($"kubectl is required for deploying to kubernetes. Please make sure to install kubectl and try again.")); return; } var dockerFilePath = Path.Combine(Environment.CurrentDirectory, "Dockerfile"); if (!FileSystemHelpers.FileExists(dockerFilePath)) { ColoredConsole.Error.WriteLine(ErrorColor($"Dockerfile not found in directory {Environment.CurrentDirectory}")); return; } var image = $"{Registry}/{Name.SanitizeImageName()}"; ColoredConsole.WriteLine("Building Docker image..."); await DockerHelpers.DockerBuild(image, Environment.CurrentDirectory); ColoredConsole.WriteLine("Pushing function image to registry..."); await DockerHelpers.DockerPush(image); var platform = PlatformFactory.CreatePlatform(Platform, ConfigPath); if (platform == null) { ColoredConsole.Error.WriteLine(ErrorColor($"Platform {Platform} is not supported")); return; } await platform.DeployContainerizedFunction(Name, image, MinInstances, MaxInstances); }
public override async Task RunAsync() { (var resolvedImageName, var shouldBuild) = ResolveImageName(); TriggersPayload triggers = null; if (DryRun) { if (shouldBuild) { // don't build on a --dry-run. // read files from the local dir triggers = await GetTriggersLocalFiles(); } else { triggers = await DockerHelpers.GetTriggersFromDockerImage(resolvedImageName); } } else { if (shouldBuild) { await DockerHelpers.DockerBuild(resolvedImageName, Environment.CurrentDirectory); } triggers = await DockerHelpers.GetTriggersFromDockerImage(resolvedImageName); } (var resources, var funcKeys) = await KubernetesHelper.GetFunctionsDeploymentResources( Name, resolvedImageName, Namespace, triggers, _secretsManager.GetSecrets(), PullSecret, SecretsCollectionName, ConfigMapName, UseConfigMap, PollingInterval, CooldownPeriod, ServiceType, MinReplicaCount, MaxReplicaCount, KeysSecretCollectionName, MountFuncKeysAsContainerVolume); if (DryRun) { ColoredConsole.WriteLine(KubernetesHelper.SerializeResources(resources, OutputSerializationOptions.Yaml)); } else { if (!await KubernetesHelper.NamespaceExists(Namespace)) { await KubernetesHelper.CreateNamespace(Namespace); } if (shouldBuild) { await DockerHelpers.DockerPush(resolvedImageName); } foreach (var resource in resources) { await KubectlHelper.KubectlApply(resource, showOutput : true, ignoreError : IgnoreErrors, @namespace : Namespace); } //Print the function keys message to the console await KubernetesHelper.PrintFunctionsInfo($"{Name}-http", Namespace, funcKeys, triggers); } }