public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
public String toImageRef() { return toString(); }
public ContainerBuilder addImage(String image) { configuration.setImage(Image.valueOf(image)); return this; }
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 static void setDefaultSeleniumCubeProperties(CubeContainer cubeContainer, int seleniumBoundedPort) { final ArrayList<PortBinding> portBindings = new ArrayList<>(); portBindings.add(PortBinding.valueOf(seleniumBoundedPort + "->4444")); final Image image = cubeContainer.getImage(); if (null != image && image.getName().toLowerCase().contains("debug")) { //Expose VNC portBindings.add(PortBinding.valueOf("5900->5900")); } cubeContainer.setPortBindings( portBindings ); Await await = new Await(); await.setStrategy("http"); await.setResponseCode(getSeleniumExpectedResponseCode()); await.setUrl("http://dockerHost:" + seleniumBoundedPort); cubeContainer.setAwait(await); cubeContainer.setKillContainer(true); }
@Test public void should_override_custom_cube_properties() 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("dockerContainersFiles", newFile.toURI().toString()); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); parameters.put("cubeSpecificProperties", OVERRIDE_CUSTOM); CubeDockerConfiguration cubeConfiguration = CubeDockerConfiguration.fromMap(parameters, null); final DockerCompositions dockerContainersContent = cubeConfiguration.getDockerContainersContent(); final CubeContainer tomcat = dockerContainersContent.get("tomcat"); assertThat(tomcat, is(notNullValue())); assertThat(tomcat.getImage().getTag(), is("7.0")); assertThat(tomcat.getAwait().getStrategy(), is("polling")); assertThat(tomcat.getBeforeStop().size(), is(1)); }
public ContainerBuilder addImage(String image) { configuration.setImage(Image.valueOf(image)); return this; }
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; }
public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
public ContainerOptionsBuilder fromImage(String image) { cubeContainer.setImage(Image.valueOf(image)); return new ContainerOptionsBuilder(); }
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)); }
public String toImageRef() { return toString(); }
public ContainerOptionsBuilder fromImage(String image) { cubeContainer.setImage(Image.valueOf(image)); return new ContainerOptionsBuilder(); }
@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 shouldCreateCustomContainerFromImageName() { when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(false); when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(true); when(cubeDroneConfiguration.getBrowserImage()).thenReturn("mycompany/mybrowser:1.0"); when(cubeDroneConfiguration.getContainerNameStrategy()).thenReturn(ContainerNameStrategy.STATIC); final SeleniumContainers firefox = SeleniumContainers.create("firefox", cubeDroneConfiguration); assertThat(firefox.getBrowser(), is("firefox")); assertThat(firefox.getSeleniumContainer().getImage().toString(), is("mycompany/mybrowser:1.0")); assertThat(firefox.getSeleniumContainer().getPortBindings(), hasItem(PortBinding.valueOf("14444->4444"))); }