Search in sources :

Example 6 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.

the class RegistryService method pullImageWithPolicy.

/**
 * Check an image, and, if <code>autoPull</code> is set to true, fetch it. Otherwise if the image
 * is not existent, throw an error
 * @param registryConfig registry configuration
 *
 * @throws DockerAccessException
 * @throws MojoExecutionException
 */
public void pullImageWithPolicy(String image, ImagePullManager pullManager, RegistryConfig registryConfig, boolean hasImage) throws DockerAccessException, MojoExecutionException {
    // Already pulled, so we don't need to take care
    if (pullManager.hasAlreadyPulled(image)) {
        return;
    }
    // Check if a pull is required
    if (!imageRequiresPull(hasImage, pullManager.getImagePullPolicy(), image)) {
        return;
    }
    ImageName imageName = new ImageName(image);
    long time = System.currentTimeMillis();
    String actualRegistry = EnvUtil.fistRegistryOf(imageName.getRegistry(), registryConfig.getRegistry());
    docker.pullImage(imageName.getFullName(), createAuthConfig(false, null, actualRegistry, registryConfig), actualRegistry);
    log.info("Pulled %s in %s", imageName.getFullName(), EnvUtil.formatDurationTill(time));
    pullManager.pulled(image);
    if (actualRegistry != null && !imageName.hasRegistry()) {
        // If coming from a registry which was not contained in the original name, add a tag from the
        // full name with the registry to the short name with no-registry.
        docker.tag(imageName.getFullName(actualRegistry), image, false);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName)

Example 7 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.

the class RunService method execInContainer.

/**
 * Create and start a Exec container with the given image configuration.
 * @param containerId container id to run exec command against
 * @param command command to execute
 * @param imageConfiguration configuration of the container's image
 * @return the exec container id
 *
 * @throws DockerAccessException if access to the docker backend fails
 */
public String execInContainer(String containerId, String command, ImageConfiguration imageConfiguration) throws DockerAccessException, ExecException {
    Arguments arguments = new Arguments();
    arguments.setExec(Arrays.asList(EnvUtil.splitOnSpaceWithEscape(command)));
    String execContainerId = docker.createExecContainer(containerId, arguments);
    docker.startExecContainer(execContainerId, logConfig.createSpec(containerId, imageConfiguration));
    ExecDetails execContainer = docker.getExecContainer(execContainerId);
    Integer exitCode = execContainer.getExitCode();
    if (exitCode != null && exitCode != 0) {
        ContainerDetails container = docker.getContainer(containerId);
        throw new ExecException(execContainer, container);
    }
    return execContainerId;
}
Also used : ExecDetails(io.fabric8.maven.docker.model.ExecDetails) ExecException(io.fabric8.maven.docker.access.ExecException) ContainerDetails(io.fabric8.maven.docker.model.ContainerDetails)

Example 8 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.

the class DockerAccessIT method testCreateContainer.

private void testCreateContainer() throws DockerAccessException {
    PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
    ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
    ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
    containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
    assertNotNull(containerId);
    String name = dockerClient.getContainer(containerId).getName();
    assertEquals(CONTAINER_NAME, name);
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) PortMapping(io.fabric8.maven.docker.access.PortMapping) Properties(java.util.Properties) ContainerHostConfig(io.fabric8.maven.docker.access.ContainerHostConfig)

Example 9 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.

the class DockerAccessWinIT method testCreateContainer.

private void testCreateContainer() throws DockerAccessException {
    PortMapping portMapping = new PortMapping(Arrays.asList(new String[] { PORT + ":" + PORT }), new Properties());
    ContainerHostConfig hostConfig = new ContainerHostConfig().portBindings(portMapping);
    ContainerCreateConfig createConfig = new ContainerCreateConfig(IMAGE).command(new Arguments("ping google.com")).hostConfig(hostConfig);
    containerId = dockerClient.createContainer(createConfig, CONTAINER_NAME);
    assertNotNull(containerId);
    String name = dockerClient.getContainer(containerId).getName();
    assertEquals(CONTAINER_NAME, name);
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments) ContainerCreateConfig(io.fabric8.maven.docker.access.ContainerCreateConfig) PortMapping(io.fabric8.maven.docker.access.PortMapping) Properties(java.util.Properties) ContainerHostConfig(io.fabric8.maven.docker.access.ContainerHostConfig)

Example 10 with DockerAccessException

use of io.fabric8.maven.docker.access.DockerAccessException in project docker-maven-plugin by fabric8io.

the class DockerAccessWinIT method testExecContainer.

private void testExecContainer() throws DockerAccessException {
    Arguments arguments = new Arguments();
    arguments.setExec(Lists.newArrayList("echo", "test", "echo"));
    String execContainerId = dockerClient.createExecContainer(this.containerId, arguments);
// assertThat(dockerClient.startExecContainer(execContainerId), is("test echo"));
}
Also used : Arguments(io.fabric8.maven.docker.config.Arguments)

Aggregations

DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)11 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 Container (io.fabric8.maven.docker.model.Container)6 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 Arguments (io.fabric8.maven.docker.config.Arguments)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 PortMapping (io.fabric8.maven.docker.access.PortMapping)3 File (java.io.File)3 IOException (java.io.IOException)3 ContainerCreateConfig (io.fabric8.maven.docker.access.ContainerCreateConfig)2 ContainerHostConfig (io.fabric8.maven.docker.access.ContainerHostConfig)2 ExecException (io.fabric8.maven.docker.access.ExecException)2 HttpBodyAndStatus (io.fabric8.maven.docker.access.hc.ApacheHttpClientDelegate.HttpBodyAndStatus)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 VolumeConfiguration (io.fabric8.maven.docker.config.VolumeConfiguration)2 LogDispatcher (io.fabric8.maven.docker.log.LogDispatcher)2 ContainerDetails (io.fabric8.maven.docker.model.ContainerDetails)2 Network (io.fabric8.maven.docker.model.Network)2