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
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ Developer forum for [docker-java](https://groups.google.com/forum/?hl=de#!forum/
* Maven 3.0.5
* Docker daemon running

The Maven build includes integration tests which are using a localhost instance of Docker and require manual setup. Make sure you have a local Docker daemon running and then provide your https://registry.hub.docker.com/account/login/ information via system properties:
If you need SSL, then you'll need to put your `*.pem` file into `~/.docker/`, if you're using boot2docker, do this:

$ ln -s /Users/alex.collins/.boot2docker/certs/boot2docker-vm .docker

$ mvn clean install -Ddocker.io.username=... -Ddocker.io.password=... -Ddocker.io.email=...
Build and run integration tests as follows:

_If your Docker server is remote, add its URL like this: `-Ddocker.io.url=https://...:2376`._
$ mvn clean install

If you do not have access to a Docker server or just want to execute the build quickly, you can run the build without the integration tests:

Expand Down Expand Up @@ -79,9 +81,10 @@ There are a couple of configuration items, all of which have sensible defaults:

* `url` The Docker URL, e.g. `https://localhost:2376`.
* `version` The API version, e.g. `1.15`.
* `username` Your repository username (required to push containers).
* `password` Your repository password.
* `email` Your repository email.
* `username` Your registry username (required to push containers).
* `password` Your registry password.
* `email` Your registry email.
* `serverAddress` Your registry's address.
* `dockerCertPath` Path to the docker certs.

There are three ways to configure, in descending order of precedence:
Expand All @@ -95,6 +98,7 @@ In your application, e.g.
.withUsername("dockeruser")
.withPassword("ilovedocker")
.withEmail("[email protected]")
.withServerAddress("https://index.docker.io/v1/")
.withDockerCertPath("/home/user/.docker")
.build();
DockerClient docker = DockerClientBuilder.getInstance(config).build();
Expand All @@ -106,6 +110,7 @@ In your application, e.g.
docker.io.username=dockeruser
docker.io.password=ilovedocker
[email protected]
docker.io.serverAddress=https://index.docker.io/v1/
docker.io.dockerCertPath=/home/user/.docker


Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/github/dockerjava/api/command/AuthCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

import com.github.dockerjava.api.UnauthorizedException;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.AuthResponse;

/**
*
* Authenticate with the server, useful for checking authentication.
*
*/
public interface AuthCmd extends DockerCmd<Void> {
public interface AuthCmd extends DockerCmd<AuthResponse> {

public AuthConfig getAuthConfig();

public AuthCmd withAuthConfig(AuthConfig authConfig);


/**
* @return The status. Based on it's value you may mean you need to authorise your account, e.g.:
* "Account created. Please see the documentation of the registry http://localhost:5000/v1/ for instructions how to activate it."
* @throws UnauthorizedException If you're not authorised (e.g. bad password).
*/
@Override
public Void exec() throws UnauthorizedException;
public AuthResponse exec() throws UnauthorizedException;

public static interface Exec extends DockerCmdExec<AuthCmd, Void> {
public static interface Exec extends DockerCmdExec<AuthCmd, AuthResponse> {
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.model.AuthConfig;

import java.io.InputStream;

/**
Expand All @@ -15,13 +17,17 @@ public interface PullImageCmd extends DockerCmd<InputStream>{

public String getRegistry();

public PullImageCmd withRepository(String repository);
public AuthConfig getAuthConfig();

public PullImageCmd withRepository(String repository);

public PullImageCmd withTag(String tag);

public PullImageCmd withRegistry(String registry);

public static interface Exec extends DockerCmdExec<PullImageCmd, InputStream> {

public PullImageCmd withAuthConfig(AuthConfig authConfig);

public static interface Exec extends DockerCmdExec<PullImageCmd, InputStream> {
}

}
13 changes: 10 additions & 3 deletions src/main/java/com/github/dockerjava/api/model/AuthConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
import com.fasterxml.jackson.annotation.JsonProperty;

public class AuthConfig {

@JsonProperty

/**
* For backwards compatibility. Make sure you update the properties if you change this.
*
* @see /docker.io.properties
*/
public static final String DEFAULT_SERVER_ADDRESS = "https://index.docker.io/v1/";

@JsonProperty
private String username;

@JsonProperty
Expand All @@ -14,7 +21,7 @@ public class AuthConfig {
private String email;

@JsonProperty("serveraddress")
private String serverAddress = "https://index.docker.io/v1/";
private String serverAddress = DEFAULT_SERVER_ADDRESS;

public String getUsername() {
return username;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/AuthResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class AuthResponse {
@JsonProperty("Status")
private String status;

public String getStatus() {
return status;
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/ErrorDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ErrorDetail {
@JsonProperty
private String message;

public String getMessage() {
return message;
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/github/dockerjava/api/model/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.dockerjava.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

public class ErrorResponse {
@JsonProperty
private ErrorDetail errorDetail;
@JsonProperty
private String error;

public ErrorDetail getErrorDetail() {
return errorDetail;
}

public String getError() {
return error;
}
}
25 changes: 22 additions & 3 deletions src/main/java/com/github/dockerjava/core/DockerClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DockerClientConfig {
private static final String DOCKER_IO_USERNAME_PROPERTY = "docker.io.username";
private static final String DOCKER_IO_PASSWORD_PROPERTY = "docker.io.password";
private static final String DOCKER_IO_EMAIL_PROPERTY = "docker.io.email";
private static final String DOCKER_IO_SERVER_ADDRESS_PROPERTY = "docker.io.serverAddress";
private static final String DOCKER_IO_READ_TIMEOUT_PROPERTY = "docker.io.readTimeout";
// this is really confusing, as there are two ways to spell it
private static final String DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY = "docker.io.enableLoggingFilter";
Expand All @@ -31,22 +32,24 @@ public class DockerClientConfig {
.put("DOCKER_USERNAME", DOCKER_IO_USERNAME_PROPERTY)
.put("DOCKER_PASSWORD", DOCKER_IO_PASSWORD_PROPERTY)
.put("DOCKER_EMAIL", DOCKER_IO_EMAIL_PROPERTY)
.put("DOCKER_SERVER_ADDRESS", DOCKER_IO_SERVER_ADDRESS_PROPERTY)
.put("DOCKER_READ_TIMEOUT", DOCKER_IO_READ_TIMEOUT_PROPERTY)
.put("DOCKER_LOGGING_FILTER_ENABLED", DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY)
.put(DOCKER_CERT_PATH_PROPERTY, DOCKER_IO_DOCKER_CERT_PATH_PROPERTY)
.build();
private static final String DOCKER_IO_PROPERTIES_PROPERTY = "docker.io.properties";
private final URI uri;
private final String version, username, password, email, dockerCertPath;
private final String version, username, password, email, serverAddress, dockerCertPath;
private final Integer readTimeout;
private final boolean loggingFilterEnabled;

DockerClientConfig(URI uri, String version, String username, String password, String email, String dockerCertPath, Integer readTimeout, boolean loggingFilterEnabled) {
DockerClientConfig(URI uri, String version, String username, String password, String email, String serverAddress, String dockerCertPath, Integer readTimeout, boolean loggingFilterEnabled) {
this.uri = uri;
this.version = version;
this.username = username;
this.password = password;
this.email = email;
this.serverAddress = serverAddress;
this.dockerCertPath = dockerCertPath;
this.readTimeout = readTimeout;
this.loggingFilterEnabled = loggingFilterEnabled;
Expand Down Expand Up @@ -146,6 +149,7 @@ private static Properties overrideDockerPropertiesWithSystemProperties(Propertie
DOCKER_IO_USERNAME_PROPERTY,
DOCKER_IO_PASSWORD_PROPERTY,
DOCKER_IO_EMAIL_PROPERTY,
DOCKER_IO_SERVER_ADDRESS_PROPERTY,
DOCKER_IO_READ_TIMEOUT_PROPERTY,
DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY,
DOCKER_IO_DOCKER_CERT_PATH_PROPERTY,
Expand Down Expand Up @@ -192,6 +196,10 @@ public String getEmail() {
return email;
}

public String getServerAddress() {
return serverAddress;
}

public Integer getReadTimeout() {
return readTimeout;
}
Expand All @@ -217,6 +225,8 @@ public boolean equals(Object o) {
if (email != null ? !email.equals(that.email) : that.email != null) return false;
if (password != null ? !password.equals(that.password) : that.password != null) return false;
if (readTimeout != null ? !readTimeout.equals(that.readTimeout) : that.readTimeout != null) return false;
if (serverAddress != null ? !serverAddress.equals(that.serverAddress) : that.serverAddress != null)
return false;
if (uri != null ? !uri.equals(that.uri) : that.uri != null) return false;
if (username != null ? !username.equals(that.username) : that.username != null) return false;
if (version != null ? !version.equals(that.version) : that.version != null) return false;
Expand All @@ -231,6 +241,7 @@ public int hashCode() {
result = 31 * result + (username != null ? username.hashCode() : 0);
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (serverAddress != null ? serverAddress.hashCode() : 0);
result = 31 * result + (dockerCertPath != null ? dockerCertPath.hashCode() : 0);
result = 31 * result + (readTimeout != null ? readTimeout.hashCode() : 0);
result = 31 * result + (loggingFilterEnabled ? 1 : 0);
Expand All @@ -245,6 +256,7 @@ public String toString() {
", username='" + username + '\'' +
", password='" + password + '\'' +
", email='" + email + '\'' +
", serverAddress='" + serverAddress + '\'' +
", dockerCertPath='" + dockerCertPath + '\'' +
", readTimeout=" + readTimeout +
", loggingFilterEnabled=" + loggingFilterEnabled +
Expand All @@ -253,7 +265,7 @@ public String toString() {

public static class DockerClientConfigBuilder {
private URI uri;
private String version, username, password, email, dockerCertPath;
private String version, username, password, email, serverAddress, dockerCertPath;
private Integer readTimeout;
private boolean loggingFilterEnabled;

Expand All @@ -269,6 +281,7 @@ public DockerClientConfigBuilder withProperties(Properties p) {
.withUsername(p.getProperty(DOCKER_IO_USERNAME_PROPERTY))
.withPassword(p.getProperty(DOCKER_IO_PASSWORD_PROPERTY))
.withEmail(p.getProperty(DOCKER_IO_EMAIL_PROPERTY))
.withServerAddress(p.getProperty(DOCKER_IO_SERVER_ADDRESS_PROPERTY))
.withReadTimeout(Integer.valueOf(p.getProperty(DOCKER_IO_READ_TIMEOUT_PROPERTY, "0")))
.withLoggingFilter(Boolean.valueOf(p.getProperty(DOCKER_IO_ENABLE_LOGGING_FILTER_PROPERTY, "true")))
.withDockerCertPath(p.getProperty(DOCKER_IO_DOCKER_CERT_PATH_PROPERTY));
Expand Down Expand Up @@ -300,6 +313,11 @@ public final DockerClientConfigBuilder withEmail(String email) {
return this;
}

public DockerClientConfigBuilder withServerAddress(String serverAddress) {
this.serverAddress = serverAddress;
return this;
}

public final DockerClientConfigBuilder withReadTimeout(Integer readTimeout) {
this.readTimeout = readTimeout;
return this;
Expand All @@ -322,6 +340,7 @@ public DockerClientConfig build() {
username,
password,
email,
serverAddress,
dockerCertPath,
readTimeout,
loggingFilterEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ private DockerCmdExecFactory getDockerCmdExecFactory() {

public AuthConfig authConfig() {
checkNotNull(dockerClientConfig.getUsername(), "Configured username is null.");
checkNotNull(dockerClientConfig.getPassword(), "Configured password is null.");
checkNotNull(dockerClientConfig.getEmail(), "Configured email is null.");
checkNotNull(dockerClientConfig.getServerAddress(), "Configured serverAddress is null.");

AuthConfig authConfig = new AuthConfig();
authConfig.setUsername(dockerClientConfig.getUsername());
authConfig.setPassword(dockerClientConfig.getPassword());
authConfig.setEmail(dockerClientConfig.getEmail());
// TODO Make the registry address configurable
authConfig.setServerAddress(dockerClientConfig.getServerAddress());

return authConfig;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
import com.github.dockerjava.api.UnauthorizedException;
import com.github.dockerjava.api.command.AuthCmd;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.AuthResponse;

/**
*
* Authenticate with the server, useful for checking authentication.
*
*/
public class AuthCmdImpl extends AbstrAuthCfgDockerCmd<AuthCmd, Void> implements AuthCmd {
public class AuthCmdImpl extends AbstrAuthCfgDockerCmd<AuthCmd, AuthResponse> implements AuthCmd {

public AuthCmdImpl(AuthCmd.Exec exec, AuthConfig authConfig) {
super(exec);
withAuthConfig(authConfig);
}

@Override
public Void exec() throws UnauthorizedException {
public AuthResponse exec() throws UnauthorizedException {
return super.exec();
}

@Override
public String toString() {
return "authenticate using " + this.getAuthConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.github.dockerjava.core.command;

import java.io.InputStream;

import com.github.dockerjava.api.command.PullImageCmd;

import com.github.dockerjava.api.model.AuthConfig;
import com.google.common.base.Preconditions;

import java.io.InputStream;

/**
*
* Pull image from repository.
*
*/
public class PullImageCmdImpl extends AbstrDockerCmd<PullImageCmd, InputStream> implements PullImageCmd {

private String repository, tag, registry;
private String repository, tag, registry;
private AuthConfig authConfig;

public PullImageCmdImpl(PullImageCmd.Exec exec, String repository) {
super(exec);
Expand All @@ -35,6 +36,10 @@ public String getRegistry() {
return registry;
}

public AuthConfig getAuthConfig() {
return authConfig;
}

@Override
public PullImageCmd withRepository(String repository) {
Preconditions.checkNotNull(repository, "repository was not specified");
Expand All @@ -56,6 +61,13 @@ public PullImageCmd withRegistry(String registry) {
return this;
}

@Override
public PullImageCmd withAuthConfig(AuthConfig authConfig) {
Preconditions.checkNotNull(authConfig, "authConfig was not specified");
this.authConfig = authConfig;
return this;
}

@Override
public String toString() {
return new StringBuilder("pull ")
Expand Down
Loading