Search in sources :

Example 16 with DockerAccessException

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

the class BuildJsonResponseHandler method process.

@Override
public void process(JSONObject json) throws DockerAccessException {
    if (json.has("error")) {
        String msg = json.getString("error");
        String detailMsg = "";
        if (json.has("errorDetail")) {
            JSONObject details = json.getJSONObject("errorDetail");
            detailMsg = details.getString("message");
        }
        throw new DockerAccessException("%s %s", json.get("error"), (msg.equals(detailMsg) || "".equals(detailMsg) ? "" : "(" + detailMsg + ")"));
    } else if (json.has("stream")) {
        String message = json.getString("stream");
        log.verbose("%s", message.trim());
    } else if (json.has("status")) {
        String status = json.getString("status").trim();
        String id = json.has("id") ? json.getString("id") : null;
        if (status.matches("^.*(Download|Pulling).*")) {
            log.info("  %s%s", id != null ? id + " " : "", status);
        }
    }
}
Also used : JSONObject(org.json.JSONObject) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException)

Example 17 with DockerAccessException

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

the class DockerImageWatcher method buildImage.

protected void buildImage(ImageConfiguration imageConfig) throws DockerAccessException, MojoExecutionException {
    String imageName = imageConfig.getName();
    // lets regenerate the label
    try {
        String imagePrefix = getImagePrefix(imageName);
        imageName = imagePrefix + "%t";
        ImageNameFormatter formatter = new ImageNameFormatter(getContext().getProject(), new Date());
        imageName = formatter.format(imageName);
        imageConfig.setName(imageName);
        log.info("New image name: " + imageConfig.getName());
    } catch (Exception e) {
        log.error("Caught: " + e, e);
    }
}
Also used : ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) Date(java.util.Date) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 18 with DockerAccessException

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

the class ExitCodeCheckerTest method checkReturnsFalseIfContainerDoesNotExist.

@Test
public void checkReturnsFalseIfContainerDoesNotExist() throws Exception {
    new Expectations() {

        {
            Exception e = new DockerAccessException("Cannot find container %s", CONTAINER_ID);
            queryService.getMandatoryContainer(CONTAINER_ID);
            result = e;
        }
    };
    ExitCodeChecker checker = new ExitCodeChecker(0, queryService, CONTAINER_ID);
    assertThat(checker.check()).isFalse();
}
Also used : Expectations(mockit.Expectations) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) Test(org.junit.Test)

Example 19 with DockerAccessException

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

the class LogRequestor method parseResponse.

private void parseResponse(HttpResponse response) throws LogCallback.DoneException, IOException {
    final StatusLine status = response.getStatusLine();
    if (status.getStatusCode() != 200) {
        exception = new DockerAccessException("Error while reading logs (" + status + ")");
        throw new LogCallback.DoneException();
    }
    final InputStream is = response.getEntity().getContent();
    try {
        while (true) {
            if (!readStreamFrame(is)) {
                return;
            }
        }
    } finally {
        if ((is != null) && (is.available() > 0)) {
            is.close();
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) InputStream(java.io.InputStream) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException)

Example 20 with DockerAccessException

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

the class BuildService method autoPullBaseImage.

private void autoPullBaseImage(ImageConfiguration imageConfig, ImagePullManager imagePullManager, BuildContext buildContext) throws DockerAccessException, MojoExecutionException {
    BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
    if (buildConfig.getDockerArchive() != null) {
        // No auto pull needed in archive mode
        return;
    }
    String fromImage;
    if (buildConfig.isDockerFileMode()) {
        fromImage = extractBaseFromDockerfile(buildConfig, buildContext);
    } else {
        fromImage = extractBaseFromConfiguration(buildConfig);
    }
    if (fromImage != null && !DockerAssemblyManager.SCRATCH_IMAGE.equals(fromImage)) {
        registryService.pullImageWithPolicy(fromImage, imagePullManager, buildContext.getRegistryConfig(), queryService.hasImage(fromImage));
    }
}
Also used : BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

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