Skip to content

Commit

Permalink
VCI-869: Make DockerImageTag array (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored May 2, 2024
1 parent 32c96e6 commit 7217e72
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using Serilog;
using VirtoCloud.Client.Api;
using VirtoCloud.Client.Model;
Expand Down Expand Up @@ -171,7 +172,7 @@ private async Task PrepareDockerContextMethod()
DockerImageName = $"{DockerUsername}/{EnvironmentName.ToLowerInvariant()}";
}

DockerImageTag ??= DateTime.Now.ToString("MMddyyHHmmss");
DockerImageTag ??= new string[] { DateTime.Now.ToString("MMddyyHHmmss") };
DockerfilePath = dockerfilePath;
DiscoveryPath = modulesPath;
ProbingPath = Path.Combine(platformDirectory, "app_data", "modules");
Expand Down Expand Up @@ -263,7 +264,7 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu
var envHelmParameters = env.Helm.Parameters;

envHelmParameters["platform.image.repository"] = DockerImageName;
envHelmParameters["platform.image.tag"] = DockerImageTag;
envHelmParameters["platform.image.tag"] = DockerImageTag[0];

await cloudClient.UpdateEnvironmentAsync(env);
});
Expand Down Expand Up @@ -375,9 +376,9 @@ private void SaveCloudToken(string token)
model.Helm.Parameters["platform.image.repository"] = DockerImageName;
}

if(!string.IsNullOrEmpty(DockerImageTag))
if(!DockerImageTag.IsNullOrEmpty())
{
model.Helm.Parameters["platform.image.tag"] = DockerImageTag;
model.Helm.Parameters["platform.image.tag"] = DockerImageTag[0];
}


Expand Down
39 changes: 35 additions & 4 deletions src/VirtoCommerce.Build/Docker/Build.Docker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Nuke.Common;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using Serilog;

namespace VirtoCommerce.Build
Expand All @@ -26,11 +29,27 @@ public static string DockerUsername
[Parameter("Docker Password")] public static string DockerPassword { get; set; }
[Parameter("Docker Registry Url")] public static string DockerRegistryUrl { get; set; }
[Parameter("Docker Image Name")] public static string DockerImageName { get; set; }
[Parameter("Docker Image Tag")] public static string DockerImageTag { get; set; }
[Parameter("Docker Image Tag")] public static string[] DockerImageTag { get; set; }
[Parameter("Dockerfile Path")] public static string DockerfilePath { get; set; }
[Parameter("Docker build context path")] public static string DockerBuildContextPath { get; set; }

private static string DockerImageFullName => string.IsNullOrEmpty(DockerImageTag) ? DockerImageName : DockerImageName.Append($":{DockerImageTag}");
private static string[] DockerImageFullName
{
get
{
if (DockerImageTag.IsNullOrEmpty())
{
return new string[] { DockerImageName };
}

var result = new List<string>();
foreach(var tag in DockerImageTag)
{
result.Add(DockerImageName.Append($":{tag}"));
}
return result.ToArray();
}
}

public static bool DockerCredentialsPassed => !string.IsNullOrEmpty(DockerUsername) && !string.IsNullOrEmpty(DockerPassword);
Target DockerLogin => _ => _
Expand Down Expand Up @@ -64,9 +83,21 @@ public static string DockerUsername
.DependsOn(DockerLogin)
.Executes(() =>
{
var settings = new DockerImagePushSettings()
.SetName(DockerImageFullName);
DockerImagePushSettings settings;
if(DockerImageTag?.Length > 1)
{
settings = new DockerImagePushSettings()
.SetName(DockerImageName)
.SetAllTags(true);
}
else
{
settings = new DockerImagePushSettings()
.SetName(DockerImageFullName[0]);
}

DockerTasks.DockerImagePush(settings);

});

public Target BuildAndPush => _ => _
Expand Down

0 comments on commit 7217e72

Please sign in to comment.