Permalink
Browse files

Remove volumes when stopping containers

  • Loading branch information...
schrieveslaach committed Dec 24, 2018
1 parent d2e1380 commit 863f8e0564989ac423b1408bc8eb5c09fd8ec70b
@@ -28,26 +28,15 @@

import com.aixigo.preview.servant.rest.junit.extension.PREvantRestApiExtension;
import com.aixigo.preview.servant.rest.model.ServiceConfiguration;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import io.restassured.response.ResponseBodyExtractionOptions;
import io.restassured.response.ValidatableResponse;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.support.io.TempDirectory;
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
import org.junit.rules.TemporaryFolder;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static io.restassured.RestAssured.given;
@@ -53,10 +53,7 @@ pub struct ServiceConfig {
}

impl ServiceConfig {
pub fn new(
service_name: &String,
image_repository: &String,
) -> ServiceConfig {
pub fn new(service_name: &String, image_repository: &String) -> ServiceConfig {
ServiceConfig {
service_name: service_name.clone(),
image_repository: image_repository.clone(),
@@ -281,12 +281,12 @@ impl DockerInfrastructure {
&ContainerOptions::builder("bash")
.volumes(vec![&volume])
.cmd(vec!["sh", "-c", &cmd])
// TODO: use auto remove: https://github.com/softprops/shiplift/pull/137
.auto_remove(true)
.build(),
)
.map(move |info| {
let docker = Docker::new();
tokio::spawn(
tokio::run(
docker
.containers()
.get(&info.id)
@@ -465,11 +465,33 @@ impl Infrastructure for DockerInfrastructure {
let container = docker.containers().get(&id);

let id_clone = id.clone();
container.stop(None).map(move |_| id_clone).and_then(|id| {
let docker = Docker::new();
let container = docker.containers().get(&id);
container.delete()
})
container
.stop(None)
.map(move |_| {
let docker = Docker::new();
let container = docker.containers().get(&id_clone);

container
.inspect()
.map(|container_details| container_details)
})
.and_then(|container_details| container_details)
.and_then(|container_details| {
let docker = Docker::new();
let container = docker.containers().get(&container_details.id);

for mount in container_details.mounts {
tokio::run(
docker
.volumes()
.get(&mount.source)
.delete()
.map_err(|err| error!("Cannot delete volume: {}", err)),
);
}

container.delete()
})
}) {
futures.push(f);
}
@@ -521,7 +543,8 @@ impl Infrastructure for DockerInfrastructure {

let (repo, user, registry, tag) =
models::service::parse_image_string(&container_details.image).unwrap();
let mut service_config = ServiceConfig::new(service.get_service_name(), &repo);
let mut service_config =
ServiceConfig::new(service.get_service_name(), &repo);

service_config.set_image_user(&user);
service_config.set_registry(&registry);

0 comments on commit 863f8e0

Please sign in to comment.