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
Expand Up @@ -117,6 +117,8 @@ public interface BuildImageCmd extends AsyncDockerCmd<BuildImageCmd, BuildRespon

BuildImageCmd withDockerfile(File dockerfile);

BuildImageCmd withDockerfilePath(String dockerfilePath);

BuildImageCmd withNoCache(Boolean noCache);

BuildImageCmd withRemove(Boolean rm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class BuildImageCmdImpl extends AbstrAsyncDockerCmd<BuildImageCmd, BuildR

private File dockerFile;

private String dockerFilePath;

private File baseDirectory;

private String cpusetcpus;
Expand Down Expand Up @@ -119,7 +121,9 @@ public Boolean hasPullEnabled() {

@Override
public String getPathToDockerfile() {
if (baseDirectory != null && dockerFile != null) {
if (dockerFilePath != null) {
return dockerFilePath;
} else if (baseDirectory != null && dockerFile != null) {
return FilePathUtil.relativize(baseDirectory, dockerFile);
} else {
return null;
Expand Down Expand Up @@ -287,6 +291,13 @@ public BuildImageCmdImpl withDockerfile(File dockerfile) {
return this;
}

@Override
public BuildImageCmd withDockerfilePath(String dockerfilePath) {
checkNotNull(dockerfilePath, "dockerfilePath is null");
this.dockerFilePath = dockerfilePath;
return this;
}

@Override
public BuildImageCmdImpl withTarInputStream(InputStream tarInputStream) {
checkNotNull(tarInputStream, "tarInputStream is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public void buildImageFromTar() throws Exception {
assertThat(response, containsString("Successfully executed testrun.sh"));
}

@Test
public void buildImageFromTarWithDockerfileNotInBaseDirectory() throws Exception {
File baseDir = fileFromBuildTestResource("dockerfileNotInBaseDirectory");
Collection<File> files = FileUtils.listFiles(baseDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
File tarFile = CompressArchiveUtil.archiveTARFiles(baseDir, files, UUID.randomUUID().toString());
String response = dockerfileBuild(new FileInputStream(tarFile), "dockerfileFolder/Dockerfile");
assertThat(response, containsString("Successfully executed testrun.sh"));
}

@Test
public void onBuild() throws Exception {
File baseDir = fileFromBuildTestResource("ONBUILD/parent");
Expand Down Expand Up @@ -123,6 +132,11 @@ public void addFolder() throws Exception {
assertThat(response, containsString("Successfully executed testAddFolder.sh"));
}

private String dockerfileBuild(InputStream tarInputStream, String dockerFilePath) throws Exception {

return execBuild(dockerClient.buildImageCmd().withTarInputStream(tarInputStream).withDockerfilePath(dockerFilePath));
}

private String dockerfileBuild(InputStream tarInputStream) throws Exception {

return execBuild(dockerClient.buildImageCmd().withTarInputStream(tarInputStream));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public void buildImageFromTar() throws Exception {
assertThat(response, containsString("Successfully executed testrun.sh"));
}

@Test
public void buildImageFromTarWithDockerfileNotInBaseDirectory() throws Exception {
File baseDir = fileFromBuildTestResource("dockerfileNotInBaseDirectory");
Collection<File> files = FileUtils.listFiles(baseDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
File tarFile = CompressArchiveUtil.archiveTARFiles(baseDir, files, UUID.randomUUID().toString());
String response = dockerfileBuild(new FileInputStream(tarFile), "dockerfileFolder/Dockerfile");
assertThat(response, containsString("Successfully executed testrun.sh"));
}

@Test
public void onBuild() throws Exception {
File baseDir = fileFromBuildTestResource("ONBUILD/parent");
Expand Down Expand Up @@ -128,6 +137,11 @@ public void addFolder() throws Exception {
assertThat(response, containsString("Successfully executed testAddFolder.sh"));
}

private String dockerfileBuild(InputStream tarInputStream, String dockerFilePath) throws Exception {

return execBuild(dockerClient.buildImageCmd().withTarInputStream(tarInputStream).withDockerfilePath(dockerFilePath));
}

private String dockerfileBuild(InputStream tarInputStream) throws Exception {

return execBuild(dockerClient.buildImageCmd().withTarInputStream(tarInputStream));
Expand Down