private String getImageName(CubeContainer containerConfiguration, String name) { String image; if (containerConfiguration.getImage() != null) { image = containerConfiguration.getImage().toImageRef(); } else { if (containerConfiguration.getBuildImage() != null) { BuildImage buildImage = containerConfiguration.getBuildImage(); if (buildImage.getDockerfileLocation() != null) { Map<String, Object> params = new HashMap<String, Object>(); //(containerConfiguration, BUILD_IMAGE); params.put("noCache", buildImage.isNoCache()); params.put("remove", buildImage.isRemove()); params.put("dockerFileLocation", buildImage.getDockerfileLocation()); params.put("dockerFileName", buildImage.getDockerfileName()); image = this.buildImage(buildImage.getDockerfileLocation(), name, params); } else { throw new IllegalArgumentException( "A tar file with Dockerfile on root or a directory with a Dockerfile should be provided."); } } else { throw new IllegalArgumentException( String.format( "Current configuration file does not contain %s nor %s parameter and one of both should be provided.", IMAGE, BUILD_IMAGE)); } } return image; }
private String getImageName(CubeContainer containerConfiguration, String name) { String image; if (containerConfiguration.getImage() != null) { image = containerConfiguration.getImage().toImageRef(); } else { if (containerConfiguration.getBuildImage() != null) { BuildImage buildImage = containerConfiguration.getBuildImage(); if (buildImage.getDockerfileLocation() != null) { Map<String, Object> params = new HashMap<String, Object>(); //(containerConfiguration, BUILD_IMAGE); params.put("noCache", buildImage.isNoCache()); params.put("remove", buildImage.isRemove()); params.put("dockerFileLocation", buildImage.getDockerfileLocation()); params.put("dockerFileName", buildImage.getDockerfileName()); image = this.buildImage(buildImage.getDockerfileLocation(), name, params); } else { throw new IllegalArgumentException( "A tar file with Dockerfile on root or a directory with a Dockerfile should be provided."); } } else { throw new IllegalArgumentException( String.format( "Current configuration file does not contain %s nor %s parameter and one of both should be provided.", IMAGE, BUILD_IMAGE)); } } return image; }
private void testResolvePlaceholders(String dockerComposeFile, String expectedImageName) throws URISyntaxException, IOException { URI readEnvsDockerCompose = DockerComposeConverterTest.class.getResource(dockerComposeFile).toURI(); DockerComposeConverter dockerComposeConverter = DockerComposeConverter.create(Paths.get(readEnvsDockerCompose)); DockerCompositions convert = dockerComposeConverter.convert(); CubeContainer webapp = convert.get("webapp2"); assertThat(webapp.getImage(), is(notNullValue())); final String image = webapp.getImage().toImageRef(); assertThat(image, is(expectedImageName)); }
@Test public void should_load_cube_configuration_from_cube_file_if_no_file_is_provided() { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("serverVersion", "1.13"); parameters.put("serverUri", "http://localhost:25123"); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); CubeContainer actualTomcat = dockerContainersContent.get("tomcat"); assertThat(actualTomcat, is(notNullValue())); String image = actualTomcat.getImage().toImageRef(); assertThat(image, is("tomcat:7.0")); }
@Test public void should_parse_and_load_configuration_file_from_container_configuration_file() throws IOException { File newFile = testFolder.newFile("config.yaml"); Files.write(Paths.get(newFile.toURI()), CONTENT.getBytes()); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("serverVersion", "1.13"); parameters.put("serverUri", "http://localhost:25123"); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); parameters.put("dockerContainersFile", newFile.toURI().toString()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); assertThat(cubeConfiguration.getDockerServerUri(), is("http://localhost:25123")); assertThat(cubeConfiguration.getDockerServerVersion(), is("1.13")); DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); CubeContainer actualTomcat = dockerContainersContent.get("tomcat"); assertThat(actualTomcat, is(notNullValue())); String image = actualTomcat.getImage().toImageRef(); assertThat(image, is("tutum/tomcat:7.0")); }
@Test public void should_parse_and_load_configuration_file_from_container_configuration_file_and_property_set_file() throws IOException { File newFile = testFolder.newFile("config.yml"); Files.write(Paths.get(newFile.toURI()), CONTENT.getBytes()); File newFile2 = testFolder.newFile("config.demo.yml"); Files.write(Paths.get(newFile2.toURI()), CONTENT2.getBytes()); System.setProperty("cube.environment", "demo"); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("serverVersion", "1.13"); parameters.put("serverUri", "http://localhost:25123"); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); parameters.put("dockerContainersFile", newFile.toURI().toString()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); assertThat(cubeConfiguration.getDockerServerUri(), is("http://localhost:25123")); assertThat(cubeConfiguration.getDockerServerVersion(), is("1.13")); DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); CubeContainer actualTomcat = dockerContainersContent.get("tomcat"); assertThat(actualTomcat, is(notNullValue())); String image = actualTomcat.getImage().toImageRef(); assertThat(image, is("tutum/tomcat:7.0")); assertThat(dockerContainersContent.get("tomcat2"), is(notNullValue())); }
@Test public void should_parse_and_load_configuration_file() { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("serverVersion", "1.13"); parameters.put("serverUri", "http://localhost:25123"); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); parameters.put("dockerContainers", CONTENT); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); assertThat(cubeConfiguration.getDockerServerUri(), is("http://localhost:25123")); assertThat(cubeConfiguration.getDockerServerVersion(), is("1.13")); DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); CubeContainer actualTomcat = dockerContainersContent.get("tomcat"); assertThat(actualTomcat, is(notNullValue())); String image = actualTomcat.getImage().toImageRef(); assertThat(image, is("tutum/tomcat:7.0")); }
@Test public void should_parse_and_load_configuration_from_container_configuration_resource() throws IOException { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("serverVersion", "1.13"); parameters.put("serverUri", "http://localhost:25123"); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); parameters.put("dockerContainersResource", "test-topologies/topology1.yaml"); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); assertThat(cubeConfiguration.getDockerServerUri(), is("http://localhost:25123")); assertThat(cubeConfiguration.getDockerServerVersion(), is("1.13")); DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); CubeContainer actualTomcat = dockerContainersContent.get("tomcat"); assertThat(actualTomcat, is(notNullValue())); String image = actualTomcat.getImage().toImageRef(); assertThat(image, is("tutum/tomcat:7.0")); }
@Test public void shouldStartAContainerObjectDefinedAsImage() { CubeContainerObjectTestEnricher cubeContainerObjectTestEnricher = new CubeContainerObjectTestEnricher(); cubeContainerObjectTestEnricher.containerObjectFactoryInstance = () -> dockerContainerObjectFactory; when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(cubeContainerObjectTestEnricher)); FourthInjectableTest injectableTest = new FourthInjectableTest(); cubeContainerObjectTestEnricher.enrich(injectableTest); final org.arquillian.cube.spi.Cube<?> image = cubeRegistry.getCube("image"); assertThat(image, is(notNullValue())); assertThat(image.hasMetadata(IsContainerObject.class), is(true)); assertThat(image.getMetadata(IsContainerObject.class).getTestClass().getName(), is(FourthInjectableTest.class.getName())); verify(cubeController, times(1)).start("image"); verify(cubeController, times(1)).create("image"); DockerCube dockerCube = (DockerCube) image; assertThat(dockerCube.configuration().getImage().toImageRef(), is("tomee:8-jre-1.7.2-webprofile")); }
@Test public void shouldStartAContainerObjectDefinedUsingImage() { final AtomicReference<DockerCube> cubeRef = new AtomicReference<>(); try { TestContainerObjectDefinedUsingImage containerObject = new DockerContainerObjectBuilder<TestContainerObjectDefinedUsingImage>(dockerClientExecutor, cubeController, cubeRegistry) .withContainerObjectClass(TestContainerObjectDefinedUsingImage.class) .onCubeCreated(cubeRef::set) .build(); assertThat(containerObject, is(notNullValue())); } catch (IllegalAccessException|InvocationTargetException|IOException e) { fail(); } DockerCube cube = cubeRef.get(); assertThat(cube, is(notNullValue())); assertThat(cube.hasMetadata(IsContainerObject.class), is(true)); assertThat(cube.getMetadata(IsContainerObject.class).getTestClass(), is(nullValue())); assertThat(cube.configuration().getImage().toImageRef(), is(BASE_IMAGE)); verify(cubeController, times(1)).create("containerDefinedUsingImage"); verify(cubeController, times(1)).start("containerDefinedUsingImage"); }
@Test public void shouldStartAContainerObjectDefinedAsImageAndEnvironmentVariables() { CubeContainerObjectTestEnricher cubeContainerObjectTestEnricher = new CubeContainerObjectTestEnricher(); cubeContainerObjectTestEnricher.containerObjectFactoryInstance = () -> dockerContainerObjectFactory; when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(cubeContainerObjectTestEnricher)); FifthInjectableTest injectableTest = new FifthInjectableTest(); cubeContainerObjectTestEnricher.enrich(injectableTest); final org.arquillian.cube.spi.Cube<?> image = cubeRegistry.getCube("image"); assertThat(image, is(notNullValue())); assertThat(image.hasMetadata(IsContainerObject.class), is(true)); assertThat(image.getMetadata(IsContainerObject.class).getTestClass().getName(), is(FifthInjectableTest.class.getName())); verify(cubeController, times(1)).start("image"); verify(cubeController, times(1)).create("image"); DockerCube dockerCube = (DockerCube) image; assertThat(dockerCube.configuration().getImage().toImageRef(), is("tomee:8-jre-1.7.2-webprofile")); assertThat(dockerCube.configuration().getEnv(), hasItems("a=b", "c=d")); }
@Test public void shouldStartAContainerObjectDefinedAsImageAndVolumesVariables() { CubeContainerObjectTestEnricher cubeContainerObjectTestEnricher = new CubeContainerObjectTestEnricher(); cubeContainerObjectTestEnricher.containerObjectFactoryInstance = () -> dockerContainerObjectFactory; when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(cubeContainerObjectTestEnricher)); SixthInjectableTest injectableTest = new SixthInjectableTest(); cubeContainerObjectTestEnricher.enrich(injectableTest); final org.arquillian.cube.spi.Cube<?> image = cubeRegistry.getCube("image"); assertThat(image, is(notNullValue())); assertThat(image.hasMetadata(IsContainerObject.class), is(true)); assertThat(image.getMetadata(IsContainerObject.class).getTestClass().getName(), is(SixthInjectableTest.class.getName())); verify(cubeController, times(1)).start("image"); verify(cubeController, times(1)).create("image"); DockerCube dockerCube = (DockerCube) image; assertThat(dockerCube.configuration().getImage().toImageRef(), is("tomee:8-jre-1.7.2-webprofile")); assertThat(dockerCube.configuration().getBinds(), hasItems("/mypath:/containerPath:Z", "/mypath2:/containerPath2:Z")); }
@Test public void should_be_able_to_extend_and_override_toplevel() throws Exception { String config = "tomcat6:\n" + " image: tutum/tomcat:6.0\n" + " exposedPorts: [8089/tcp]\n" + " await:\n" + " strategy: static\n" + " ip: localhost\n" + " ports: [8080, 8089]\n" + "tomcat7:\n" + " extends: tomcat6\n" + " image: tutum/tomcat:7.0\n"; Map<String, String> parameters = new HashMap<String, String>(); parameters.put("dockerContainers", config); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); CubeContainer tomcat7 = cubeConfiguration.getDockerContainersContent().get("tomcat7"); Assert.assertEquals("tutum/tomcat:7.0", tomcat7.getImage().toImageRef()); Assert.assertTrue(tomcat7.getAwait() != null); Assert.assertEquals("8089/tcp", tomcat7.getExposedPorts().iterator().next().toString()); }
@Test public void shouldStartAContainerObjectDefinedUsingImageAndVolumes() { final AtomicReference<DockerCube> cubeRef = new AtomicReference<>(); try { CubeContainer ccconfig = new CubeContainer(); ccconfig.setBinds(Collections.singleton("/mypath3:/containerPath3:Z")); CubeContainerObjectConfiguration ccoconfig = new CubeContainerObjectConfiguration(ccconfig); TestContainerObjectDefinedUsingImageAndVolumes containerObject = new DockerContainerObjectBuilder<TestContainerObjectDefinedUsingImageAndVolumes>(dockerClientExecutor, cubeController, cubeRegistry) .withContainerObjectClass(TestContainerObjectDefinedUsingImageAndVolumes.class) .withContainerObjectConfiguration(ccoconfig) .onCubeCreated(cubeRef::set) .build(); assertThat(containerObject, is(notNullValue())); } catch (IllegalAccessException|InvocationTargetException|IOException e) { fail(); } DockerCube cube = cubeRef.get(); assertThat(cube, is(notNullValue())); assertThat(cube.hasMetadata(IsContainerObject.class), is(true)); assertThat(cube.getMetadata(IsContainerObject.class).getTestClass(), is(nullValue())); assertThat(cube.configuration().getImage().toImageRef(), is(BASE_IMAGE)); assertThat(cube.configuration().getBinds(), hasItems("/mypath:/containerPath:Z", "/mypath2:/containerPath2:Z", "/mypath3:/containerPath3:Z")); verify(cubeController, times(1)).create("containerWithVolumes"); verify(cubeController, times(1)).start("containerWithVolumes"); }
@Test public void shouldStartAContainerObjectDefinedUsingImageAndEnvironmentVariables() { final AtomicReference<DockerCube> cubeRef = new AtomicReference<>(); try { CubeContainer ccconfig = new CubeContainer(); ccconfig.setEnv(Collections.singleton("e=f")); CubeContainerObjectConfiguration ccoconfig = new CubeContainerObjectConfiguration(ccconfig); TestContainerObjectDefinedUsingImageAndEnvironmentVariables containerObject = new DockerContainerObjectBuilder<TestContainerObjectDefinedUsingImageAndEnvironmentVariables>(dockerClientExecutor, cubeController, cubeRegistry) .withContainerObjectClass(TestContainerObjectDefinedUsingImageAndEnvironmentVariables.class) .withContainerObjectConfiguration(ccoconfig) .onCubeCreated(cubeRef::set) .build(); assertThat(containerObject, is(notNullValue())); } catch (IllegalAccessException|InvocationTargetException|IOException e) { fail(); } DockerCube cube = cubeRef.get(); assertThat(cube, is(notNullValue())); assertThat(cube.hasMetadata(IsContainerObject.class), is(true)); assertThat(cube.getMetadata(IsContainerObject.class).getTestClass(), is(nullValue())); assertThat(cube.configuration().getImage().toImageRef(), is(BASE_IMAGE)); assertThat(cube.configuration().getEnv(), hasItems("a=b", "c=d", "e=f")); verify(cubeController, times(1)).create("containerWithEnvironmentVariables"); verify(cubeController, times(1)).start("containerWithEnvironmentVariables"); }