Search in sources :

Example 1 with ArchiveCompression

use of io.fabric8.maven.docker.config.ArchiveCompression in project docker-maven-plugin by fabric8io.

the class SaveMojo method executeInternal.

@Override
protected void executeInternal(ServiceHub serviceHub) throws DockerAccessException, MojoExecutionException {
    List<ImageConfiguration> images = getResolvedImages();
    if (skipSaveFor(images)) {
        return;
    }
    ImageConfiguration image = getImageToSave(images);
    String imageName = image.getName();
    String fileName = getFileName(imageName);
    ensureSaveDir(fileName);
    log.info("Saving image %s to %s", imageName, fileName);
    if (!serviceHub.getQueryService().hasImage(imageName)) {
        throw new MojoExecutionException("No image " + imageName + " exists");
    }
    long time = System.currentTimeMillis();
    ArchiveCompression compression = ArchiveCompression.fromFileName(fileName);
    serviceHub.getDockerAccess().saveImage(imageName, fileName, compression);
    log.info("%s: Saved image to %s in %s", imageName, fileName, EnvUtil.formatDurationTill(time));
    String classifier = getClassifier(image);
    if (classifier != null) {
        projectHelper.attachArtifact(project, compression.getFileSuffix(), classifier, new File(fileName));
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ArchiveCompression(io.fabric8.maven.docker.config.ArchiveCompression) File(java.io.File)

Example 2 with ArchiveCompression

use of io.fabric8.maven.docker.config.ArchiveCompression in project docker-maven-plugin by fabric8io.

the class ArchiveCompressionTest method fromFileName.

@Test
public void fromFileName() throws Exception {
    ArchiveCompression c = ArchiveCompression.fromFileName("test.tar");
    assertEquals("tar", c.getFileSuffix());
    c = ArchiveCompression.fromFileName("test.tar.bzip2");
    assertEquals("tar.bz", c.getFileSuffix());
    c = ArchiveCompression.fromFileName("test.tar.bz2");
    assertEquals("tar.bz", c.getFileSuffix());
    c = ArchiveCompression.fromFileName("test.tar.gz");
    assertEquals("tar.gz", c.getFileSuffix());
    c = ArchiveCompression.fromFileName("test.tgz");
    assertEquals("tar.gz", c.getFileSuffix());
}
Also used : ArchiveCompression(io.fabric8.maven.docker.config.ArchiveCompression) Test(org.junit.Test)

Example 3 with ArchiveCompression

use of io.fabric8.maven.docker.config.ArchiveCompression in project docker-maven-plugin by fabric8io.

the class DockerAccessWithHcClient method saveImage.

@Override
public void saveImage(String image, String filename, ArchiveCompression compression) throws DockerAccessException {
    ImageName name = new ImageName(image);
    String url = urlBuilder.getImage(name);
    try {
        delegate.get(url, getImageResponseHandler(filename, compression), HTTP_OK);
    } catch (IOException e) {
        throw new DockerAccessException(e, "Unable to save '%s' to '%s'", image, filename);
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) DockerAccessException(io.fabric8.maven.docker.access.DockerAccessException) IOException(java.io.IOException)

Aggregations

ArchiveCompression (io.fabric8.maven.docker.config.ArchiveCompression)2 DockerAccessException (io.fabric8.maven.docker.access.DockerAccessException)1 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)1 ImageName (io.fabric8.maven.docker.util.ImageName)1 File (java.io.File)1 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 Test (org.junit.Test)1