Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DockerUri.Build call does not tag the images #279

Open
dil-bkis opened this issue Sep 23, 2022 · 1 comment
Open

DockerUri.Build call does not tag the images #279

dil-bkis opened this issue Sep 23, 2022 · 1 comment
Assignees
Labels
Milestone

Comments

@dil-bkis
Copy link

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();
    }
@mariotoffia mariotoffia self-assigned this Sep 24, 2022
@mariotoffia mariotoffia added this to the 3.0.0-RELEASE milestone Sep 24, 2022
@mariotoffia
Copy link
Owner

Hi @dil-bkis and thanks for your good bug report!

I'll add it to my TODO list.

Cheers,
Mario :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants