feat(compose): implement InspectImage rpc with broadcast support

This commit is contained in:
Pavel Sviderski
2025-03-21 19:43:58 +10:00
parent 2ad098c612
commit 874af1ba10
4 changed files with 321 additions and 123 deletions
+28 -20
View File
@@ -72,10 +72,8 @@ func (c *Client) CreateContainer(
Name: name,
})
if err != nil {
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return resp, errdefs.NotFound(err)
}
if status.Convert(err).Code() == codes.NotFound {
return resp, errdefs.NotFound(err)
}
return resp, err
}
@@ -92,10 +90,8 @@ func (c *Client) InspectContainer(ctx context.Context, id string) (types.Contain
grpcResp, err := c.grpcClient.InspectContainer(ctx, &pb.InspectContainerRequest{Id: id})
if err != nil {
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return resp, errdefs.NotFound(err)
}
if status.Convert(err).Code() == codes.NotFound {
return resp, errdefs.NotFound(err)
}
return resp, err
}
@@ -118,10 +114,8 @@ func (c *Client) StartContainer(ctx context.Context, id string, opts container.S
Options: optsBytes,
})
if err != nil {
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return errdefs.NotFound(err)
}
if status.Convert(err).Code() == codes.NotFound {
return errdefs.NotFound(err)
}
}
return err
@@ -139,10 +133,8 @@ func (c *Client) StopContainer(ctx context.Context, id string, opts container.St
Options: optsBytes,
})
if err != nil {
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return errdefs.NotFound(err)
}
if status.Convert(err).Code() == codes.NotFound {
return errdefs.NotFound(err)
}
}
return err
@@ -191,10 +183,8 @@ func (c *Client) RemoveContainer(ctx context.Context, id string, opts container.
Options: optsBytes,
})
if err != nil {
if s, ok := status.FromError(err); ok {
if s.Code() == codes.NotFound {
return errdefs.NotFound(err)
}
if status.Convert(err).Code() == codes.NotFound {
return errdefs.NotFound(err)
}
}
return err
@@ -237,3 +227,21 @@ func (c *Client) PullImage(ctx context.Context, image string) (<-chan PullImageM
return ch, nil
}
// ImageInspect returns the image information for the given image ID.
func (c *Client) ImageInspect(ctx context.Context, id string) (types.ImageInspect, error) {
var resp types.ImageInspect
grpcResp, err := c.grpcClient.InspectImage(ctx, &pb.InspectImageRequest{id: id})
if err != nil {
if status.Convert(err).Code() == codes.NotFound {
return resp, errdefs.NotFound(err)
}
return resp, err
}
if err = json.Unmarshal(grpcResp.Response, &resp); err != nil {
return resp, fmt.Errorf("unmarshal gRPC response: %w", err)
}
return resp, nil
}