Merge pull request #1308 from jzelinskie/aci-refresh

Fix ACI Volume Names
This commit is contained in:
Jimmy Zelinskie 2016-03-22 15:08:03 -04:00
commit 47506d6ec0

View file

@ -1,9 +1,15 @@
import json
import re
from uuid import uuid4
from app import app
from util.registry.streamlayerformat import StreamLayerMerger
from formats.tarimageformatter import TarImageFormatter
import json
import re
ACNAME_REGEX = re.compile(r'[^a-z-]+')
class ACIImage(TarImageFormatter):
""" Image formatter which produces an ACI-compatible TAR.
@ -79,7 +85,6 @@ class ACIImage(TarImageFormatter):
return isolators
@staticmethod
def _get_docker_config_value(docker_config, key, default_value):
# Try the key itself.
@ -94,7 +99,6 @@ class ACIImage(TarImageFormatter):
return default_value
@staticmethod
def _build_ports(docker_config):
""" Builds the ports definitions for the ACI. """
@ -126,14 +130,20 @@ class ACIImage(TarImageFormatter):
return ports
@staticmethod
def _ac_name(value):
sanitized = ACNAME_REGEX.sub('-', value.lower()).strip('-')
if sanitized == '':
return str(uuid4())
return sanitized
@staticmethod
def _build_volumes(docker_config):
""" Builds the volumes definitions for the ACI. """
volumes = []
names = set()
def get_name(docker_volume_path):
return "volume-%s" % docker_volume_path.replace('/', '-')
return "volume-%s" % ACIImage._ac_name(docker_volume_path)
for docker_volume_path in ACIImage._get_docker_config_value(docker_config, 'Volumes', []):
if not docker_volume_path:
@ -146,7 +156,6 @@ class ACIImage(TarImageFormatter):
})
return volumes
@staticmethod
def _build_manifest(namespace, repository, tag, docker_layer_data, synthetic_image_id):
""" Builds an ACI manifest from the docker layer data. """