GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Narrow docker interface (#3650) · knative/func@0073591

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkg
    • buildpacks
      • builder.go
    • docker
      • close_guarding_client.go
      • docker_client.go
      • runner.go
      • zz_close_guarding_client_generated.go
    • s2i
      • builder.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkg/buildpacks/builder.go‎

Copy file name to clipboardExpand all lines: pkg/buildpacks/builder.go
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
261261
// (and update build opts as necessary)
262262
if impl == nil {
263263
var (
264-
cli client.APIClient
264+
cli docker.DockerClient
265265
dockerHost string
266266
)
267267

@@ -296,7 +296,7 @@ func (b *Builder) Build(ctx context.Context, f fn.Function, platforms []fn.Platf
296296
return
297297
}
298298

299-
func isPodmanV43(ctx context.Context, cli client.APIClient) (b bool, err error) {
299+
func isPodmanV43(ctx context.Context, cli docker.DockerClient) (b bool, err error) {
300300
version, err := cli.ServerVersion(ctx, client.ServerVersionOptions{})
301301
if err != nil {
302302
return
Collapse file

‎pkg/docker/close_guarding_client.go‎

Copy file name to clipboardExpand all lines: pkg/docker/close_guarding_client.go
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ package docker
22

33
import (
44
"sync"
5-
6-
"github.com/moby/moby/client"
75
)
86

9-
// Client that panics when used after Close()
7+
// closeGuardingClient wraps a DockerClient and panics if any method
8+
// is called after Close().
109
type closeGuardingClient struct {
11-
pimpl client.APIClient
10+
pimpl DockerClient
1211
m sync.RWMutex
1312
closed bool
1413
}
Collapse file

‎pkg/docker/docker_client.go‎

Copy file name to clipboardExpand all lines: pkg/docker/docker_client.go
+44-9Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package docker
22

33
import (
4+
"context"
45
"crypto/tls"
56
"crypto/x509"
67
"encoding/json"
@@ -19,12 +20,45 @@ import (
1920

2021
"github.com/docker/cli/cli/config"
2122
"github.com/docker/go-connections/tlsconfig"
23+
"github.com/google/go-containerregistry/pkg/v1/daemon"
2224
"github.com/moby/moby/client"
2325
"golang.org/x/crypto/ssh"
2426

2527
fnssh "knative.dev/func/pkg/ssh"
2628
)
2729

30+
// DockerClient is a subset of client.APIClient with only the methods
31+
// needed by this project and its third-party integrations (pack, s2i).
32+
type DockerClient interface {
33+
daemon.Client // Ping, ImageSave, ImageLoad, ImageTag, ImageInspect, ImageHistory
34+
35+
ContainerAttach(ctx context.Context, container string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error)
36+
ContainerCommit(ctx context.Context, container string, options client.ContainerCommitOptions) (client.ContainerCommitResult, error)
37+
ContainerCreate(ctx context.Context, options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
38+
ContainerInspect(ctx context.Context, containerID string, options client.ContainerInspectOptions) (client.ContainerInspectResult, error)
39+
ContainerKill(ctx context.Context, containerID string, options client.ContainerKillOptions) (client.ContainerKillResult, error)
40+
ContainerRemove(ctx context.Context, container string, options client.ContainerRemoveOptions) (client.ContainerRemoveResult, error)
41+
ContainerStart(ctx context.Context, container string, options client.ContainerStartOptions) (client.ContainerStartResult, error)
42+
ContainerStop(ctx context.Context, containerID string, options client.ContainerStopOptions) (client.ContainerStopResult, error)
43+
ContainerWait(ctx context.Context, containerID string, options client.ContainerWaitOptions) client.ContainerWaitResult
44+
CopyFromContainer(ctx context.Context, containerID string, options client.CopyFromContainerOptions) (client.CopyFromContainerResult, error)
45+
CopyToContainer(ctx context.Context, container string, options client.CopyToContainerOptions) (client.CopyToContainerResult, error)
46+
47+
ImageBuild(ctx context.Context, buildContext io.Reader, options client.ImageBuildOptions) (client.ImageBuildResult, error)
48+
ImagePull(ctx context.Context, ref string, options client.ImagePullOptions) (client.ImagePullResponse, error)
49+
ImagePush(ctx context.Context, ref string, options client.ImagePushOptions) (client.ImagePushResponse, error)
50+
ImageRemove(ctx context.Context, image string, options client.ImageRemoveOptions) (client.ImageRemoveResult, error)
51+
52+
Info(ctx context.Context, options client.InfoOptions) (client.SystemInfoResult, error)
53+
NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error)
54+
NetworkRemove(ctx context.Context, networkID string, options client.NetworkRemoveOptions) (client.NetworkRemoveResult, error)
55+
ServerVersion(ctx context.Context, options client.ServerVersionOptions) (client.ServerVersionResult, error)
56+
VolumeList(ctx context.Context, options client.VolumeListOptions) (client.VolumeListResult, error)
57+
VolumeRemove(ctx context.Context, volumeID string, options client.VolumeRemoveOptions) (client.VolumeRemoveResult, error)
58+
59+
Close() error
60+
}
61+
2862
var ErrNoDocker = errors.New("docker/podman API not available")
2963

3064
// NewClient creates a new docker client.
@@ -35,10 +69,11 @@ var ErrNoDocker = errors.New("docker/podman API not available")
3569
// - For TCP connections it returns "" so it defaults in the remote (note that
3670
// one should not be use client.DefaultDockerHost in this situation). This is
3771
// needed beaus of TCP+tls connections.
38-
func NewClient(defaultHost string) (dockerClient client.APIClient, dockerHostInRemote string, err error) {
72+
func NewClient(defaultHost string) (dc DockerClient, dockerHostInRemote string, err error) {
73+
var rawClient client.APIClient
3974
defer func() {
40-
if dockerClient != nil && err == nil {
41-
dockerClient = &closeGuardingClient{pimpl: dockerClient}
75+
if rawClient != nil && err == nil {
76+
dc = &closeGuardingClient{pimpl: rawClient}
4277
}
4378
}()
4479

@@ -62,7 +97,7 @@ func NewClient(defaultHost string) (dockerClient client.APIClient, dockerHostInR
6297
case os.IsNotExist(err) && podmanPresent():
6398
if runtime.GOOS == "linux" {
6499
// on Linux: spawn temporary podman service
65-
dockerClient, dockerHostInRemote, err = newClientWithPodmanService()
100+
rawClient, dockerHostInRemote, err = newClientWithPodmanService()
66101
return
67102
} else {
68103
// on non-Linux: try to use connection to podman machine
@@ -109,7 +144,7 @@ func NewClient(defaultHost string) (dockerClient client.APIClient, dockerHostInR
109144
opts = append(opts, client.WithHTTPClient(httpClient))
110145
}
111146
}
112-
dockerClient, err = client.New(opts...)
147+
rawClient, err = client.New(opts...)
113148
return
114149
}
115150

@@ -133,19 +168,19 @@ func NewClient(defaultHost string) (dockerClient client.APIClient, dockerHostInR
133168
},
134169
}
135170

136-
dockerClient, err = client.New(
171+
rawClient, err = client.New(
137172
client.WithHTTPClient(httpClient))
138173

139174
if closer, ok := contextDialer.(io.Closer); ok {
140-
dockerClient = clientWithAdditionalCleanup{
141-
APIClient: dockerClient,
175+
rawClient = clientWithAdditionalCleanup{
176+
APIClient: rawClient,
142177
cleanUp: func() {
143178
closer.Close()
144179
},
145180
}
146181
}
147182

148-
return dockerClient, dockerHostInRemote, err
183+
return dc, dockerHostInRemote, err
149184
}
150185

151186
// If the DOCKER_TLS_VERIFY environment variable is set
Collapse file

‎pkg/docker/runner.go‎

Copy file name to clipboardExpand all lines: pkg/docker/runner.go
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, address string, startTi
6161
var (
6262
host = DefaultHost
6363
port = DefaultPort
64-
c client.APIClient // Docker client
65-
id string // ID of running container
66-
conn net.Conn // Connection to container's stdio
64+
c DockerClient // Docker client
65+
id string // ID of running container
66+
conn net.Conn // Connection to container's stdio
6767

6868
// Channels for gathering runtime errors from the container instance
6969
copyErrCh = make(chan error, 10)
@@ -254,7 +254,7 @@ func choosePort(host, preferredPort string, dialTimeout time.Duration) string {
254254

255255
}
256256

257-
func newContainer(ctx context.Context, c client.APIClient, f fn.Function, host, port string, verbose bool) (id string, err error) {
257+
func newContainer(ctx context.Context, c DockerClient, f fn.Function, host, port string, verbose bool) (id string, err error) {
258258
var (
259259
containerCfg container.Config
260260
hostCfg container.HostConfig
@@ -322,7 +322,7 @@ func newHostConfig(host, port string) (c container.HostConfig, err error) {
322322

323323
// copy stdin and stdout from the container of the given ID. Errors encountered
324324
// during copy are communicated via a provided errs channel.
325-
func copyStdio(ctx context.Context, c client.APIClient, id string, errs chan error, out, errOut io.Writer) (conn net.Conn, err error) {
325+
func copyStdio(ctx context.Context, c DockerClient, id string, errs chan error, out, errOut io.Writer) (conn net.Conn, err error) {
326326
res, err := c.ContainerAttach(ctx, id, client.ContainerAttachOptions{
327327
Stdout: true,
328328
Stderr: true,

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.