All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.mike10004.containment.dockerjava.DjContainerCopier Maven / Gradle / Ivy

package io.github.mike10004.containment.dockerjava;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.exception.DockerException;
import com.google.common.io.ByteStreams;
import io.github.mike10004.containment.ContainerCopier;
import io.github.mike10004.containment.ContainerInfo;
import io.github.mike10004.containment.ContainmentException;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.io.FilenameUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;

import static java.util.Objects.requireNonNull;

class DjContainerCopier implements ContainerCopier {

    private final DockerClient client;
    private final ContainerInfo containerInfo;

    public DjContainerCopier(DockerClient client, ContainerInfo containerInfo) {
        this.client = requireNonNull(client);
        this.containerInfo = requireNonNull(containerInfo);
    }

    @Override
    public void copyToContainer(File srcFile, String destinationPathname) throws IOException, ContainmentException {
        try {
            client.copyArchiveToContainerCmd(containerInfo.id())
                    .withHostResource(srcFile.getAbsolutePath())
                    .withRemotePath(destinationPathname)
                    .withNoOverwriteDirNonDir(true)
                    .exec();
        } catch (DockerException e) {
            throw new ContainmentException(e);
        }
    }

    @Override
    public void copyFromContainer(String path, File destinationFile, Set




© 2015 - 2024 Weber Informatics LLC | Privacy Policy