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

Consider using Docker.DotNet instead of docker cli #117

Open
paulomorgado opened this issue Sep 25, 2024 · 5 comments
Open

Consider using Docker.DotNet instead of docker cli #117

paulomorgado opened this issue Sep 25, 2024 · 5 comments

Comments

@paulomorgado
Copy link

Using Docker.DotNet.

Maybe this could be a different addin to not break anyone and allow incremental implementation of aliases.

I can contribute.

@MihaMarkic
Copy link
Owner

Does it offer full capability compared to cli commands?

@paulomorgado
Copy link
Author

It should, but, just in case, we could DockerApi for the alias and keep both.

@MihaMarkic
Copy link
Owner

OK, will take a look, it might take some time. Will let you know.

@paulomorgado
Copy link
Author

paulomorgado commented Sep 26, 2024

The one I have and am using is for docker image load.

But, in the usage I have, I already have the image loaded into a Stream. That could be the STDIN.

So we need to have two options for the image:

  • FilePath
  • Stream

Maybe we could have two overloads:

public static void DockerApiImageLoad(this ICakeContext context, FilePath image, DockerApiImageLoadSettings settings);
public static void DockerApiImageLoad(this ICakeContext context, Stream image, DockerApiImageLoadSettings settings);

/// <summary>
/// Settings for docker image load [OPTIONS].
/// Load an image from a tar archive file or stream
/// </summary>
public class DockerApiImageLoadSettings
{
	/// <summary>
	/// Gets or sets whether to suppress or not the load output.
	/// </summary>
        /// <value><see langword="true" /> to suppress load output; <see langword="false" /> to not suppress load output. Default is <see langword="false" />.
        /// <remarks>Same as command-line <c>--quiet</c>,<c>-q</c> option.</remarks>
	public bool Quiet { get; set; }
}

The invocation of the client would be something like:

await dockerClient.Images.LoadImageAsync(
    new ImageLoadParameters { Quiet = settings.Quiet },
    imageStream, // the provided stream or the stream from the provided file path.
    new Progress(context))
    .ConfigureAwait(ConfigureAwaitOptions.None);

private sealed class Progress(BuildContext context) : IProgress<JSONMessage>
{
    public void Report(JSONMessage value)
    {
        if (!string.IsNullOrEmpty(value.Stream))
        {
            context.Log.Information($"Stream: {value.Stream}");
        }

        if (!string.IsNullOrEmpty(value.Status))
        {
            context.Log.Information($"Status: {value.Status}");
        }

        if (value.Error is { } error)
        {
            context.Log.Error($"Error {error.Code}: {error.Message}");
            throw new Exception(error.Message);
        }

        if (!string.IsNullOrEmpty(value.ProgressMessage))
        {
            context.Log.Information($"Progress: {value.ProgressMessage}");
        }
    }
}

How's that for a start?

@MihaMarkic
Copy link
Owner

TBH I'm mulling an idea that cake addin is not even required with this library. One could reference Docker.DotNet directly and use it as it deems appropriate. Even more so because it's stateful. But let's take it slowly.

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

No branches or pull requests

2 participants