Search in sources :

Example 1 with FixedRegistryAuthSupplier

use of com.spotify.docker.client.auth.FixedRegistryAuthSupplier in project TOSCAna by StuPro-TOSCAna.

the class PushingImageBuilder method getDockerClient.

@Override
protected DockerClient getDockerClient() throws DockerCertificateException {
    // Initialize Docker Client
    logger.debug("Attempting to get connection to the Docker Daemon");
    RegistryAuth auth = this.credentials.toRegistryAuth();
    return DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(auth, RegistryConfigs.create(Collections.singletonMap(this.credentials.getRegistryURL(), auth)))).build();
}
Also used : FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth)

Example 2 with FixedRegistryAuthSupplier

use of com.spotify.docker.client.auth.FixedRegistryAuthSupplier in project TOSCAna by StuPro-TOSCAna.

the class PushingImageBuilderIT method validate.

@Override
public void validate(String tag) throws Exception {
    RegistryAuth auth = credentials.toRegistryAuth();
    DockerClient client = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(auth, RegistryConfigs.create(Collections.singletonMap(credentials.getRegistryURL(), auth)))).build();
    client.removeImage(tag);
    // Pull the image from the registry
    client.pull(tag);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth)

Example 3 with FixedRegistryAuthSupplier

use of com.spotify.docker.client.auth.FixedRegistryAuthSupplier in project docker-client by spotify.

the class DefaultDockerClientTest method testBuildImageIdWithAuth.

@Test
public void testBuildImageIdWithAuth() throws Exception {
    final Path dockerDirectory = getResource("dockerDirectory");
    final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();
    final RegistryAuth registryAuth = RegistryAuth.builder().username(AUTH_USERNAME).password(AUTH_PASSWORD).build();
    final DockerClient sut2 = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap("", registryAuth)))).build();
    final String returnedImageId = sut2.build(dockerDirectory, "test", new ProgressHandler() {

        @Override
        public void progress(ProgressMessage message) throws DockerException {
            final String imageId = message.buildImageId();
            if (imageId != null) {
                imageIdFromMessage.set(imageId);
            }
        }
    });
    assertThat(returnedImageId, is(imageIdFromMessage.get()));
}
Also used : Path(java.nio.file.Path) DockerException(com.spotify.docker.client.exceptions.DockerException) ProgressMessage(com.spotify.docker.client.messages.ProgressMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Example 4 with FixedRegistryAuthSupplier

use of com.spotify.docker.client.auth.FixedRegistryAuthSupplier in project docker-client by spotify.

the class PushPullIT method setup.

@Before
public void setup() throws Exception {
    final RegistryAuth registryAuth = RegistryAuth.builder().username(LOCAL_AUTH_USERNAME).password(LOCAL_AUTH_PASSWORD).build();
    client = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth)))).build();
    System.out.printf("- %s\n", testName.getMethodName());
}
Also used : FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Before(org.junit.Before)

Example 5 with FixedRegistryAuthSupplier

use of com.spotify.docker.client.auth.FixedRegistryAuthSupplier in project docker-client by spotify.

the class PushPullIT method testPushHubPrivateImageWithAuth.

@Test
public void testPushHubPrivateImageWithAuth() throws Exception {
    // Push an image to a private repo on Docker Hub and check it succeeds
    final String dockerDirectory = Resources.getResource("dockerDirectory").getPath();
    final RegistryAuth registryAuth = RegistryAuth.builder().username(HUB_AUTH_USERNAME).password(HUB_AUTH_PASSWORD).build();
    final DockerClient client = DefaultDockerClient.fromEnv().registryAuthSupplier(new FixedRegistryAuthSupplier(registryAuth, RegistryConfigs.create(singletonMap(HUB_NAME, registryAuth)))).build();
    client.build(Paths.get(dockerDirectory), HUB_PRIVATE_IMAGE);
    client.push(HUB_PRIVATE_IMAGE);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FixedRegistryAuthSupplier(com.spotify.docker.client.auth.FixedRegistryAuthSupplier) RegistryAuth(com.spotify.docker.client.messages.RegistryAuth) Test(org.junit.Test)

Aggregations

FixedRegistryAuthSupplier (com.spotify.docker.client.auth.FixedRegistryAuthSupplier)7 RegistryAuth (com.spotify.docker.client.messages.RegistryAuth)7 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)4 DockerClient (com.spotify.docker.client.DockerClient)4 Test (org.junit.Test)4 DockerException (com.spotify.docker.client.exceptions.DockerException)1 ProgressMessage (com.spotify.docker.client.messages.ProgressMessage)1 Long.toHexString (java.lang.Long.toHexString)1 Path (java.nio.file.Path)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)1 Before (org.junit.Before)1