[test/plugin] remove the image on docker exit (#4374)
* remove image on docker exit * polish
This commit is contained in:
parent
334239388a
commit
ca6a5618c5
|
|
@ -92,7 +92,7 @@ public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
|
|||
}
|
||||
|
||||
protected List<DockerService> convertDockerServices(final String version,
|
||||
Map<String, DependencyComponent> componentMap) {
|
||||
Map<String, DependencyComponent> componentMap) {
|
||||
ArrayList<DockerService> services = Lists.newArrayList();
|
||||
componentMap.forEach((name, dependency) -> {
|
||||
DockerService service = new DockerService();
|
||||
|
|
@ -108,6 +108,7 @@ public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
|
|||
service.setEntrypoint(dependency.getEntrypoint());
|
||||
service.setHealthcheck(dependency.getHealthcheck());
|
||||
service.setEnvironment(dependency.getEnvironment());
|
||||
service.setRemoveOnExit(dependency.getRemoveOnExit());
|
||||
services.add(service);
|
||||
});
|
||||
return services;
|
||||
|
|
@ -124,6 +125,17 @@ public class DockerComposeRunningGenerator extends AbstractRunningGenerator {
|
|||
root.put("docker_compose_file", docker_compose_file);
|
||||
root.put("build_id", configuration.dockerImageVersion());
|
||||
root.put("docker_container_name", configuration.dockerContainerName());
|
||||
|
||||
StringBuilder removeImagesScript = new StringBuilder();
|
||||
configuration.caseConfiguration().getDependencies().forEach((name, service) -> {
|
||||
if (service.getRemoveOnExit()) {
|
||||
removeImagesScript.append("docker rmi ")
|
||||
.append(service.getImage().replace("${CASE_SERVER_IMAGE_VERSION}", configuration.scenarioVersion()))
|
||||
.append(System.lineSeparator());
|
||||
}
|
||||
});
|
||||
root.put("removeImagesScript", removeImagesScript.toString());
|
||||
|
||||
StringWriter out = null;
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class DependencyComponent {
|
|||
private String image;
|
||||
private String hostname;
|
||||
private String version;
|
||||
private boolean removeOnExit = false;
|
||||
private List<String> startScript;
|
||||
private List<String> links;
|
||||
private List<String> expose;
|
||||
|
|
@ -110,4 +111,12 @@ public class DependencyComponent {
|
|||
public void setStartScript(List<String> startScript) {
|
||||
this.startScript = startScript;
|
||||
}
|
||||
|
||||
public boolean getRemoveOnExit() {
|
||||
return removeOnExit;
|
||||
}
|
||||
|
||||
public void setRemoveOnExit(final boolean removeOnExit) {
|
||||
this.removeOnExit = removeOnExit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class DockerService {
|
|||
private String name;
|
||||
private String imageName;
|
||||
private String hostname;
|
||||
private boolean removeOnExit;
|
||||
private List<String> startScript;
|
||||
private List<String> links;
|
||||
private List<String> expose;
|
||||
|
|
@ -110,4 +111,12 @@ public class DockerService {
|
|||
public void setStartScript(List<String> startScript) {
|
||||
this.startScript = startScript;
|
||||
}
|
||||
|
||||
public boolean getRemoveOnExit() {
|
||||
return removeOnExit;
|
||||
}
|
||||
|
||||
public void setRemoveOnExit(final boolean removeOnExit) {
|
||||
this.removeOnExit = removeOnExit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,4 +36,6 @@ else
|
|||
docker-compose -p ${project_name} -f ${compose_file} kill
|
||||
docker-compose -p ${project_name} -f ${compose_file} rm -f
|
||||
fi
|
||||
</#noparse>
|
||||
</#noparse>
|
||||
|
||||
${removeImagesScript}
|
||||
|
|
@ -58,6 +58,9 @@ services:
|
|||
${service.name}:
|
||||
image: ${service.imageName}
|
||||
hostname: ${service.hostname}
|
||||
<#if service.remoteOnExit??>
|
||||
remoteOnExit: ${service.remoteOnExit}
|
||||
</#if>
|
||||
<#if service.volumes??>
|
||||
volumes:
|
||||
<#list service.volumes as volume>
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ dependencies:
|
|||
elasticsearch-server-5.x:
|
||||
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.0
|
||||
hostname: elasticsearch-server-5.x
|
||||
removeOnExit: true
|
||||
expose:
|
||||
- 9300
|
||||
- 9200
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ dependencies:
|
|||
elasticsearch-server-6.x:
|
||||
image: elasticsearch:${CASE_SERVER_IMAGE_VERSION}
|
||||
hostname: elasticsearch-server-6.x
|
||||
removeOnExit: true
|
||||
expose:
|
||||
- 9200
|
||||
environment:
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ dependencies:
|
|||
elasticsearch-server-7.x:
|
||||
image: elasticsearch:${CASE_SERVER_IMAGE_VERSION}
|
||||
hostname: elasticsearch-server-7.x
|
||||
removeOnExit: true
|
||||
expose:
|
||||
- 9200
|
||||
environment:
|
||||
|
|
|
|||
Loading…
Reference in New Issue