private void prepareImageBuild() throws InvocationTargetException, IllegalAccessException, IOException { // @CubeDockerfile is defined as static method if (classHasMethodWithCubeDockerFile) { cubeDockerFileAnnotation = methodWithCubeDockerFile.getAnnotation(CubeDockerFile.class); final Archive<?> archive = (Archive<?>) methodWithCubeDockerFile.invoke(null, new Object[0]); File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); archive.as(ExplodedExporter.class).exportExplodedInto(output); dockerfileLocation = output; } else if (classDefinesCubeDockerFile) { cubeDockerFileAnnotation = containerObjectClass.getAnnotation(CubeDockerFile.class); //Copy Dockerfile and all contains of the same directory in a known directory. File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); DockerFileUtil.copyDockerfileDirectory(containerObjectClass, cubeDockerFileAnnotation, output); dockerfileLocation = output; } else if (classDefinesImage) { cubeImageAnnotation = containerObjectClass.getAnnotation(Image.class); } }
private void prepareImageBuild() throws InvocationTargetException, IllegalAccessException, IOException { // @CubeDockerfile is defined as static method if (classHasMethodWithCubeDockerFile) { cubeDockerFileAnnotation = methodWithCubeDockerFile.getAnnotation(CubeDockerFile.class); final Archive<?> archive = (Archive<?>) methodWithCubeDockerFile.invoke(null, new Object[0]); File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); archive.as(ExplodedExporter.class).exportExplodedInto(output); dockerfileLocation = output; } else if (classDefinesCubeDockerFile) { cubeDockerFileAnnotation = containerObjectClass.getAnnotation(CubeDockerFile.class); //Copy Dockerfile and all contains of the same directory in a known directory. File output = createTemporalDirectoryForCopyingDockerfile(containerName); logger.finer(String.format("Created %s directory for storing contents of %s cube.", output, containerName)); DockerFileUtil.copyDockerfileDirectory(containerObjectClass, cubeDockerFileAnnotation, output); dockerfileLocation = output; } else if (classDefinesImage) { cubeImageAnnotation = containerObjectClass.getAnnotation(Image.class); } }
@Test public void shouldCopyDockerfileFromDefaultLocation() throws IOException { File outputDir = folder.newFolder(); DockerFileUtil.copyDockerfileDirectory(TestLocalDockerFile.class, TestLocalDockerFile.class.getAnnotation(CubeDockerFile.class), outputDir); Assert.assertThat(new File(outputDir, "Dockerfile").exists(), Is.is(true)); }
@Test public void shouldCopyDockerfileFromJarLocation() throws IOException, ClassNotFoundException { //Creates a jar file with required content JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addClass(CustomTestJarDockerfiler.class) .addClasses(CubeDockerFile.class) .addAsResource( new StringAsset("FROM java:8-jre"), "/test/Dockerfile" ); File jarDirectory = folder.newFolder(); File jarFile = new File(jarDirectory, "test.jar"); jar.as(ZipExporter.class).exportTo(jarFile); //Creates a class loader that depends on the system one loading the jar. Jars are isolated from the test ones. ClassLoader classloader = new URLClassLoader(new URL[] {jarFile.toURI().toURL()}, null); Class<?> clazz = (Class<?>) Class.forName("org.arquillian.cube.docker.impl.util.DockerFileUtilTest$CustomTestJarDockerfiler", true, classloader); //Executes the test File outputDir = folder.newFolder(); DockerFileUtil.copyDockerfileDirectory(clazz, CustomTestJarDockerfiler.class.getAnnotation(CubeDockerFile.class), outputDir); Assert.assertThat(new File(outputDir, "Dockerfile").exists(), Is.is(true)); }
@Test public void shouldCopyDockerfileFromDefaultJar() throws IOException, ClassNotFoundException { //Creates a jar file with required content JavaArchive jar = ShrinkWrap.create(JavaArchive.class) .addClass(TestJarDockerFile.class) .addClasses(CubeDockerFile.class) .addAsResource( new StringAsset("FROM java:8-jre"), "/org/arquillian/cube/docker/impl/util/DockerFileUtilTest/TestJarDockerFile/Dockerfile" ); File jarDirectory = folder.newFolder(); File jarFile = new File(jarDirectory, "test.jar"); jar.as(ZipExporter.class).exportTo(jarFile); //Creates a class loader that depends on the system one loading the jar. Jars are isolated from the test ones. ClassLoader classloader = new URLClassLoader(new URL[] {jarFile.toURI().toURL()}, null); Class<?> clazz = (Class<?>) Class.forName("org.arquillian.cube.docker.impl.util.DockerFileUtilTest$TestJarDockerFile", true, classloader); //Executes the test File outputDir = folder.newFolder(); DockerFileUtil.copyDockerfileDirectory(clazz, TestJarDockerFile.class.getAnnotation(CubeDockerFile.class), outputDir); Assert.assertThat(new File(outputDir, "Dockerfile").exists(), Is.is(true)); }