Search in sources :

Example 46 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method pushImage.

@Override
public void pushImage(String image, AuthConfig authConfig, String registry, int retries) throws DockerAccessException {
    ImageName name = new ImageName(image);
    String pushUrl = urlBuilder.pushImage(name, registry);
    TemporaryImageHandler temporaryImageHandler = tagTemporaryImage(name, registry);
    DockerAccessException dae = null;
    try {
        doPushImage(pushUrl, createAuthHeader(authConfig), createPullOrPushResponseHandler(), HTTP_OK, retries);
    } catch (IOException e) {
        dae = new DockerAccessException(e, "Unable to push '%s'%s", image, (registry != null) ? " to registry '" + registry + "'" : "");
        throw dae;
    } finally {
        temporaryImageHandler.handle(dae);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException)

Example 47 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class LogsMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub hub) throws MojoExecutionException, DockerAccessException {
    QueryService queryService = hub.getQueryService();
    LogDispatcher logDispatcher = getLogDispatcher(hub);
    for (ImageConfiguration image : getResolvedImages()) {
        String imageName = image.getName();
        if (logAll) {
            for (Container container : queryService.getContainersForImage(imageName, false)) {
                doLogging(logDispatcher, image, container.getId());
            }
        } else {
            Container container = queryService.getLatestContainerForImage(imageName, false);
            if (container != null) {
                doLogging(logDispatcher, image, container.getId());
            }
        }
    }
    if (follow) {
        // Block forever ....
        waitForEver();
    }
}
Also used : Container(io.fabric8.maven.docker.model.Container) QueryService(io.fabric8.maven.docker.service.QueryService) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) LogDispatcher(io.fabric8.maven.docker.log.LogDispatcher)

Example 48 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class RegistryServiceTest method givenAnImageConfiguration.

private void givenAnImageConfiguration(String imageName) {
    final BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration.Builder().build();
    imageConfiguration = new ImageConfiguration.Builder().name(imageName).buildConfig(buildImageConfiguration).build();
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 49 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class BuildService method tagImage.

public void tagImage(String imageName, String tag, String repo, CleanupMode cleanupMode) throws DockerAccessException {
    if (tag != null) {
        String fullImageName = new ImageName(imageName, tag).getNameWithOptionalRepository(repo);
        String oldImageId = null;
        if (cleanupMode.isRemove()) {
            oldImageId = queryService.getImageId(fullImageName);
        }
        docker.tag(imageName, fullImageName, true);
        log.info("Tagging image %s successful!", fullImageName);
        String newImageId = queryService.getImageId(fullImageName);
        removeDanglingImage(fullImageName, oldImageId, newImageId, cleanupMode, false);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 50 with ImageName

use of io.fabric8.maven.docker.util.ImageName in project docker-maven-plugin by fabric8io.

the class JibBuildService method getRegistryCredentials.

static Credential getRegistryCredentials(RegistryService.RegistryConfig registryConfig, boolean isPush, ImageConfiguration imageConfiguration, Logger log) throws MojoExecutionException {
    String registry;
    if (isPush) {
        registry = EnvUtil.firstRegistryOf(new ImageName(imageConfiguration.getName()).getRegistry(), imageConfiguration.getRegistry(), registryConfig.getRegistry());
    } else {
        registry = EnvUtil.firstRegistryOf(new ImageName(getBaseImage(imageConfiguration)).getRegistry(), registryConfig.getRegistry());
    }
    if (registry == null || DEFAULT_DOCKER_REGISTRIES.contains(registry)) {
        // Let's assume docker is default registry.
        registry = DOCKER_LOGIN_DEFAULT_REGISTRY;
    }
    AuthConfigFactory authConfigFactory = registryConfig.getAuthConfigFactory();
    AuthConfig standardAuthConfig = authConfigFactory.createAuthConfig(isPush, registryConfig.isSkipExtendedAuth(), registryConfig.getAuthConfig(), registryConfig.getSettings(), null, registry);
    Credential credentials = null;
    if (standardAuthConfig != null) {
        credentials = Credential.from(standardAuthConfig.getUsername(), standardAuthConfig.getPassword());
    }
    return credentials;
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) Credential(com.google.cloud.tools.jib.api.Credential) AuthConfigFactory(io.fabric8.maven.docker.util.AuthConfigFactory) AuthConfig(io.fabric8.maven.docker.access.AuthConfig)

Aggregations

ImageName (io.fabric8.maven.docker.util.ImageName)20 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 File (java.io.File)9 IOException (java.io.IOException)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)6 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)4 CopyConfiguration (io.fabric8.maven.docker.config.CopyConfiguration)4 Container (io.fabric8.maven.docker.model.Container)4 Test (org.junit.Test)4 DockerClient (io.fabric8.docker.client.DockerClient)3 Container (io.fabric8.kubernetes.api.model.Container)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)3 ArrayList (java.util.ArrayList)3 Controller (io.fabric8.kubernetes.api.Controller)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)2 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)2