Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize all Docker Compose operations #226

Merged
merged 1 commit into from
Sep 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class DockerComposeContainer<SELF extends DockerComposeContainer<SELF>> e
private Map<String, Integer> scalingPreferences = new HashMap<>();
private DockerClient dockerClient;

private static final Object MUTEX = new Object();

/**
* Properties that should be passed through to all Compose and ambassador containers (not
* necessarily to containers that are spawned by Compose itself)
Expand Down Expand Up @@ -79,12 +81,13 @@ public void starting(Description description) {
profiler.setLogger(logger());
profiler.start("Docker compose container startup");

pullImages();
applyScaling(); // scale before up, so that all scaled instances are available first for linking
createServices();
registerContainersForShutdown();
startAmbassadorContainers(profiler);

synchronized (MUTEX) {
pullImages();
applyScaling(); // scale before up, so that all scaled instances are available first for linking
createServices();
registerContainersForShutdown();
startAmbassadorContainers(profiler);
}
}

private void pullImages() {
Expand Down Expand Up @@ -184,19 +187,22 @@ private Logger logger() {
@Override @VisibleForTesting
public void finished(Description description) {

// shut down all the ambassador containers
ambassadorContainers.forEach((String address, AmbassadorContainer container) -> container.stop());

// Kill the services using docker-compose
getDockerCompose("down -v")
.start();
synchronized (MUTEX) {
// shut down all the ambassador containers
ambassadorContainers.forEach((String address, AmbassadorContainer container) -> container.stop());

// remove the networks before removing the containers
ResourceReaper.instance().removeNetworks(identifier);
// Kill the services using docker-compose
getDockerCompose("down -v")
.start();

// remove the networks before removing the containers
ResourceReaper.instance().removeNetworks(identifier);

// kill the spawned service containers
spawnedContainerIds.forEach(id -> ResourceReaper.instance().stopAndRemoveContainer(id));
spawnedContainerIds.clear();
// kill the spawned service containers
spawnedContainerIds.forEach(id -> ResourceReaper.instance().stopAndRemoveContainer(id));
spawnedContainerIds.clear();
}
}

public SELF withExposedService(String serviceName, int servicePort) {
Expand Down