From 3e196355deb87ff9f4c0c0b4643f512e62257bf8 Mon Sep 17 00:00:00 2001 From: JoannaaKL Date: Wed, 2 Nov 2022 11:27:37 +0100 Subject: [PATCH] Allow the container.image to be empty (#2235) * Allow container.image to be null/empty * Remove unnecessary workflow type * Update src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> * Rename ConvertToJobContainer to ConvertToContainer It converts serviceContainers too * Remove unused parameter AllowExpressions was always false * Allow service in yaml with empty string for value * Don't attempt to start services without an image * Improve error messages * Revert "Remove unused parameter" This reverts commit f4ab2d50d0cbf7287460c206cec817434839c0c7. * Revert "Rename ConvertToJobContainer to ConvertToContainer" This reverts commit ffc62f834328af5c8509dfaff75e4cbdcc4e8238. * Fix revert merge conflict * Removed info logs * Added info log for services without container images Co-authored-by: moonblade Co-authored-by: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Co-authored-by: Ava Stancu --- src/Runner.Worker/JobExtension.cs | 5 +++++ .../Pipelines/ObjectTemplating/PipelineTemplateConverter.cs | 2 +- src/Sdk/DTPipelines/workflow-v1.0.json | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Runner.Worker/JobExtension.cs b/src/Runner.Worker/JobExtension.cs index 58e1b1137..246274734 100644 --- a/src/Runner.Worker/JobExtension.cs +++ b/src/Runner.Worker/JobExtension.cs @@ -220,6 +220,11 @@ namespace GitHub.Runner.Worker { var networkAlias = pair.Key; var serviceContainer = pair.Value; + if (serviceContainer == null) + { + context.Output($"The service '{networkAlias}' will not be started because the container definition has an empty image."); + continue; + } jobContext.Global.ServiceContainers.Add(new Container.ContainerInfo(HostContext, serviceContainer, false, networkAlias)); } } diff --git a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs index 69f9a3d32..506a7d268 100644 --- a/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs +++ b/src/Sdk/DTPipelines/Pipelines/ObjectTemplating/PipelineTemplateConverter.cs @@ -316,7 +316,7 @@ namespace GitHub.DistributedTask.Pipelines.ObjectTemplating if (String.IsNullOrEmpty(result.Image)) { - context.Error(value, "Container image cannot be empty"); + return null; } return result; diff --git a/src/Sdk/DTPipelines/workflow-v1.0.json b/src/Sdk/DTPipelines/workflow-v1.0.json index 6ae301fbd..a3745029b 100644 --- a/src/Sdk/DTPipelines/workflow-v1.0.json +++ b/src/Sdk/DTPipelines/workflow-v1.0.json @@ -381,7 +381,7 @@ "container-mapping": { "mapping": { "properties": { - "image": "non-empty-string", + "image": "string", "options": "non-empty-string", "env": "container-env", "ports": "sequence-of-non-empty-string", @@ -414,7 +414,7 @@ "vars" ], "one-of": [ - "non-empty-string", + "string", "container-mapping" ] },