Skip to content

Commit 6dacc40

Browse files
authored
Merge pull request #503 from serverlessworkflow/fix-docker-runtime
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.
2 parents ff4e3e5 + 5096a8b commit 6dacc40

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/runtime/Synapse.Runtime.Docker/Services/DockerRuntime.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using Docker.DotNet.Models;
1616
using Microsoft.Extensions.DependencyInjection;
1717
using Synapse.Runtime.Services;
18+
using static Synapse.SynapseDefaults.Resources;
19+
using System.Net;
1820

1921
namespace Synapse.Runtime.Docker.Services;
2022

@@ -76,8 +78,20 @@ public override async Task<IWorkflowProcess> CreateProcessAsync(Workflow workflo
7678
try
7779
{
7880
this.Logger.LogDebug("Creating a new Docker container for workflow instance '{workflowInstance}'...", workflowInstance.GetQualifiedName());
79-
if (this.Docker == null) await this.InitializeAsync(cancellationToken).ConfigureAwait(false);
81+
if (this.Docker == null) await this.InitializeAsync(cancellationToken).ConfigureAwait(false);
8082
var container = this.Runner.Runtime.Docker!.ContainerTemplate.Clone()!;
83+
try
84+
{
85+
await this.Docker!.Images.InspectImageAsync(container.Image, cancellationToken).ConfigureAwait(false);
86+
}
87+
catch (DockerApiException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
88+
{
89+
var downloadProgress = new Progress<JSONMessage>();
90+
var imageComponents = container.Image.Split(':');
91+
var imageName = imageComponents[0];
92+
var imageTag = imageComponents.Length > 1 ? imageComponents[1] : null;
93+
await this.Docker!.Images.CreateImageAsync(new() { FromImage = imageName, Tag = imageTag }, new(), downloadProgress, cancellationToken).ConfigureAwait(false);
94+
}
8195
container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.Namespace, workflowInstance.GetNamespace()!);
8296
container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.Name, $"{workflowInstance.GetName()}-{Guid.NewGuid().ToString("N")[..12].ToLowerInvariant()}");
8397
container.SetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Api.Uri, this.Runner.Api.Uri.OriginalString);

0 commit comments

Comments
 (0)