@Test public void should_not_remove_docker_image_as_not_built_by_cube() { DockerClientExecutor executor = Mockito.mock(DockerClientExecutor.class); String config = "pingpong:\n" + " image: jonmorehouse/ping-pong\n" + " exposedPorts: [8080/tcp]\n" + " portBindings: [8080->8080/tcp]\n"; Map<String, String> parameters = new HashMap<>(); parameters.put("dockerContainers", config); parameters.put("definitionFormat", DefinitionFormat.CUBE.name()); CubeConfiguration cubeConfiguration = CubeConfiguration.fromMap(new HashMap<String, String>()); bind(ApplicationScoped.class, CubeConfiguration.class, cubeConfiguration); CubeDockerConfiguration dockerConfiguration = CubeDockerConfiguration.fromMap(parameters, null); when(cube.getId()).thenReturn(CUBE_ID); when(cube.configuration()).thenReturn(dockerConfiguration.getDockerContainersContent().get(CUBE_ID)); bind(ApplicationScoped.class, CubeDockerConfiguration.class, dockerConfiguration); final LocalCubeRegistry localCubeRegistry = new LocalCubeRegistry(); localCubeRegistry.addCube(cube); bind(ApplicationScoped.class, CubeRegistry.class, localCubeRegistry); bind(ApplicationScoped.class, DockerClientExecutor.class, executor); fire(new AfterDestroy(CUBE_ID)); Mockito.verify(executor, never()).removeImage("pingpong:latest", false); }
public void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration) { if (configuration.isCleanBuildImage()) { String cubeId = event.getCubeId(); Cube cube = registry.getCube(cubeId); if (cube == null) { throw new IllegalArgumentException("No cube with id " + cubeId + " found in registry"); } if (cube.configuration() instanceof CubeContainer) { CubeContainer config = (CubeContainer) cube.configuration(); if (config.getBuildImage() != null) { String imageRef = event.getCubeId() + TAG; DockerClientExecutor executor = dockerClientExecutorInstance.get(); executor.removeImage(imageRef, false); } } } }
DockerImageController { public void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration) { if (configuration.isCleanBuildImage()) { String cubeId = event.getCubeId(); Cube cube = registry.getCube(cubeId); if (cube == null) { throw new IllegalArgumentException("No cube with id " + cubeId + " found in registry"); } if (cube.configuration() instanceof CubeContainer) { CubeContainer config = (CubeContainer) cube.configuration(); if (config.getBuildImage() != null) { String imageRef = event.getCubeId() + TAG; DockerClientExecutor executor = dockerClientExecutorInstance.get(); executor.removeImage(imageRef, false); } } } } }
DockerImageController { public void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration) { if (configuration.isCleanBuildImage()) { String cubeId = event.getCubeId(); Cube cube = registry.getCube(cubeId); if (cube == null) { throw new IllegalArgumentException("No cube with id " + cubeId + " found in registry"); } if (cube.configuration() instanceof CubeContainer) { CubeContainer config = (CubeContainer) cube.configuration(); if (config.getBuildImage() != null) { String imageRef = event.getCubeId() + TAG; DockerClientExecutor executor = dockerClientExecutorInstance.get(); executor.removeImage(imageRef, false); } } } }  }
DockerImageController { public void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration) { if (configuration.isCleanBuildImage()) { String cubeId = event.getCubeId(); Cube cube = registry.getCube(cubeId); if (cube == null) { throw new IllegalArgumentException("No cube with id " + cubeId + " found in registry"); } if (cube.configuration() instanceof CubeContainer) { CubeContainer config = (CubeContainer) cube.configuration(); if (config.getBuildImage() != null) { String imageRef = event.getCubeId() + TAG; DockerClientExecutor executor = dockerClientExecutorInstance.get(); executor.removeImage(imageRef, false); } } } }  void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration); }
DockerImageController { public void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration) { if (configuration.isCleanBuildImage()) { String cubeId = event.getCubeId(); Cube cube = registry.getCube(cubeId); if (cube == null) { throw new IllegalArgumentException("No cube with id " + cubeId + " found in registry"); } if (cube.configuration() instanceof CubeContainer) { CubeContainer config = (CubeContainer) cube.configuration(); if (config.getBuildImage() != null) { String imageRef = event.getCubeId() + TAG; DockerClientExecutor executor = dockerClientExecutorInstance.get(); executor.removeImage(imageRef, false); } } } }  void removeImage(@Observes AfterDestroy event, CubeRegistry registry, CubeDockerConfiguration configuration);  }