|
@@ -693,32 +693,29 @@ class Service(object):
|
|
|
stream_output(output, sys.stdout)
|
|
|
|
|
|
|
|
|
-def get_container_data_volumes(container, volumes_option):
|
|
|
- """Find the container data volumes that are in `volumes_option`, and return
|
|
|
- a mapping of volume bindings for those volumes.
|
|
|
- """
|
|
|
- volumes = []
|
|
|
+# Names
|
|
|
|
|
|
- volumes_option = volumes_option or []
|
|
|
- container_volumes = container.get('Volumes') or {}
|
|
|
- image_volumes = container.image_config['ContainerConfig'].get('Volumes') or {}
|
|
|
|
|
|
- for volume in set(volumes_option + image_volumes.keys()):
|
|
|
- volume = parse_volume_spec(volume)
|
|
|
- # No need to preserve host volumes
|
|
|
- if volume.external:
|
|
|
- continue
|
|
|
+def build_container_name(project, service, number, one_off=False):
|
|
|
+ bits = [project, service]
|
|
|
+ if one_off:
|
|
|
+ bits.append('run')
|
|
|
+ return '_'.join(bits + [str(number)])
|
|
|
|
|
|
- volume_path = container_volumes.get(volume.internal)
|
|
|
- # New volume, doesn't exist in the old container
|
|
|
- if not volume_path:
|
|
|
- continue
|
|
|
|
|
|
- # Copy existing volume from old container
|
|
|
- volume = volume._replace(external=volume_path)
|
|
|
- volumes.append(build_volume_binding(volume))
|
|
|
+# Images
|
|
|
|
|
|
- return dict(volumes)
|
|
|
+
|
|
|
+def parse_repository_tag(s):
|
|
|
+ if ":" not in s:
|
|
|
+ return s, ""
|
|
|
+ repo, tag = s.rsplit(":", 1)
|
|
|
+ if "/" in tag:
|
|
|
+ return s, ""
|
|
|
+ return repo, tag
|
|
|
+
|
|
|
+
|
|
|
+# Volumes
|
|
|
|
|
|
|
|
|
def merge_volume_bindings(volumes_option, previous_container):
|
|
@@ -737,35 +734,37 @@ def merge_volume_bindings(volumes_option, previous_container):
|
|
|
return volume_bindings
|
|
|
|
|
|
|
|
|
-def build_container_name(project, service, number, one_off=False):
|
|
|
- bits = [project, service]
|
|
|
- if one_off:
|
|
|
- bits.append('run')
|
|
|
- return '_'.join(bits + [str(number)])
|
|
|
+def get_container_data_volumes(container, volumes_option):
|
|
|
+ """Find the container data volumes that are in `volumes_option`, and return
|
|
|
+ a mapping of volume bindings for those volumes.
|
|
|
+ """
|
|
|
+ volumes = []
|
|
|
+
|
|
|
+ volumes_option = volumes_option or []
|
|
|
+ container_volumes = container.get('Volumes') or {}
|
|
|
+ image_volumes = container.image_config['ContainerConfig'].get('Volumes') or {}
|
|
|
|
|
|
+ for volume in set(volumes_option + image_volumes.keys()):
|
|
|
+ volume = parse_volume_spec(volume)
|
|
|
+ # No need to preserve host volumes
|
|
|
+ if volume.external:
|
|
|
+ continue
|
|
|
|
|
|
-def build_container_labels(label_options, service_labels, number, one_off=False):
|
|
|
- labels = label_options or {}
|
|
|
- labels.update(label.split('=', 1) for label in service_labels)
|
|
|
- labels[LABEL_CONTAINER_NUMBER] = str(number)
|
|
|
- labels[LABEL_VERSION] = __version__
|
|
|
- return labels
|
|
|
+ volume_path = container_volumes.get(volume.internal)
|
|
|
+ # New volume, doesn't exist in the old container
|
|
|
+ if not volume_path:
|
|
|
+ continue
|
|
|
|
|
|
+ # Copy existing volume from old container
|
|
|
+ volume = volume._replace(external=volume_path)
|
|
|
+ volumes.append(build_volume_binding(volume))
|
|
|
|
|
|
-def parse_restart_spec(restart_config):
|
|
|
- if not restart_config:
|
|
|
- return None
|
|
|
- parts = restart_config.split(':')
|
|
|
- if len(parts) > 2:
|
|
|
- raise ConfigError("Restart %s has incorrect format, should be "
|
|
|
- "mode[:max_retry]" % restart_config)
|
|
|
- if len(parts) == 2:
|
|
|
- name, max_retry_count = parts
|
|
|
- else:
|
|
|
- name, = parts
|
|
|
- max_retry_count = 0
|
|
|
+ return dict(volumes)
|
|
|
|
|
|
- return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
|
|
+
|
|
|
+def build_volume_binding(volume_spec):
|
|
|
+ internal = {'bind': volume_spec.internal, 'ro': volume_spec.mode == 'ro'}
|
|
|
+ return volume_spec.external, internal
|
|
|
|
|
|
|
|
|
def parse_volume_spec(volume_config):
|
|
@@ -788,18 +787,7 @@ def parse_volume_spec(volume_config):
|
|
|
return VolumeSpec(external, internal, mode)
|
|
|
|
|
|
|
|
|
-def parse_repository_tag(s):
|
|
|
- if ":" not in s:
|
|
|
- return s, ""
|
|
|
- repo, tag = s.rsplit(":", 1)
|
|
|
- if "/" in tag:
|
|
|
- return s, ""
|
|
|
- return repo, tag
|
|
|
-
|
|
|
-
|
|
|
-def build_volume_binding(volume_spec):
|
|
|
- internal = {'bind': volume_spec.internal, 'ro': volume_spec.mode == 'ro'}
|
|
|
- return volume_spec.external, internal
|
|
|
+# Ports
|
|
|
|
|
|
|
|
|
def build_port_bindings(ports):
|
|
@@ -830,6 +818,39 @@ def split_port(port):
|
|
|
return internal_port, (external_ip, external_port or None)
|
|
|
|
|
|
|
|
|
+# Labels
|
|
|
+
|
|
|
+
|
|
|
+def build_container_labels(label_options, service_labels, number, one_off=False):
|
|
|
+ labels = label_options or {}
|
|
|
+ labels.update(label.split('=', 1) for label in service_labels)
|
|
|
+ labels[LABEL_CONTAINER_NUMBER] = str(number)
|
|
|
+ labels[LABEL_VERSION] = __version__
|
|
|
+ return labels
|
|
|
+
|
|
|
+
|
|
|
+# Restart policy
|
|
|
+
|
|
|
+
|
|
|
+def parse_restart_spec(restart_config):
|
|
|
+ if not restart_config:
|
|
|
+ return None
|
|
|
+ parts = restart_config.split(':')
|
|
|
+ if len(parts) > 2:
|
|
|
+ raise ConfigError("Restart %s has incorrect format, should be "
|
|
|
+ "mode[:max_retry]" % restart_config)
|
|
|
+ if len(parts) == 2:
|
|
|
+ name, max_retry_count = parts
|
|
|
+ else:
|
|
|
+ name, = parts
|
|
|
+ max_retry_count = 0
|
|
|
+
|
|
|
+ return {'Name': name, 'MaximumRetryCount': int(max_retry_count)}
|
|
|
+
|
|
|
+
|
|
|
+# Extra hosts
|
|
|
+
|
|
|
+
|
|
|
def build_extra_hosts(extra_hosts_config):
|
|
|
if not extra_hosts_config:
|
|
|
return {}
|