Skip to content
Permalink
Browse files

Include already running services for service templating

- Reload list of running services before resolving application companions.
  This ensures that a (re)deloyment of a single service includes all services
  for the templating of application companions.

  Missing is the inclusion of service companions. Needs to be fixed as well.
- Remove stopped containers to clean up docker host.
  • Loading branch information...
schrieveslaach committed Feb 21, 2019
1 parent 18339bb commit fbb454e2eaa7a364bb5a33ad090dc27d137b83fa
Showing with 55 additions and 15 deletions.
  1. +40 −9 api/src/services/apps_service.rs
  2. +15 −6 api/src/services/docker/docker_infrastructure.rs
@@ -115,15 +115,7 @@ impl<'a> AppsService<'a> {
}

configs.extend(service_companions);

for app_companion_config in self.config.get_application_companion_configs()? {
let applied_template_config = apply_templating_for_application_companion(
&app_companion_config,
app_name,
&configs,
)?;
configs.push(applied_template_config);
}
configs.extend(self.get_application_companion_configs(app_name, &configs)?);

configs.sort_unstable_by(|a, b| {
let index1 = AppsService::container_type_index(a.get_container_type());
@@ -140,6 +132,45 @@ impl<'a> AppsService<'a> {
Ok(services)
}

fn get_application_companion_configs(
&self,
app_name: &String,
service_configs: &Vec<ServiceConfig>,
) -> Result<Vec<ServiceConfig>, AppsServiceError> {
let mut configs_for_templating = service_configs.clone();

// TODO: make sure that service companions are included!
for config in self
.infrastructure
.get_configs_of_app(app_name)?
.into_iter()
.filter(|config| {
match service_configs
.iter()
.find(|c| c.get_service_name() == config.get_service_name())
{
None => true,
Some(_) => false,
}
})
{
configs_for_templating.push(config);
}

let mut companion_configs = Vec::new();
for app_companion_config in self.config.get_application_companion_configs()? {
let c = apply_templating_for_application_companion(
&app_companion_config,
app_name,
&configs_for_templating,
)?;

companion_configs.push(c);
}

Ok(companion_configs)
}

fn container_type_index(container_type: &ContainerType) -> i32 {
match container_type {
ContainerType::ApplicationCompanion => 0,
@@ -306,7 +306,11 @@ impl DockerInfrastructure {
Some(volumes) => volumes,
};

debug!("Copy data to container: {:?} (service = {})", container_info, service_config.get_service_name());
debug!(
"Copy data to container: {:?} (service = {})",
container_info,
service_config.get_service_name()
);

let docker = Docker::new();
let containers = docker.containers();
@@ -483,16 +487,21 @@ impl Infrastructure for DockerInfrastructure {
let container_ids: Vec<String> = runtime.block_on(future)?;

let mut stop_futures = Vec::new();
for id in container_ids {
let future = containers
.get(&id)
.stop(None);
for id in &container_ids {
let future = containers.get(&id).stop(None);

stop_futures.push(future);
}

runtime.block_on(join_all(stop_futures))?;

let mut delete_futures = Vec::new();
for id in &container_ids {
let future = containers.get(&id).delete();

delete_futures.push(future);
}
runtime.block_on(join_all(delete_futures))?;

self.delete_network(app_name)?;

Ok(services)

0 comments on commit fbb454e

Please sign in to comment.
You can’t perform that action at this time.