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 app import app
from util.registry.streamlayerformat import StreamLayerMerger from util.registry.streamlayerformat import StreamLayerMerger
from formats.tarimageformatter import TarImageFormatter from formats.tarimageformatter import TarImageFormatter
import json
import re ACNAME_REGEX = re.compile(r'[^a-z-]+')
class ACIImage(TarImageFormatter): class ACIImage(TarImageFormatter):
""" Image formatter which produces an ACI-compatible TAR. """ Image formatter which produces an ACI-compatible TAR.
@ -79,7 +85,6 @@ class ACIImage(TarImageFormatter):
return isolators return isolators
@staticmethod @staticmethod
def _get_docker_config_value(docker_config, key, default_value): def _get_docker_config_value(docker_config, key, default_value):
# Try the key itself. # Try the key itself.
@ -94,7 +99,6 @@ class ACIImage(TarImageFormatter):
return default_value return default_value
@staticmethod @staticmethod
def _build_ports(docker_config): def _build_ports(docker_config):
""" Builds the ports definitions for the ACI. """ """ Builds the ports definitions for the ACI. """
@ -126,14 +130,20 @@ class ACIImage(TarImageFormatter):
return ports return ports
@staticmethod
def _ac_name(value):
sanitized = ACNAME_REGEX.sub('-', value.lower()).strip('-')
if sanitized == '':
return str(uuid4())
return sanitized
@staticmethod @staticmethod
def _build_volumes(docker_config): def _build_volumes(docker_config):
""" Builds the volumes definitions for the ACI. """ """ Builds the volumes definitions for the ACI. """
volumes = [] volumes = []
names = set()
def get_name(docker_volume_path): 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', []): for docker_volume_path in ACIImage._get_docker_config_value(docker_config, 'Volumes', []):
if not docker_volume_path: if not docker_volume_path:
@ -146,7 +156,6 @@ class ACIImage(TarImageFormatter):
}) })
return volumes return volumes
@staticmethod @staticmethod
def _build_manifest(namespace, repository, tag, docker_layer_data, synthetic_image_id): def _build_manifest(namespace, repository, tag, docker_layer_data, synthetic_image_id):
""" Builds an ACI manifest from the docker layer data. """ """ Builds an ACI manifest from the docker layer data. """
@ -173,18 +182,18 @@ class ACIImage(TarImageFormatter):
"acVersion": "0.6.1", "acVersion": "0.6.1",
"name": '%s/%s/%s' % (hostname.lower(), namespace.lower(), repository.lower()), "name": '%s/%s/%s' % (hostname.lower(), namespace.lower(), repository.lower()),
"labels": [ "labels": [
{ {
"name": "version", "name": "version",
"value": tag, "value": tag,
}, },
{ {
"name": "arch", "name": "arch",
"value": docker_layer_data.get('architecture', 'amd64') "value": docker_layer_data.get('architecture', 'amd64')
}, },
{ {
"name": "os", "name": "os",
"value": docker_layer_data.get('os', 'linux') "value": docker_layer_data.get('os', 'linux')
} }
], ],
"app": { "app": {
"exec": exec_path, "exec": exec_path,