kiwi-el8/kiwi/container/docker.py
David Cassany 38dbd7e76d Include '--delete' in OCI images DataSync
This commit includes #310 patch for OCI images.

It also corrects the end of line format for kiwi/container/docker.py
and test/unit/container_image_docker_test.py, so flake tests are all
green.
2017-04-24 12:29:44 +02:00

65 lines
2.0 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.container.oci import ContainerImageOCI
from kiwi.path import Path
from kiwi.command import Command
from kiwi.utils.compress import Compress
class ContainerImageDocker(ContainerImageOCI):
"""
Create docker container from a root directory
Attributes
* :attr:`root_dir`
root directory path name
* :attr:`custom_args`
representation of the containerconfig and its subsections
"""
def pack_image_to_file(self, filename):
"""
Packs the given oci image into the given filename.
:param string filename: file name of the resulting packed image
"""
docker_tarfile = filename.replace('.xz', '')
oci_image = os.sep.join([
self.oci_dir, ':'.join(['umoci_layout', self.container_tag])
])
# make sure the target tar file does not exist
# skopeo doesn't support force overwrite
Path.wipe(docker_tarfile)
Command.run(
[
'skopeo', 'copy', 'oci:{0}'.format(
oci_image
),
'docker-archive:{0}:{1}:{2}'.format(
docker_tarfile, self.container_name, self.container_tag
)
]
)
compressor = Compress(docker_tarfile)
compressor.xz()