Change tar stream formatters to be based on tag and manifest, instead of legacy images
This commit is contained in:
parent
c92294c218
commit
bafab2e734
4 changed files with 21 additions and 55 deletions
|
@ -18,10 +18,10 @@ class AppCImageFormatter(TarImageFormatter):
|
|||
Image formatter which produces an tarball according to the AppC specification.
|
||||
"""
|
||||
|
||||
def stream_generator(self, repo_image, tag, synthetic_image_id, get_image_iterator,
|
||||
def stream_generator(self, tag, manifest, synthetic_image_id, layer_iterator,
|
||||
tar_stream_getter_iterator, reporter=None):
|
||||
image_mtime = 0
|
||||
created = next(get_image_iterator()).v1_metadata.created
|
||||
created = manifest.created_datetime
|
||||
if created is not None:
|
||||
image_mtime = calendar.timegm(created.utctimetuple())
|
||||
|
||||
|
@ -31,8 +31,8 @@ class AppCImageFormatter(TarImageFormatter):
|
|||
|
||||
# Yield the manifest.
|
||||
manifest = json.dumps(DockerV1ToACIManifestTranslator.build_manifest(
|
||||
repo_image,
|
||||
tag,
|
||||
manifest,
|
||||
synthetic_image_id
|
||||
))
|
||||
yield self.tar_file('manifest', manifest, mtime=image_mtime)
|
||||
|
@ -170,16 +170,16 @@ class DockerV1ToACIManifestTranslator(object):
|
|||
return volumes
|
||||
|
||||
@staticmethod
|
||||
def build_manifest(repo_image, tag, synthetic_image_id):
|
||||
def build_manifest(tag, manifest, synthetic_image_id):
|
||||
""" Builds an ACI manifest of an existing repository image. """
|
||||
docker_layer_data = JSONPathDict(repo_image.compat_metadata)
|
||||
docker_layer_data = JSONPathDict(manifest.leaf_layer.v1_metadata)
|
||||
config = docker_layer_data['config'] or JSONPathDict({})
|
||||
|
||||
namespace = repo_image.repository.namespace_name
|
||||
repo_name = repo_image.repository.name
|
||||
namespace = tag.repository.namespace_name
|
||||
repo_name = tag.repository.name
|
||||
source_url = "%s://%s/%s/%s:%s" % (app.config['PREFERRED_URL_SCHEME'],
|
||||
app.config['SERVER_HOSTNAME'],
|
||||
namespace, repo_name, tag)
|
||||
namespace, repo_name, tag.name)
|
||||
|
||||
# ACI requires that the execution command be absolutely referenced. Therefore, if we find
|
||||
# a relative command, we give it as an argument to /bin/sh to resolve and execute for us.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from image.appc import DockerV1ToACIManifestTranslator
|
||||
from endpoints.verbs.models_interface import RepositoryReference, ImageWithBlob
|
||||
from util.dict_wrappers import JSONPathDict
|
||||
|
||||
|
||||
|
@ -74,31 +73,6 @@ EXAMPLE_MANIFEST_OBJ = {
|
|||
"throwaway": True
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repo_image():
|
||||
repo_ref = RepositoryReference(1, 'simple', 'devtable')
|
||||
return ImageWithBlob(1, None, EXAMPLE_MANIFEST_OBJ, repo_ref, 1, None)
|
||||
|
||||
|
||||
def test_port_conversion(repo_image):
|
||||
output = DockerV1ToACIManifestTranslator.build_manifest(repo_image, 'v3.0.15', 'abcdef')
|
||||
ports = output['app']['ports']
|
||||
ports.sort()
|
||||
assert {'name':'port-2379', 'port':2379, 'protocol':'tcp'} == ports[0]
|
||||
assert {'name':'port-2380', 'port':2380, 'protocol':'tcp'} == ports[1]
|
||||
|
||||
|
||||
def test_legacy_port_conversion(repo_image):
|
||||
del repo_image.compat_metadata['config']['ExposedPorts']
|
||||
repo_image.compat_metadata['config']['ports'] = ['8080', '8081']
|
||||
output = DockerV1ToACIManifestTranslator.build_manifest(repo_image, 'v3.0.15', 'abcdef')
|
||||
ports = output['app']['ports']
|
||||
ports.sort()
|
||||
assert {'name':'port-8080', 'port':8080, 'protocol':'tcp'} == ports[0]
|
||||
assert {'name':'port-8081', 'port':8081, 'protocol':'tcp'} == ports[1]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("vcfg,expected", [
|
||||
({'Volumes': None}, []),
|
||||
({'Volumes': {}}, []),
|
||||
|
|
Reference in a new issue