Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static KeyStore createKeyStore(final String dockerCertPath) throws NoSuch
keyStore.load(null);

keyStore.setKeyEntry("docker", keyPair.getPrivate(), "docker".toCharArray(),
privateCertificates.toArray(new Certificate[privateCertificates.size()]) );
privateCertificates.toArray(new Certificate[privateCertificates.size()]));
return keyStore;
}

Expand Down Expand Up @@ -82,7 +82,8 @@ public static KeyStore createTrustStore(final String dockerCertPath) throws IOEx

}

private static List<Certificate> loadCertificates(final String dockerCertPath) throws IOException, CertificateException {
private static List<Certificate> loadCertificates(final String dockerCertPath) throws IOException,
CertificateException {
File certificate = new File(dockerCertPath, "cert.pem");
BufferedReader reader = new BufferedReader(new FileReader(certificate));
PEMParser pemParser = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static File archiveTARFiles(File base, Iterable<File> files, String archi
throws IOException {
File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
tarFile.deleteOnExit();
try(TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(
new BufferedOutputStream(new FileOutputStream(tarFile))))) {
try (TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(
new FileOutputStream(tarFile))))) {
tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
for (File file : files) {
TarArchiveEntry tarEntry = new TarArchiveEntry(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie

for (String key : new String[] { DOCKER_IO_URL_PROPERTY, DOCKER_IO_VERSION_PROPERTY,
DOCKER_IO_USERNAME_PROPERTY, DOCKER_IO_PASSWORD_PROPERTY, DOCKER_IO_EMAIL_PROPERTY,
DOCKER_IO_SERVER_ADDRESS_PROPERTY,
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CFG_PATH_PROPERTY, }) {
DOCKER_IO_SERVER_ADDRESS_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY,
DOCKER_IO_DOCKER_CFG_PATH_PROPERTY, }) {
if (systemProperties.containsKey(key)) {
overriddenProperties.setProperty(key, systemProperties.getProperty(key));
}
Expand Down Expand Up @@ -337,8 +337,7 @@ public int hashCode() {
public String toString() {
return "DockerClientConfig{" + "uri=" + uri + ", version='" + version + '\'' + ", username='" + username + '\''
+ ", password='" + password + '\'' + ", email='" + email + '\'' + ", serverAddress='" + serverAddress
+ '\'' + ", dockerCfgPath='" + dockerCfgPath + '\'' + ", sslConfig='" + sslConfig + '\''
+ '}';
+ '\'' + ", dockerCfgPath='" + dockerCfgPath + '\'' + ", sslConfig='" + sslConfig + '\'' + '}';
}

public static class DockerClientConfigBuilder {
Expand Down Expand Up @@ -415,7 +414,7 @@ public final DockerClientConfigBuilder withSSLConfig(SSLConfig config) {

public DockerClientConfig build() {
return new DockerClientConfig(uri, version, username, password, email, serverAddress, dockerCfgPath,
sslConfig);
sslConfig);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public void onStart(Closeable stream) {

@Override
public void onError(Throwable throwable) {
if(closed) return;
if (closed)
return;

try {
LOGGER.error("Error during callback", throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected String registryAuth(AuthConfig authConfig) {

protected String registryConfigs(AuthConfigurations authConfigs) {
try {
return Base64.encodeBase64String(new ObjectMapper().writeValueAsString(authConfigs).getBytes());
String json = new ObjectMapper().writeValueAsString(authConfigs.getConfigs());
return Base64.encodeBase64String(json.getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public void init(DockerClientConfig dockerClientConfig) {

if (clientRequestFilters != null) {
for (ClientRequestFilter clientRequestFilter : clientRequestFilters) {
if(clientRequestFilter != null)
clientConfig.register(clientRequestFilter);
if (clientRequestFilter != null)
clientConfig.register(clientRequestFilter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static void assertContainerHasVolumes(InspectContainerResponse inspectCon
}

protected String containerLog(String containerId) throws Exception {
return dockerClient.logContainerCmd(containerId).withStdOut()
.exec(new LogContainerTestCallback()).awaitCompletion().toString();
return dockerClient.logContainerCmd(containerId).withStdOut().exec(new LogContainerTestCallback())
.awaitCompletion().toString();
}

public static class LogContainerTestCallback extends LogContainerResultCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DockerClientImplTest {
@Test
public void configuredInstanceAuthConfig() throws Exception {
// given a config with null serverAddress
DockerClientConfig dockerClientConfig = new DockerClientConfig(null, null, "", "", "", null, null,null);
DockerClientConfig dockerClientConfig = new DockerClientConfig(null, null, "", "", "", null, null, null);
DockerClientImpl dockerClient = DockerClientImpl.getInstance(dockerClientConfig);

// when we get the auth config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void onNext(Frame frame) {
};
};

dockerClient.attachContainerCmd(container.getId()).withStdErr().withStdOut().withFollowStream()
.exec(callback).awaitCompletion(15, TimeUnit.SECONDS).close();
dockerClient.attachContainerCmd(container.getId()).withStdErr().withStdOut().withFollowStream().exec(callback)
.awaitCompletion(15, TimeUnit.SECONDS).close();

System.out.println("log: " + callback.toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.lang.StringUtils;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
Expand All @@ -31,7 +29,11 @@
import com.github.dockerjava.api.command.CreateContainerResponse;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.command.InspectImageResponse;
import com.github.dockerjava.api.model.BuildResponseItem;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.AuthConfigurations;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.client.AbstractDockerClientTest;
import com.github.dockerjava.core.CompressArchiveUtil;

Expand Down Expand Up @@ -225,17 +227,59 @@ public void testAddAndCopySubstitution() throws Exception {
String response = dockerfileBuild(baseDir);
assertThat(response, containsString("testENVSubstitution successfully completed"));
}

@Test
public void testBuilderPerformance() throws Exception {
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("nginx").getFile());
public void testBuildFromPrivateRegistry() throws Exception {
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("privateRegistry").getFile());

String imageId = buildImage(baseDir);

InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
assertThat(inspectImageResponse, not(nullValue()));
LOG.info("Image Inspect: {}", inspectImageResponse.toString());

assertThat(inspectImageResponse.getAuthor(), equalTo("Guillaume J. Charmes \"[email protected]\""));
dockerClient.tagImageCmd(imageId, "testregistry", "2").withForce().exec();

// see https://github.com/docker/distribution/blob/master/docs/deploying.md#native-basic-auth
CreateContainerResponse testregistry = dockerClient
.createContainerCmd("testregistry:2")
.withName("registry")
.withPortBindings(new PortBinding(new Ports.Binding(5000), ExposedPort.tcp(5000)))
.withEnv("REGISTRY_AUTH=htpasswd", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
"REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd", "REGISTRY_LOG_LEVEL=debug",
"REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt", "REGISTRY_HTTP_TLS_KEY=/certs/domain.key")
.exec();

dockerClient.startContainerCmd(testregistry.getId()).exec();

AuthConfig authConfig = new AuthConfig();

// credentials as configured in /auth/htpasswd
authConfig.setUsername("testuser");
authConfig.setPassword("testpassword");
authConfig.setEmail("[email protected]");
authConfig.setServerAddress("localhost:5000");

dockerClient.authCmd().withAuthConfig(authConfig).exec();
dockerClient.tagImageCmd("busybox:latest", "localhost:5000/testuser/busybox", "latest").withForce().exec();

dockerClient.pushImageCmd("localhost:5000/testuser/busybox").withTag("latest").withAuthConfig(authConfig)
.exec(new PushImageResultCallback()).awaitSuccess();

dockerClient.removeImageCmd("localhost:5000/testuser/busybox").withForce().exec();

baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testBuildFromPrivateRegistry")
.getFile());

AuthConfigurations authConfigurations = new AuthConfigurations();
authConfigurations.addConfig(authConfig);

imageId = dockerClient.buildImageCmd(baseDir).withNoCache().withBuildAuthConfigs(authConfigurations)
.exec(new BuildImageResultCallback()).awaitImageId();

inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec();
assertThat(inspectImageResponse, not(nullValue()));
LOG.info("Image Inspect: {}", inspectImageResponse.toString());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,4 @@ public void asyncMultipleLogContainer() throws Exception {
assertTrue(loggingCallback.toString().contains(snippet));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,14 @@ public void pushLatest() throws Exception {
LOG.info("Removing image: {}", imageId);
dockerClient.removeImageCmd(imageId).exec();

dockerClient.pullImageCmd(username + "/busybox")
.exec(new PullImageResultCallback()).awaitSuccess();
dockerClient.pullImageCmd(username + "/busybox").exec(new PullImageResultCallback()).awaitSuccess();
}

@Test(expectedExceptions = DockerClientException.class)
public void pushNonExistentImage() throws Exception {

dockerClient.pushImageCmd(username + "/xxx").exec(new PushImageResultCallback())
.awaitSuccess();

dockerClient.pushImageCmd(username + "/xxx").exec(new PushImageResultCallback()).awaitSuccess();

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
public class DockerfileAddMultipleFilesTest extends TestCase {

private static final Logger log = LoggerFactory.getLogger(DockerfileAddMultipleFilesTest.class);

private static final Function<File, String> TO_FILE_NAMES = new Function<File, String>() {
@Override
public String apply(File file) {
Expand All @@ -26,7 +27,8 @@ public String apply(File file) {

@Test
public void testAddMultipleFiles() throws IOException {
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testAddMultipleFiles").getFile());
File baseDir = new File(Thread.currentThread().getContextClassLoader().getResource("testAddMultipleFiles")
.getFile());
Dockerfile dockerfile = new Dockerfile(new File(baseDir, "Dockerfile"));
Dockerfile.ScannedResult result = dockerfile.parse();
Collection<String> filesToAdd = transform(result.filesToAdd, TO_FILE_NAMES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ public class DockerfileStatementAddTest extends TestCase {

@DataProvider(name = "valid scenarios")
public Object[][] validScenarios() {
return new Object[][] {
{"ADD src dest", contains("src"), "dest"},
{"ADD \"src file\" \"dest\"", contains("src file"), "dest"},
{"ADD src\"file dest", contains("src\"file"), "dest"},
{"ADD src1 src2 dest", containsInAnyOrder("src1", "src2"), "dest"},
{"COPY src dest", contains("src"), "dest"},
{"COPY \"src file\" \"dest\"", contains("src file"), "dest"},
{"COPY src\"file dest", contains("src\"file"), "dest"},
{"COPY src1 src2 dest", containsInAnyOrder("src1", "src2"), "dest"}
};
return new Object[][] { { "ADD src dest", contains("src"), "dest" },
{ "ADD \"src file\" \"dest\"", contains("src file"), "dest" },
{ "ADD src\"file dest", contains("src\"file"), "dest" },
{ "ADD src1 src2 dest", containsInAnyOrder("src1", "src2"), "dest" },
{ "COPY src dest", contains("src"), "dest" },
{ "COPY \"src file\" \"dest\"", contains("src file"), "dest" },
{ "COPY src\"file dest", contains("src\"file"), "dest" },
{ "COPY src1 src2 dest", containsInAnyOrder("src1", "src2"), "dest" } };
}

@Test(dataProvider = "valid scenarios")
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/privateRegistry/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM registry:2
ADD auth/htpasswd /auth/htpasswd
ADD certs/* /certs/
2 changes: 2 additions & 0 deletions src/test/resources/privateRegistry/auth/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# testuser:testpassword (see see https://github.com/docker/distribution/blob/master/docs/deploying.md#native-basic-auth)
testuser:$2y$05$gI1hyzOYeLU92o5/DjVtOOHtdGymYbkjqJipZNqPET.ChzXMsz2KS
2 changes: 2 additions & 0 deletions src/test/resources/privateRegistry/certs/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory contains self signed certificate for docker registry with CN: "localhost". For testing purposes only.
See https://github.com/docker/distribution/blob/master/docs/insecure.md#using-self-signed-certificates
35 changes: 35 additions & 0 deletions src/test/resources/privateRegistry/certs/domain.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-----BEGIN CERTIFICATE-----
MIIGHzCCBAegAwIBAgIJALeUCTgohkuvMA0GCSqGSIb3DQEBCwUAMIGlMQswCQYD
VQQGEwJERTEQMA4GA1UECAwHSGFtYnVyZzEQMA4GA1UEBwwHSGFtYnVyZzEUMBIG
A1UECgwLZG9ja2VyLWphdmExFDASBgNVBAsMC2RvY2tlci1qYXZhMRIwEAYDVQQD
DAlsb2NhbGhvc3QxMjAwBgkqhkiG9w0BCQEWI2RvY2tlci1qYXZhLW1haW50YWlu
QGdvb2dsZW1haWwuY29tMB4XDTE1MDgxNDE3NDkyN1oXDTE2MDgxMzE3NDkyN1ow
gaUxCzAJBgNVBAYTAkRFMRAwDgYDVQQIDAdIYW1idXJnMRAwDgYDVQQHDAdIYW1i
dXJnMRQwEgYDVQQKDAtkb2NrZXItamF2YTEUMBIGA1UECwwLZG9ja2VyLWphdmEx
EjAQBgNVBAMMCWxvY2FsaG9zdDEyMDAGCSqGSIb3DQEJARYjZG9ja2VyLWphdmEt
bWFpbnRhaW5AZ29vZ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