Search in sources :

Example 11 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project kubernetes by ballerinax.

the class DockerHandler method pushImage.

/**
 * Push docker image.
 *
 * @param dockerModel DockerModel
 * @throws InterruptedException When error with docker build process
 * @throws IOException          When error with docker build process
 */
public void pushImage(DockerModel dockerModel) throws InterruptedException, IOException, KubernetesPluginException {
    AuthConfig authConfig = new AuthConfigBuilder().withUsername(dockerModel.getUsername()).withPassword(dockerModel.getPassword()).build();
    Config config = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).addToAuthConfigs(RegistryUtils.extractRegistry(dockerModel.getName()), authConfig).build();
    DockerClient client = new DefaultDockerClient(config);
    final DockerError dockerError = new DockerError();
    OutputHandle handle = client.image().withName(dockerModel.getName()).push().usingListener(new EventListener() {

        @Override
        public void onSuccess(String message) {
            pushDone.countDown();
        }

        @Override
        public void onError(String message) {
            pushDone.countDown();
            dockerError.setErrorMsg("error pushing docker image: " + message);
        }

        @Override
        public void onError(Throwable t) {
            pushDone.countDown();
            dockerError.setErrorMsg("error pushing docker image: " + t.getMessage());
        }

        @Override
        public void onEvent(String event) {
            printDebug(event);
        }
    }).toRegistry();
    pushDone.await();
    handle.close();
    client.close();
    handleError(dockerError);
}
Also used : AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) DockerClient(io.fabric8.docker.client.DockerClient) Config(io.fabric8.docker.client.Config) AuthConfig(io.fabric8.docker.api.model.AuthConfig) DefaultDockerClient(io.fabric8.docker.client.DefaultDockerClient) AuthConfigBuilder(io.fabric8.docker.api.model.AuthConfigBuilder) ConfigBuilder(io.fabric8.docker.client.ConfigBuilder) OutputHandle(io.fabric8.docker.dsl.OutputHandle) AuthConfig(io.fabric8.docker.api.model.AuthConfig) EventListener(io.fabric8.docker.dsl.EventListener)

Example 12 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromPluginConfigurationPull.

@Test
public void testFromPluginConfigurationPull() throws MojoExecutionException {
    Map pullConfig = new HashMap();
    pullConfig.put("username", "roland");
    pullConfig.put("password", "secret");
    pullConfig.put("email", "roland@jolokia.org");
    Map pluginConfig = new HashMap();
    pluginConfig.put("pull", pullConfig);
    AuthConfig config = factory.createAuthConfig(false, false, pluginConfig, settings, null, null);
    verifyAuthConfig(config, "roland", "secret", "roland@jolokia.org");
}
Also used : HashMap(java.util.HashMap) AuthConfig(io.fabric8.maven.docker.access.AuthConfig) HashMap(java.util.HashMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) Test(org.junit.Test)

Example 13 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromSettingsDefault.

@Test
public void testFromSettingsDefault() throws MojoExecutionException {
    setupServers();
    AuthConfig config = factory.createAuthConfig(isPush, false, null, settings, "fabric8io", "test.org");
    assertNotNull(config);
    verifyAuthConfig(config, "fabric8io", "secret2", "fabric8io@redhat.com");
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 14 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromSettingsSimple.

@Test
public void testFromSettingsSimple() throws MojoExecutionException {
    setupServers();
    AuthConfig config = factory.createAuthConfig(isPush, false, null, settings, "roland", "test.org");
    assertNotNull(config);
    verifyAuthConfig(config, "roland", "secret", "roland@jolokia.org");
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Example 15 with AuthConfig

use of io.fabric8.docker.api.model.AuthConfig in project docker-maven-plugin by fabric8io.

the class AuthConfigFactoryTest method testFromSettingsDefault2.

@Test
public void testFromSettingsDefault2() throws MojoExecutionException {
    setupServers();
    AuthConfig config = factory.createAuthConfig(isPush, false, null, settings, "tanja", null);
    assertNotNull(config);
    verifyAuthConfig(config, "tanja", "doublesecret", "tanja@jolokia.org");
}
Also used : AuthConfig(io.fabric8.maven.docker.access.AuthConfig) Test(org.junit.Test)

Aggregations

AuthConfig (io.fabric8.maven.docker.access.AuthConfig)22 Test (org.junit.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Date (java.util.Date)3 Collections.singletonMap (java.util.Collections.singletonMap)2 Properties (java.util.Properties)2 HttpPost (org.apache.http.client.methods.HttpPost)2 StringEntity (org.apache.http.entity.StringEntity)2 JSONObject (org.json.JSONObject)2 AuthConfig (io.fabric8.docker.api.model.AuthConfig)1 AuthConfigBuilder (io.fabric8.docker.api.model.AuthConfigBuilder)1 Config (io.fabric8.docker.client.Config)1 ConfigBuilder (io.fabric8.docker.client.ConfigBuilder)1 DefaultDockerClient (io.fabric8.docker.client.DefaultDockerClient)1 DockerClient (io.fabric8.docker.client.DockerClient)1 EventListener (io.fabric8.docker.dsl.EventListener)1 OutputHandle (io.fabric8.docker.dsl.OutputHandle)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1