Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.dockerjava.api.command;

public interface DockerCmd<RES_T> {
import java.io.Closeable;

public interface DockerCmd<RES_T> extends Closeable {

public RES_T exec();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.dockerjava.core.command;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,4 +27,7 @@ public RES_T exec() throws DockerException {
LOGGER.debug("Cmd: {}", this);
return execution.exec((CMD_T)this);
}
}

@Override
public void close() throws IOException {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class BuildImageCmdImpl extends AbstrDockerCmd<BuildImageCmd, InputStream
.compile("^ENV\\s+(.*)\\s+(.*)$");

private InputStream tarInputStream = null;
private File tarFile = null;
private String tag;
private boolean noCache;
private boolean remove = true;
Expand All @@ -48,7 +49,13 @@ public class BuildImageCmdImpl extends AbstrDockerCmd<BuildImageCmd, InputStream
public BuildImageCmdImpl(BuildImageCmd.Exec exec, File dockerFolder) {
super(exec);
Preconditions.checkNotNull(dockerFolder, "dockerFolder is null");
withTarInputStream(buildDockerFolderTar(dockerFolder));
tarFile = buildDockerFolderTar(dockerFolder);
try {
withTarInputStream(FileUtils.openInputStream(tarFile));
} catch (IOException e) {
// we just created the file this should never happen.
throw new RuntimeException(e);
}
}

public BuildImageCmdImpl(BuildImageCmd.Exec exec, InputStream tarInputStream) {
Expand Down Expand Up @@ -129,6 +136,14 @@ public BuildImageCmdImpl withQuiet(boolean quiet) {
return this;
}

@Override
public void close() throws IOException {
super.close();
if (tarFile != null) {
FileUtils.deleteQuietly(tarFile);
}
}

@Override
public String toString() {
return new StringBuilder("build ")
Expand All @@ -139,7 +154,7 @@ public String toString() {
.toString();
}

protected InputStream buildDockerFolderTar(File dockerFolder) {
protected File buildDockerFolderTar(File dockerFolder) {
Preconditions.checkArgument(dockerFolder.exists(),
"Path %s doesn't exist", dockerFolder);
Preconditions.checkArgument(dockerFolder.isDirectory(),
Expand Down Expand Up @@ -255,9 +270,8 @@ protected InputStream buildDockerFolderTar(File dockerFolder) {
}
}

dockerFolderTar = CompressArchiveUtil.archiveTARFiles(dockerFolder,
return CompressArchiveUtil.archiveTARFiles(dockerFolder,
filesToAdd, archiveNameWithOutExtension);
return FileUtils.openInputStream(dockerFolderTar);
} catch (IOException ex) {
FileUtils.deleteQuietly(dockerFolderTar);
throw new DockerClientException(
Expand Down