Skip to content

Commit

Permalink
VCI-223: Add targets for build and push docker images (#29)
Browse files Browse the repository at this point in the history
* VCI-223: Add targets for build and push docker images

* VCI-223: Remove codesmells
  • Loading branch information
krankenbro authored Nov 29, 2021
1 parent 41f6176 commit ad38219
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions Docker/Build.Docker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Nuke.Common;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Utilities;

namespace VirtoCommerce.Build
{
internal partial class Build
{
[Parameter("Connection String")] public static string DockerConnectionString { get; set; }
[Parameter("Docker Username")] public static string DockerUsername { get; set; }
[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("Dockerfile Path")] public static string DockerfilePath { get; set; }

private static string DockerImageFullName => DockerImageTag.IsNullOrEmpty() ? DockerImageName : DockerImageName.Append($":{DockerImageTag}");

Target DockerLogin => _ => _
.Before(BuildImage, PushImage)
.Executes(() =>
{
var settings = new DockerLoginSettings()
.SetServer(DockerRegistryUrl)
.SetUsername(DockerUsername)
.SetPassword(DockerPassword);
DockerTasks.DockerLogin(settings);
});

Target BuildImage => _ => _
.Before(PushImage)
.Executes(() =>
{

var settings = new DockerBuildSettings()
.SetFile(DockerfilePath)
.SetPull(true)
.SetTag(DockerImageFullName);
DockerTasks.DockerBuild(settings);
});

Target PushImage => _ => _
.DependsOn(DockerLogin)
.Executes(() =>
{
var settings = new DockerImagePushSettings()
.SetName(DockerImageFullName);
DockerTasks.DockerImagePush(settings);
});

Target BuildAndPush => _ => _
.DependsOn(DockerLogin, BuildImage, PushImage);
}
}

0 comments on commit ad38219

Please sign in to comment.