MCPcopy Index your code
hub / github.com/coder/envbox / ExtractClient

Function ExtractClient

dockerutil/client.go:32–48  ·  view source on GitHub ↗

ExtractClient returns the DockerClient set on the context. If one can't be found a default client is returned.

(ctx context.Context)

Source from the content-addressed store, hash-verified

30// ExtractClient returns the DockerClient set on the context. If one can't be
31// found a default client is returned.
32func ExtractClient(ctx context.Context) (Client, error) {
33 client := ctx.Value(clientKey{})
34 if client == nil {
35 client, err := dockerclient.NewClientWithOpts(
36 dockerclient.FromEnv,
37 dockerclient.WithAPIVersionNegotiation(), // use daemon's max API (e.g. 1.47) so we don't exceed it
38 )
39 if err != nil {
40 return nil, xerrors.Errorf("new env client: %w", err)
41 }
42
43 return client, nil
44 }
45
46 //nolint we should panic if this isn't the case.
47 return client.(Client), nil
48}
49
50type AuthConfig registry.AuthConfig
51

Callers 2

dockerCmdFunction · 0.92
DockerClientFunction · 0.92

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected