integration-cli: don't build -test images if they already exist
| ... | ... |
@@ -801,7 +801,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName |
| 801 | 801 |
return nil |
| 802 | 802 |
} |
| 803 | 803 |
|
| 804 |
-func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error { // nolint: interfacer
|
|
| 804 |
+func updateJoinInfo(networkSettings *network.Settings, n libnetwork.Network, ep libnetwork.Endpoint) error {
|
|
| 805 | 805 |
if ep == nil {
|
| 806 | 806 |
return errors.New("invalid enppoint whhile building portmap info")
|
| 807 | 807 |
} |
| ... | ... |
@@ -143,7 +143,7 @@ type metricsPlugin interface {
|
| 143 | 143 |
StopMetrics() error |
| 144 | 144 |
} |
| 145 | 145 |
|
| 146 |
-func makePluginAdapter(p plugingetter.CompatPlugin) (metricsPlugin, error) { // nolint: interfacer
|
|
| 146 |
+func makePluginAdapter(p plugingetter.CompatPlugin) (metricsPlugin, error) {
|
|
| 147 | 147 |
if pc, ok := p.(plugingetter.PluginWithV1Client); ok {
|
| 148 | 148 |
return &metricsPluginAdapter{pc.Client(), p.Name()}, nil
|
| 149 | 149 |
} |
| ... | ... |
@@ -13,7 +13,6 @@ import ( |
| 13 | 13 |
"time" |
| 14 | 14 |
|
| 15 | 15 |
"github.com/docker/distribution/reference" |
| 16 |
- "github.com/docker/distribution/registry/client/auth" |
|
| 17 | 16 |
"github.com/docker/distribution/registry/client/transport" |
| 18 | 17 |
"github.com/docker/docker/distribution/metadata" |
| 19 | 18 |
"github.com/docker/docker/distribution/xfer" |
| ... | ... |
@@ -70,9 +69,7 @@ func (p *v1Puller) Pull(ctx context.Context, ref reference.Named, _ *specs.Platf |
| 70 | 70 |
return nil |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
-// Note use auth.Scope rather than reference.Named due to this warning causing Jenkins CI to fail: |
|
| 74 |
-// warning: ref can be github.com/docker/docker/vendor/github.com/docker/distribution/registry/client/auth.Scope (interfacer) |
|
| 75 |
-func (p *v1Puller) pullRepository(ctx context.Context, ref auth.Scope) error {
|
|
| 73 |
+func (p *v1Puller) pullRepository(ctx context.Context, ref reference.Named) error {
|
|
| 76 | 74 |
progress.Message(p.config.ProgressOutput, "", "Pulling repository "+p.repoInfo.Name.Name()) |
| 77 | 75 |
|
| 78 | 76 |
tagged, isTagged := ref.(reference.NamedTagged) |
| ... | ... |
@@ -649,7 +649,6 @@ func (bla byLikeness) Swap(i, j int) {
|
| 649 | 649 |
} |
| 650 | 650 |
func (bla byLikeness) Len() int { return len(bla.arr) }
|
| 651 | 651 |
|
| 652 |
-// nolint: interfacer |
|
| 653 | 652 |
func sortV2MetadataByLikenessAndAge(repoInfo reference.Named, hmacKey []byte, marr []metadata.V2Metadata) {
|
| 654 | 653 |
// reverse the metadata array to shift the newest entries to the beginning |
| 655 | 654 |
for i := 0; i < len(marr)/2; i++ {
|
| ... | ... |
@@ -8,7 +8,6 @@ import ( |
| 8 | 8 |
"path/filepath" |
| 9 | 9 |
"runtime" |
| 10 | 10 |
"strings" |
| 11 |
- "sync" |
|
| 12 | 11 |
|
| 13 | 12 |
"github.com/docker/docker/integration-cli/checker" |
| 14 | 13 |
"github.com/docker/docker/internal/test/fixtures/load" |
| ... | ... |
@@ -24,17 +23,13 @@ type logT interface {
|
| 24 | 24 |
Logf(string, ...interface{})
|
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 |
-var ensureSyscallTestOnce sync.Once |
|
| 28 |
- |
|
| 29 | 27 |
func ensureSyscallTest(c *check.C) {
|
| 30 |
- var doIt bool |
|
| 31 |
- ensureSyscallTestOnce.Do(func() {
|
|
| 32 |
- doIt = true |
|
| 33 |
- }) |
|
| 34 |
- if !doIt {
|
|
| 28 |
+ defer testEnv.ProtectImage(c, "syscall-test:latest") |
|
| 29 |
+ |
|
| 30 |
+ // If the image already exists, there's nothing left to do. |
|
| 31 |
+ if testEnv.HasExistingImage(c, "syscall-test:latest") {
|
|
| 35 | 32 |
return |
| 36 | 33 |
} |
| 37 |
- defer testEnv.ProtectImage(c, "syscall-test:latest") |
|
| 38 | 34 |
|
| 39 | 35 |
// if no match, must build in docker, which is significantly slower |
| 40 | 36 |
// (slower mostly because of the vfs graphdriver) |
| ... | ... |
@@ -93,6 +88,14 @@ func ensureSyscallTestBuild(c *check.C) {
|
| 93 | 93 |
|
| 94 | 94 |
func ensureNNPTest(c *check.C) {
|
| 95 | 95 |
defer testEnv.ProtectImage(c, "nnp-test:latest") |
| 96 |
+ |
|
| 97 |
+ // If the image already exists, there's nothing left to do. |
|
| 98 |
+ if testEnv.HasExistingImage(c, "nnp-test:latest") {
|
|
| 99 |
+ return |
|
| 100 |
+ } |
|
| 101 |
+ |
|
| 102 |
+ // if no match, must build in docker, which is significantly slower |
|
| 103 |
+ // (slower mostly because of the vfs graphdriver) |
|
| 96 | 104 |
if testEnv.OSType != runtime.GOOS {
|
| 97 | 105 |
ensureNNPTestBuild(c) |
| 98 | 106 |
return |
| ... | ... |
@@ -12,16 +12,6 @@ import ( |
| 12 | 12 |
"gotest.tools/assert" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
-type testingT interface {
|
|
| 16 |
- assert.TestingT |
|
| 17 |
- logT |
|
| 18 |
- Fatalf(string, ...interface{})
|
|
| 19 |
-} |
|
| 20 |
- |
|
| 21 |
-type logT interface {
|
|
| 22 |
- Logf(string, ...interface{})
|
|
| 23 |
-} |
|
| 24 |
- |
|
| 25 | 15 |
// Clean the environment, preserving protected objects (images, containers, ...) |
| 26 | 16 |
// and removing everything else. It's meant to run after any tests so that they don't |
| 27 | 17 |
// depend on each others. |
| ... | ... |
@@ -8,9 +8,12 @@ import ( |
| 8 | 8 |
"strings" |
| 9 | 9 |
|
| 10 | 10 |
"github.com/docker/docker/api/types" |
| 11 |
+ "github.com/docker/docker/api/types/filters" |
|
| 11 | 12 |
"github.com/docker/docker/client" |
| 13 |
+ "github.com/docker/docker/internal/test" |
|
| 12 | 14 |
"github.com/docker/docker/internal/test/fixtures/load" |
| 13 | 15 |
"github.com/pkg/errors" |
| 16 |
+ "gotest.tools/assert" |
|
| 14 | 17 |
) |
| 15 | 18 |
|
| 16 | 19 |
// Execution contains information about the current test execution and daemon |
| ... | ... |
@@ -151,6 +154,26 @@ func (e *Execution) IsUserNamespace() bool {
|
| 151 | 151 |
return root != "" |
| 152 | 152 |
} |
| 153 | 153 |
|
| 154 |
+// HasExistingImage checks whether there is an image with the given reference. |
|
| 155 |
+// Note that this is done by filtering and then checking whether there were any |
|
| 156 |
+// results -- so ambiguous references might result in false-positives. |
|
| 157 |
+func (e *Execution) HasExistingImage(t assert.TestingT, reference string) bool {
|
|
| 158 |
+ if ht, ok := t.(test.HelperT); ok {
|
|
| 159 |
+ ht.Helper() |
|
| 160 |
+ } |
|
| 161 |
+ client := e.APIClient() |
|
| 162 |
+ filter := filters.NewArgs() |
|
| 163 |
+ filter.Add("dangling", "false")
|
|
| 164 |
+ filter.Add("reference", reference)
|
|
| 165 |
+ imageList, err := client.ImageList(context.Background(), types.ImageListOptions{
|
|
| 166 |
+ All: true, |
|
| 167 |
+ Filters: filter, |
|
| 168 |
+ }) |
|
| 169 |
+ assert.NilError(t, err, "failed to list images") |
|
| 170 |
+ |
|
| 171 |
+ return len(imageList) > 0 |
|
| 172 |
+} |
|
| 173 |
+ |
|
| 154 | 174 |
// EnsureFrozenImagesLinux loads frozen test images into the daemon |
| 155 | 175 |
// if they aren't already loaded |
| 156 | 176 |
func EnsureFrozenImagesLinux(testEnv *Execution) error {
|
| ... | ... |
@@ -33,7 +33,7 @@ func newProtectedElements() protectedElements {
|
| 33 | 33 |
// ProtectAll protects the existing environment (containers, images, networks, |
| 34 | 34 |
// volumes, and, on Linux, plugins) from being cleaned up at the end of test |
| 35 | 35 |
// runs |
| 36 |
-func ProtectAll(t testingT, testEnv *Execution) {
|
|
| 36 |
+func ProtectAll(t assert.TestingT, testEnv *Execution) {
|
|
| 37 | 37 |
if ht, ok := t.(test.HelperT); ok {
|
| 38 | 38 |
ht.Helper() |
| 39 | 39 |
} |
| ... | ... |
@@ -48,7 +48,7 @@ func ProtectAll(t testingT, testEnv *Execution) {
|
| 48 | 48 |
|
| 49 | 49 |
// ProtectContainer adds the specified container(s) to be protected in case of |
| 50 | 50 |
// clean |
| 51 |
-func (e *Execution) ProtectContainer(t testingT, containers ...string) {
|
|
| 51 |
+func (e *Execution) ProtectContainer(t assert.TestingT, containers ...string) {
|
|
| 52 | 52 |
if ht, ok := t.(test.HelperT); ok {
|
| 53 | 53 |
ht.Helper() |
| 54 | 54 |
} |
| ... | ... |
@@ -59,7 +59,7 @@ func (e *Execution) ProtectContainer(t testingT, containers ...string) {
|
| 59 | 59 |
|
| 60 | 60 |
// ProtectContainers protects existing containers from being cleaned up at the |
| 61 | 61 |
// end of test runs |
| 62 |
-func ProtectContainers(t testingT, testEnv *Execution) {
|
|
| 62 |
+func ProtectContainers(t assert.TestingT, testEnv *Execution) {
|
|
| 63 | 63 |
if ht, ok := t.(test.HelperT); ok {
|
| 64 | 64 |
ht.Helper() |
| 65 | 65 |
} |
| ... | ... |
@@ -85,7 +85,7 @@ func getExistingContainers(t assert.TestingT, testEnv *Execution) []string {
|
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
// ProtectImage adds the specified image(s) to be protected in case of clean |
| 88 |
-func (e *Execution) ProtectImage(t testingT, images ...string) {
|
|
| 88 |
+func (e *Execution) ProtectImage(t assert.TestingT, images ...string) {
|
|
| 89 | 89 |
if ht, ok := t.(test.HelperT); ok {
|
| 90 | 90 |
ht.Helper() |
| 91 | 91 |
} |
| ... | ... |
@@ -96,7 +96,7 @@ func (e *Execution) ProtectImage(t testingT, images ...string) {
|
| 96 | 96 |
|
| 97 | 97 |
// ProtectImages protects existing images and on linux frozen images from being |
| 98 | 98 |
// cleaned up at the end of test runs |
| 99 |
-func ProtectImages(t testingT, testEnv *Execution) {
|
|
| 99 |
+func ProtectImages(t assert.TestingT, testEnv *Execution) {
|
|
| 100 | 100 |
if ht, ok := t.(test.HelperT); ok {
|
| 101 | 101 |
ht.Helper() |
| 102 | 102 |
} |
| ... | ... |
@@ -145,7 +145,7 @@ func tagsFromImageSummary(image types.ImageSummary) []string {
|
| 145 | 145 |
|
| 146 | 146 |
// ProtectNetwork adds the specified network(s) to be protected in case of |
| 147 | 147 |
// clean |
| 148 |
-func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
|
| 148 |
+func (e *Execution) ProtectNetwork(t assert.TestingT, networks ...string) {
|
|
| 149 | 149 |
if ht, ok := t.(test.HelperT); ok {
|
| 150 | 150 |
ht.Helper() |
| 151 | 151 |
} |
| ... | ... |
@@ -156,7 +156,7 @@ func (e *Execution) ProtectNetwork(t testingT, networks ...string) {
|
| 156 | 156 |
|
| 157 | 157 |
// ProtectNetworks protects existing networks from being cleaned up at the end |
| 158 | 158 |
// of test runs |
| 159 |
-func ProtectNetworks(t testingT, testEnv *Execution) {
|
|
| 159 |
+func ProtectNetworks(t assert.TestingT, testEnv *Execution) {
|
|
| 160 | 160 |
if ht, ok := t.(test.HelperT); ok {
|
| 161 | 161 |
ht.Helper() |
| 162 | 162 |
} |
| ... | ... |
@@ -180,7 +180,7 @@ func getExistingNetworks(t assert.TestingT, testEnv *Execution) []string {
|
| 180 | 180 |
} |
| 181 | 181 |
|
| 182 | 182 |
// ProtectPlugin adds the specified plugin(s) to be protected in case of clean |
| 183 |
-func (e *Execution) ProtectPlugin(t testingT, plugins ...string) {
|
|
| 183 |
+func (e *Execution) ProtectPlugin(t assert.TestingT, plugins ...string) {
|
|
| 184 | 184 |
if ht, ok := t.(test.HelperT); ok {
|
| 185 | 185 |
ht.Helper() |
| 186 | 186 |
} |
| ... | ... |
@@ -191,7 +191,7 @@ func (e *Execution) ProtectPlugin(t testingT, plugins ...string) {
|
| 191 | 191 |
|
| 192 | 192 |
// ProtectPlugins protects existing plugins from being cleaned up at the end of |
| 193 | 193 |
// test runs |
| 194 |
-func ProtectPlugins(t testingT, testEnv *Execution) {
|
|
| 194 |
+func ProtectPlugins(t assert.TestingT, testEnv *Execution) {
|
|
| 195 | 195 |
if ht, ok := t.(test.HelperT); ok {
|
| 196 | 196 |
ht.Helper() |
| 197 | 197 |
} |
| ... | ... |
@@ -219,7 +219,7 @@ func getExistingPlugins(t assert.TestingT, testEnv *Execution) []string {
|
| 219 | 219 |
} |
| 220 | 220 |
|
| 221 | 221 |
// ProtectVolume adds the specified volume(s) to be protected in case of clean |
| 222 |
-func (e *Execution) ProtectVolume(t testingT, volumes ...string) {
|
|
| 222 |
+func (e *Execution) ProtectVolume(t assert.TestingT, volumes ...string) {
|
|
| 223 | 223 |
if ht, ok := t.(test.HelperT); ok {
|
| 224 | 224 |
ht.Helper() |
| 225 | 225 |
} |
| ... | ... |
@@ -230,7 +230,7 @@ func (e *Execution) ProtectVolume(t testingT, volumes ...string) {
|
| 230 | 230 |
|
| 231 | 231 |
// ProtectVolumes protects existing volumes from being cleaned up at the end of |
| 232 | 232 |
// test runs |
| 233 |
-func ProtectVolumes(t testingT, testEnv *Execution) {
|
|
| 233 |
+func ProtectVolumes(t assert.TestingT, testEnv *Execution) {
|
|
| 234 | 234 |
if ht, ok := t.(test.HelperT); ok {
|
| 235 | 235 |
ht.Helper() |
| 236 | 236 |
} |
| ... | ... |
@@ -248,7 +248,6 @@ func (err PingResponseError) Error() string {
|
| 248 | 248 |
// challenge manager for the supported authentication types and |
| 249 | 249 |
// whether v2 was confirmed by the response. If a response is received but |
| 250 | 250 |
// cannot be interpreted a PingResponseError will be returned. |
| 251 |
-// nolint: interfacer |
|
| 252 | 251 |
func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.Manager, bool, error) {
|
| 253 | 252 |
var ( |
| 254 | 253 |
foundV2 = false |