kiwi-el8/kiwi/system/root_import/base.py
David Cassany 8f1048f840
Refactor OCI images packing
This commit refactors the OCI images support:

  * added import_container_image and export_container_image methods
    to oci_tools classes. 'umoci' and 'buildah' consume different
    formats thus the inital skopeo call to import a container is tool
    dependent.

  * use oci-archive transport for packing the OCI images, this causes
    docker and oci operations to just diverge on transport type.

  * add_tag method no longer needed in oci_tools/base, skopeo is used
    for that matter.

  * container/docker.py class is no longer needed. The difference
    between docker and OCI images is just on packing format which is just
    a parameter in skopeo. It does not deserve a dedicated class

  * system/root_import/docker.py class no longer needed. The difference
    between OCI and Docker class was just the transport type for the
    skopeo call. It does not deserve a dedicated class
2019-03-11 13:54:42 +01:00

87 lines
2.6 KiB
Python

# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved.
#
# This file is part of kiwi.
#
# kiwi is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# kiwi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
#
import os
# project
from kiwi.utils.checksum import Checksum
from kiwi.logger import log
from kiwi.exceptions import (
KiwiRootImportError,
KiwiUriTypeUnknown
)
class RootImportBase(object):
"""
Imports the root system from an already packed image.
* :attr:`root_dir`
root directory path name
* :attr:`image_uri`
Uri object to store source location
* :attr:`custom_args`
Dictonary to set specialized class specific configuration values
"""
def __init__(self, root_dir, image_uri, custom_args=None):
self.unknown_uri = None
self.root_dir = root_dir
try:
if image_uri.is_remote():
raise KiwiRootImportError(
'Only local imports are supported'
)
self.image_file = image_uri.translate()
if not os.path.exists(self.image_file):
raise KiwiRootImportError(
'Could not stat base image file: {0}'.format(
self.image_file
)
)
except KiwiUriTypeUnknown:
# Let specialized class handle unknown uri schemes
log.warning(
'Unkown URI type for the base image: %s', image_uri.uri
)
self.unknown_uri = image_uri.uri
finally:
self.post_init(custom_args)
def post_init(self, custom_args):
"""
Initialization of the specialized import class
Implementation in specialized root import class
"""
pass
def sync_data(self):
"""
Synchronizes the root system of `image_file` into the root_dir
Implementation in specialized root import class
"""
raise NotImplementedError
def _make_checksum(self, image):
checksum = Checksum(image)
checksum.md5(''.join([image, '.md5']))