@@ -95,7 +95,7 @@ func TestPushArchs(t *testing.T) {
9595 t .Run (testCase .name , func (t * testing.T ) {
9696 cmd := info .configuredCmd
9797 ref := info .registryAddress + "/test/push-pull:1"
98- args := []string {"app" , "push" , "--tag" , ref , "--insecure-registries=" + info . registryAddress }
98+ args := []string {"app" , "push" , "--tag" , ref }
9999 args = append (args , testCase .args ... )
100100 args = append (args , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
101101 cmd .Command = dockerCli .Command (args ... )
@@ -121,14 +121,31 @@ func TestPushArchs(t *testing.T) {
121121 })
122122}
123123
124+ func TestPushInsecureRegistry (t * testing.T ) {
125+ runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
126+ ref := info .registryAddress + "/test/push-insecure"
127+
128+ // create a command outside of the dind context so without the insecure registry configured
129+ cmd2 , cleanup2 := dockerCli .createTestCmd ()
130+ defer cleanup2 ()
131+ cmd2 .Command = dockerCli .Command ("app" , "push" , "--tag" , ref , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
132+ icmd .RunCmd (cmd2 ).Assert (t , icmd.Expected {ExitCode : 1 })
133+
134+ // run the push with the command inside dind context configured to allow access to the insecure registry
135+ cmd := info .configuredCmd
136+ cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
137+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
138+ })
139+ }
140+
124141func TestPushInstall (t * testing.T ) {
125142 runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
126143 cmd := info .configuredCmd
127144 ref := info .registryAddress + "/test/push-pull"
128- cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref , "--insecure-registries=" + info . registryAddress , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
145+ cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
129146 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
130147
131- cmd .Command = dockerCli .Command ("app" , "install" , "--insecure-registries=" + info . registryAddress , ref , "--name" , t .Name ())
148+ cmd .Command = dockerCli .Command ("app" , "install" , ref , "--name" , t .Name ())
132149 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
133150 cmd .Command = dockerCli .Command ("service" , "ls" )
134151 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (), ref ))
@@ -140,16 +157,16 @@ func TestPushPullInstall(t *testing.T) {
140157 cmd := info .configuredCmd
141158 ref := info .registryAddress + "/test/push-pull"
142159 tag := ":v.0.0.1"
143- cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref + tag , "--insecure-registries=" + info . registryAddress , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
160+ cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref + tag , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
144161 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
145- cmd .Command = dockerCli .Command ("app" , "pull" , ref + tag , "--insecure-registries=" + info . registryAddress )
162+ cmd .Command = dockerCli .Command ("app" , "pull" , ref + tag )
146163 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
147164
148165 // stop the registry
149166 info .stopRegistry ()
150167
151168 // install without --pull should succeed (rely on local store)
152- cmd .Command = dockerCli .Command ("app" , "install" , "--insecure-registries=" + info . registryAddress , ref + tag , "--name" , t .Name ())
169+ cmd .Command = dockerCli .Command ("app" , "install" , ref + tag , "--name" , t .Name ())
153170 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
154171 cmd .Command = dockerCli .Command ("service" , "ls" )
155172 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (), ref ))
@@ -162,7 +179,7 @@ func TestPushPullInstall(t *testing.T) {
162179 })
163180
164181 // install with --pull should fail (registry is stopped)
165- cmd .Command = dockerCli .Command ("app" , "install" , "--pull" , "--insecure-registries=" + info . registryAddress , ref , "--name" , t .Name ()+ "2" )
182+ cmd .Command = dockerCli .Command ("app" , "install" , "--pull" , ref , "--name" , t .Name ()+ "2" )
166183 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 1 }).Combined (), "failed to resolve bundle manifest" ))
167184 })
168185}
@@ -183,10 +200,10 @@ func TestPushInstallBundle(t *testing.T) {
183200 // push it and install to check it is available
184201 t .Run ("push-bundle" , func (t * testing.T ) {
185202 name := strings .Replace (t .Name (), "/" , "_" , 1 )
186- cmd .Command = dockerCli .Command ("app" , "push" , "--insecure-registries=" + info . registryAddress , "-- tag" , ref , bundleFile )
203+ cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref , bundleFile )
187204 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
188205
189- cmd .Command = dockerCli .Command ("app" , "install" , "--insecure-registries=" + info . registryAddress , ref , "--name" , name )
206+ cmd .Command = dockerCli .Command ("app" , "install" , ref , "--name" , name )
190207 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
191208 cmd .Command = dockerCli .Command ("service" , "ls" )
192209 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (), ref ))
@@ -203,10 +220,10 @@ func TestPushInstallBundle(t *testing.T) {
203220 t .Run ("push-ref" , func (t * testing.T ) {
204221 name := strings .Replace (t .Name (), "/" , "_" , 1 )
205222 ref2 := info .registryAddress + "/test/push-ref"
206- cmd .Command = dockerCli .Command ("app" , "push" , "--insecure-registries=" + info . registryAddress , "-- tag" , ref2 , ref + ":latest" )
223+ cmd .Command = dockerCli .Command ("app" , "push" , "--tag" , ref2 , ref + ":latest" )
207224 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
208225
209- cmd .Command = dockerCli .Command ("app" , "install" , "--insecure-registries=" + info . registryAddress , ref2 , "--name" , name )
226+ cmd .Command = dockerCli .Command ("app" , "install" , ref2 , "--name" , name )
210227 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
211228 cmd .Command = dockerCli .Command ("service" , "ls" )
212229 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (), ref2 ))
@@ -218,16 +235,22 @@ func TestPushInstallBundle(t *testing.T) {
218235 ref2 := ref + ":v0.42"
219236 // Create a new command so the bundle store can be trashed before installing the app
220237 cmd2 , cleanup2 := dockerCli .createTestCmd ()
238+
239+ // Enter the same context as `cmd` to run commands within the same environment
240+ cmd2 .Command = dockerCli .Command ("context" , "create" , "swarm-context" , "--docker" , fmt .Sprintf (`"host=tcp://%s"` , info .swarmAddress ))
241+ icmd .RunCmd (cmd2 ).Assert (t , icmd .Success )
242+ cmd2 .Env = append (cmd2 .Env , "DOCKER_CONTEXT=swarm-context" )
243+
221244 // bundle the app again but this time with a tag to store it into the bundle store
222245 cmd2 .Command = dockerCli .Command ("app" , "bundle" , "--tag" , ref2 , "-o" , bundleFile , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ))
223246 icmd .RunCmd (cmd2 ).Assert (t , icmd .Success )
224247 // Push the app without tagging it explicitly
225- cmd2 .Command = dockerCli .Command ("app" , "push" , "--insecure-registries=" + info . registryAddress , ref2 )
248+ cmd2 .Command = dockerCli .Command ("app" , "push" , ref2 )
226249 icmd .RunCmd (cmd2 ).Assert (t , icmd .Success )
227250 // remove the bundle from the bundle store to be sure it won't be used instead of registry
228251 cleanup2 ()
229252 // install from the registry
230- cmd .Command = dockerCli .Command ("app" , "install" , "--insecure-registries=" + info . registryAddress , ref2 , "--name" , name )
253+ cmd .Command = dockerCli .Command ("app" , "install" , ref2 , "--name" , name )
231254 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
232255 cmd .Command = dockerCli .Command ("service" , "ls" )
233256 assert .Check (t , cmp .Contains (icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (), ref ))
0 commit comments