FluentDocker
FluentDocker copied to clipboard
DockerUri.Build call does not tag the images
Hi! I found the following issue while using the package. It's nothing serious, but if you have a bit of time, please take a look. Thanks for everything, have a nice day!
ISSUE:
When using the DockerUri.Build(...) method with name, tag and work directory the created image is not tagged with the specified values. The workaround is to add a ContainerBuildParams object to the call with a non-null Tags array.
// NOT TAGGED
var buildResult = docker.Host.Build(
"my-app",
"latest",
"..\\..\\MyApp");
// TAGGED
var buildResult = docker.Host.Build(
"my-app",
"latest",
"..\\..\\MyApp",
new ContainerBuildParams { Tags = Array.Empty<string>() });
The offending code from the package seems to be the following:
public static CommandResponse<IList<string>> Build(this DockerUri host, string name, string tag, string workdir = null,
ContainerBuildParams prms = null,
ICertificatePaths certificates = null)
{
if (null == tag)
{
tag = "latest";
}
if (string.IsNullOrEmpty(workdir))
{
workdir = ".";
}
var options = string.Empty;
// NOTE:
// If prms or the Tags property within is null, the tags are not added.
// That's why adding a ContainerBuildParams with an empty Tags array works.
if (null != prms?.Tags)
{
// ANOTHER NOTE:
// This comparison is also a bit weird, because the prms.Tags will contain full 'name:tag' values,
// but the tag will only contain the 'tag' itself.
if (!prms.Tags.Any(x => x == tag))
{
options = $"-t {name}:{tag}";
}
}
if (null != prms)
{
options += $" {prms}";
}
return
new ProcessExecutor<StringListResponseParser, IList<string>>(
"docker".ResolveBinary(),
$"{host.RenderBaseArgs(certificates)} build {options} {workdir}").Execute();
}
Hi @dil-bkis and thanks for your good bug report!
I'll add it to my TODO list.
Cheers, Mario :)