use of io.fabric8.docker.dsl.EventListener 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);
}
use of io.fabric8.docker.dsl.EventListener in project kubernetes by ballerinax.
the class DockerHandler method buildImage.
/**
* Create docker image.
*
* @param dockerModel dockerModel object
* @param dockerDir dockerfile directory
* @throws InterruptedException When error with docker build process
* @throws IOException When error with docker build process
*/
public void buildImage(DockerModel dockerModel, String dockerDir) throws InterruptedException, IOException, KubernetesPluginException {
Config dockerClientConfig = new ConfigBuilder().withDockerUrl(dockerModel.getDockerHost()).build();
DockerClient client = new io.fabric8.docker.client.DefaultDockerClient(dockerClientConfig);
final DockerError dockerError = new DockerError();
OutputHandle buildHandle = client.image().build().withRepositoryName(dockerModel.getName()).withNoCache().alwaysRemovingIntermediate().usingListener(new EventListener() {
@Override
public void onSuccess(String message) {
buildDone.countDown();
}
@Override
public void onError(String message) {
dockerError.setErrorMsg("error building docker image: " + message);
buildDone.countDown();
}
@Override
public void onError(Throwable t) {
dockerError.setErrorMsg("error building docker image: " + t.getMessage());
buildDone.countDown();
}
@Override
public void onEvent(String event) {
printDebug(event);
}
}).fromFolder(dockerDir);
buildDone.await();
buildHandle.close();
client.close();
handleError(dockerError);
}
Aggregations