From 7521a5f9a9354b78d13163eb40c35e406ae4cf4b Mon Sep 17 00:00:00 2001 From: Ravi Chodavarapu Date: Sat, 1 Apr 2017 15:08:08 +0100 Subject: [PATCH 1/2] When supplying a TAR stream to the build command, API consumers just want to pass a String location of the Dockerfile within the TAR stream they are supplying --- .../dockerjava/api/command/BuildImageCmd.java | 2 ++ .../dockerjava/core/command/BuildImageCmdImpl.java | 13 ++++++++++++- .../core/command/BuildImageCmdImplTest.java | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java b/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java index ac98db2f9..0c9b7f5a4 100644 --- a/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java +++ b/src/main/java/com/github/dockerjava/api/command/BuildImageCmd.java @@ -117,6 +117,8 @@ public interface BuildImageCmd extends AsyncDockerCmd 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"); @@ -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)); From d0258631ce6e4b46c9533876aaf0c0bc9e715037 Mon Sep 17 00:00:00 2001 From: Ravi Chodavarapu Date: Wed, 5 Apr 2017 18:30:38 +0100 Subject: [PATCH 2/2] Add netty test for building with an explicitly specified Dockerfile location within a tar --- .../netty/exec/BuildImageCmdExecTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/com/github/dockerjava/netty/exec/BuildImageCmdExecTest.java b/src/test/java/com/github/dockerjava/netty/exec/BuildImageCmdExecTest.java index f567dcfc8..63fcf7ea1 100644 --- a/src/test/java/com/github/dockerjava/netty/exec/BuildImageCmdExecTest.java +++ b/src/test/java/com/github/dockerjava/netty/exec/BuildImageCmdExecTest.java @@ -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 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"); @@ -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));