Skip to content

Commit d7ba1f8

Browse files
committed
Use containerd dist libs for plugin pull/pull
This removes the use of the old distribution code in the plugin packages and replaces it with containerd libraries for plugin pushes and pulls. Additionally it uses a content store from containerd which seems like it's compatible with the old "basicBlobStore" in the plugin package. This is being used locally isntead of through the containerd client for now. Signed-off-by: Brian Goff <[email protected]>
1 parent af04152 commit d7ba1f8

File tree

13 files changed

+911
-525
lines changed

13 files changed

+911
-525
lines changed

integration/plugin/common/main_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import (
55
"os"
66
"testing"
77

8+
"github.com/docker/docker/pkg/reexec"
89
"github.com/docker/docker/testutil/environment"
910
)
1011

1112
var testEnv *environment.Execution
1213

1314
func TestMain(m *testing.M) {
15+
if reexec.Init() {
16+
return
17+
}
1418
var err error
1519
testEnv, err = environment.New()
1620
if err != nil {

integration/plugin/common/plugin_test.go

+121
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
package common // import "github.com/docker/docker/integration/plugin/common"
22

33
import (
4+
"context"
5+
"encoding/base64"
6+
"encoding/json"
7+
"io"
8+
"io/ioutil"
9+
"net"
410
"net/http"
11+
"path"
12+
"strings"
513
"testing"
614

15+
"github.com/docker/docker/api/types"
16+
"github.com/docker/docker/testutil/daemon"
17+
"github.com/docker/docker/testutil/fixtures/plugin"
18+
"github.com/docker/docker/testutil/registry"
719
"github.com/docker/docker/testutil/request"
820
"gotest.tools/v3/assert"
921
is "gotest.tools/v3/assert/cmp"
22+
"gotest.tools/v3/skip"
1023
)
1124

1225
func TestPluginInvalidJSON(t *testing.T) {
@@ -36,3 +49,111 @@ func TestPluginInvalidJSON(t *testing.T) {
3649
})
3750
}
3851
}
52+
53+
func TestPluginInstall(t *testing.T) {
54+
skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
55+
skip.If(t, testEnv.OSType == "windows")
56+
skip.If(t, testEnv.IsRootless, "rootless mode has different view of localhost")
57+
58+
ctx := context.Background()
59+
client := testEnv.APIClient()
60+
61+
t.Run("no auth", func(t *testing.T) {
62+
defer setupTest(t)()
63+
64+
reg := registry.NewV2(t)
65+
defer reg.Close()
66+
67+
name := "test-" + strings.ToLower(t.Name())
68+
repo := path.Join(registry.DefaultURL, name+":latest")
69+
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, nil))
70+
71+
rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{Disabled: true, RemoteRef: repo})
72+
assert.NilError(t, err)
73+
defer rdr.Close()
74+
75+
_, err = io.Copy(ioutil.Discard, rdr)
76+
assert.NilError(t, err)
77+
78+
_, _, err = client.PluginInspectWithRaw(ctx, repo)
79+
assert.NilError(t, err)
80+
})
81+
82+
t.Run("with htpasswd", func(t *testing.T) {
83+
defer setupTest(t)()
84+
85+
reg := registry.NewV2(t, registry.Htpasswd)
86+
defer reg.Close()
87+
88+
name := "test-" + strings.ToLower(t.Name())
89+
repo := path.Join(registry.DefaultURL, name+":latest")
90+
auth := &types.AuthConfig{ServerAddress: registry.DefaultURL, Username: "testuser", Password: "testpassword"}
91+
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, auth))
92+
93+
authEncoded, err := json.Marshal(auth)
94+
assert.NilError(t, err)
95+
96+
rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{
97+
RegistryAuth: base64.URLEncoding.EncodeToString(authEncoded),
98+
Disabled: true,
99+
RemoteRef: repo,
100+
})
101+
assert.NilError(t, err)
102+
defer rdr.Close()
103+
104+
_, err = io.Copy(ioutil.Discard, rdr)
105+
assert.NilError(t, err)
106+
107+
_, _, err = client.PluginInspectWithRaw(ctx, repo)
108+
assert.NilError(t, err)
109+
})
110+
t.Run("with insecure", func(t *testing.T) {
111+
skip.If(t, !testEnv.IsLocalDaemon())
112+
113+
addrs, err := net.InterfaceAddrs()
114+
assert.NilError(t, err)
115+
116+
var bindTo string
117+
for _, addr := range addrs {
118+
ip, ok := addr.(*net.IPNet)
119+
if !ok {
120+
continue
121+
}
122+
if ip.IP.IsLoopback() || ip.IP.To4() == nil {
123+
continue
124+
}
125+
bindTo = ip.IP.String()
126+
}
127+
128+
if bindTo == "" {
129+
t.Skip("No suitable interface to bind registry to")
130+
}
131+
132+
regURL := bindTo + ":5000"
133+
134+
d := daemon.New(t)
135+
defer d.Stop(t)
136+
137+
d.Start(t, "--insecure-registry="+regURL)
138+
defer d.Stop(t)
139+
140+
reg := registry.NewV2(t, registry.URL(regURL))
141+
defer reg.Close()
142+
143+
name := "test-" + strings.ToLower(t.Name())
144+
repo := path.Join(regURL, name+":latest")
145+
assert.NilError(t, plugin.CreateInRegistry(ctx, repo, nil, plugin.WithInsecureRegistry(regURL)))
146+
147+
client := d.NewClientT(t)
148+
rdr, err := client.PluginInstall(ctx, repo, types.PluginInstallOptions{Disabled: true, RemoteRef: repo})
149+
assert.NilError(t, err)
150+
defer rdr.Close()
151+
152+
_, err = io.Copy(ioutil.Discard, rdr)
153+
assert.NilError(t, err)
154+
155+
_, _, err = client.PluginInspectWithRaw(ctx, repo)
156+
assert.NilError(t, err)
157+
})
158+
// TODO: test insecure registry with https
159+
}

0 commit comments

Comments
 (0)