|
10 | 10 |
|
11 | 11 | import java.io.File; |
12 | 12 | import java.io.FileInputStream; |
13 | | -import java.io.IOException; |
14 | 13 | import java.io.InputStream; |
15 | 14 | import java.lang.reflect.Method; |
16 | 15 | import java.util.Collection; |
17 | 16 | import java.util.UUID; |
18 | 17 |
|
19 | 18 | import org.apache.commons.io.FileUtils; |
20 | 19 | import org.apache.commons.io.filefilter.TrueFileFilter; |
21 | | -import org.apache.commons.lang.StringUtils; |
22 | 20 | import org.testng.ITestResult; |
23 | 21 | import org.testng.annotations.AfterMethod; |
24 | 22 | import org.testng.annotations.AfterTest; |
|
31 | 29 | import com.github.dockerjava.api.command.CreateContainerResponse; |
32 | 30 | import com.github.dockerjava.api.command.InspectContainerResponse; |
33 | 31 | import com.github.dockerjava.api.command.InspectImageResponse; |
34 | | -import com.github.dockerjava.api.model.BuildResponseItem; |
| 32 | +import com.github.dockerjava.api.model.AuthConfig; |
| 33 | +import com.github.dockerjava.api.model.AuthConfigurations; |
| 34 | +import com.github.dockerjava.api.model.ExposedPort; |
| 35 | +import com.github.dockerjava.api.model.PortBinding; |
| 36 | +import com.github.dockerjava.api.model.Ports; |
35 | 37 | import com.github.dockerjava.client.AbstractDockerClientTest; |
36 | 38 | import com.github.dockerjava.core.CompressArchiveUtil; |
37 | 39 |
|
@@ -225,17 +227,61 @@ public void testAddAndCopySubstitution() throws Exception { |
225 | 227 | String response = dockerfileBuild(baseDir); |
226 | 228 | assertThat(response, containsString("testENVSubstitution successfully completed")); |
227 | 229 | } |
228 | | - |
| 230 | + |
229 | 231 | @Test |
230 | | - public void testBuilderPerformance() throws Exception { |
231 | | - File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("nginx").getFile()); |
| 232 | + public void testBuildFromPrivateRegistry() throws Exception { |
| 233 | + File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("privateRegistry").getFile()); |
232 | 234 |
|
233 | 235 | String imageId = buildImage(baseDir); |
234 | 236 |
|
235 | 237 | InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec(); |
236 | 238 | assertThat(inspectImageResponse, not(nullValue())); |
237 | 239 | LOG.info("Image Inspect: {}", inspectImageResponse.toString()); |
238 | 240 |
|
239 | | - assertThat(inspectImageResponse.getAuthor(), equalTo("Guillaume J. Charmes \"guillaume@dotcloud.com\"")); |
| 241 | + dockerClient.tagImageCmd(imageId, "testregistry", "2").withForce().exec(); |
| 242 | + |
| 243 | + // see https://github.com/docker/distribution/blob/master/docs/deploying.md#native-basic-auth |
| 244 | + CreateContainerResponse testregistry = dockerClient |
| 245 | + .createContainerCmd("testregistry:2") |
| 246 | + .withName("registry") |
| 247 | + .withPortBindings(new PortBinding(new Ports.Binding(5000), ExposedPort.tcp(5000))) |
| 248 | + .withEnv("REGISTRY_AUTH=htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm", |
| 249 | + "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_LOG_LEVEL=debug", |
| 250 | + "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key") |
| 251 | + .exec(); |
| 252 | + |
| 253 | + dockerClient.startContainerCmd(testregistry.getId()).exec(); |
| 254 | + |
| 255 | + AuthConfig authConfig = new AuthConfig(); |
| 256 | + |
| 257 | + // credentials as configured in /auth/htpasswd |
| 258 | + authConfig.setUsername("testuser"); |
| 259 | + authConfig.setPassword("testpassword"); |
| 260 | + authConfig.setEmail("foo@bar.de"); |
| 261 | + authConfig.setServerAddress("localhost:5000"); |
| 262 | + |
| 263 | + dockerClient.authCmd().withAuthConfig(authConfig).exec(); |
| 264 | + dockerClient.tagImageCmd("busybox:latest", "localhost:5000/testuser/busybox", "latest").withForce().exec(); |
| 265 | + |
| 266 | + dockerClient.pushImageCmd("localhost:5000/testuser/busybox").withTag("latest").withAuthConfig(authConfig) |
| 267 | + .exec(new PushImageResultCallback()).awaitSuccess(); |
| 268 | + |
| 269 | + dockerClient.removeImageCmd("busybox:latest").withForce().exec(); |
| 270 | + |
| 271 | + dockerClient.removeImageCmd("localhost:5000/testuser/busybox").withForce().exec(); |
| 272 | + |
| 273 | + baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testBuildFromPrivateRegistry") |
| 274 | + .getFile()); |
| 275 | + |
| 276 | + AuthConfigurations authConfigurations = new AuthConfigurations(); |
| 277 | + authConfigurations.addConfig(authConfig); |
| 278 | + |
| 279 | + imageId = dockerClient.buildImageCmd(baseDir).withNoCache().withBuildAuthConfigs(authConfigurations) |
| 280 | + .exec(new BuildImageResultCallback()).awaitImageId(); |
| 281 | + |
| 282 | + inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec(); |
| 283 | + assertThat(inspectImageResponse, not(nullValue())); |
| 284 | + LOG.info("Image Inspect: {}", inspectImageResponse.toString()); |
| 285 | + |
240 | 286 | } |
241 | 287 | } |
0 commit comments