From 5096a8be2c30793459b61f97ef40ef78a00e4875 Mon Sep 17 00:00:00 2001 From: Charles d'Avernas Date: Wed, 23 Apr 2025 15:22:29 +0200 Subject: [PATCH] fix: Resolved an issue in `DockerRuntime` where it failed to check for the presence of the image locally, resulting in the image not being pulled when necessary. Signed-off-by: Charles d'Avernas --- .../Services/DockerRuntime.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/runtime/Synapse.Runtime.Docker/Services/DockerRuntime.cs b/src/runtime/Synapse.Runtime.Docker/Services/DockerRuntime.cs index 1804ccc8f..044c699d1 100644 --- a/src/runtime/Synapse.Runtime.Docker/Services/DockerRuntime.cs +++ b/src/runtime/Synapse.Runtime.Docker/Services/DockerRuntime.cs @@ -15,6 +15,8 @@ using Docker.DotNet.Models; using Microsoft.Extensions.DependencyInjection; using Synapse.Runtime.Services; +using static Synapse.SynapseDefaults.Resources; +using System.Net; namespace Synapse.Runtime.Docker.Services; @@ -76,8 +78,20 @@ public override async Task CreateProcessAsync(Workflow workflo try { this.Logger.LogDebug("Creating a new Docker container for workflow instance '{workflowInstance}'...", workflowInstance.GetQualifiedName()); - if (this.Docker == null) await this.InitializeAsync(cancellationToken).ConfigureAwait(false); + if (this.Docker == null) await this.InitializeAsync(cancellationToken).ConfigureAwait(false); var container = this.Runner.Runtime.Docker!.ContainerTemplate.Clone()!; + try + { + await this.Docker!.Images.InspectImageAsync(container.Image, cancellationToken).ConfigureAwait(false); + } + catch (DockerApiException ex) when (ex.StatusCode == HttpStatusCode.NotFound) + { + var downloadProgress = new Progress(); + var imageComponents = container.Image.Split(':'); + var imageName = imageComponents[0]; + var imageTag = imageComponents.Length > 1 ? imageComponents[1] : null; + await this.Docker!.Images.CreateImageAsync(new() { FromImage = imageName, Tag = imageTag }, new(), downloadProgress, cancellationToken).ConfigureAwait(false); + } container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.Namespace, workflowInstance.GetNamespace()!); container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.Name, $"{workflowInstance.GetName()}-{Guid.NewGuid().ToString("N")[..12].ToLowerInvariant()}"); container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Uri, this.Runner.Api.Uri.OriginalString);