mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
@ -108,19 +108,16 @@ class Container(AttachMixin, StartMixin, collections.UserDict):
|
|||||||
results = podman.ExportContainer(self._id, target)
|
results = podman.ExportContainer(self._id, target)
|
||||||
return results['tarfile']
|
return results['tarfile']
|
||||||
|
|
||||||
def commit(self,
|
def commit(self, image_name, **kwargs):
|
||||||
image_name,
|
|
||||||
*args,
|
|
||||||
changes=[],
|
|
||||||
message='',
|
|
||||||
pause=True,
|
|
||||||
**kwargs): # pylint: disable=unused-argument
|
|
||||||
"""Create image from container.
|
"""Create image from container.
|
||||||
|
|
||||||
All changes overwrite existing values.
|
Keyword arguments:
|
||||||
See inspect() to obtain current settings.
|
author -- change image's author
|
||||||
|
message -- change image's message, docker format only.
|
||||||
|
pause -- pause container during commit
|
||||||
|
change -- Additional properties to change
|
||||||
|
|
||||||
Changes:
|
Change examples:
|
||||||
CMD=/usr/bin/zsh
|
CMD=/usr/bin/zsh
|
||||||
ENTRYPOINT=/bin/sh date
|
ENTRYPOINT=/bin/sh date
|
||||||
ENV=TEST=test_containers.TestContainers.test_commit
|
ENV=TEST=test_containers.TestContainers.test_commit
|
||||||
@ -129,21 +126,23 @@ class Container(AttachMixin, StartMixin, collections.UserDict):
|
|||||||
USER=bozo:circus
|
USER=bozo:circus
|
||||||
VOLUME=/data
|
VOLUME=/data
|
||||||
WORKDIR=/data/application
|
WORKDIR=/data/application
|
||||||
"""
|
|
||||||
# TODO: Clean up *args, **kwargs after Commit() is complete
|
|
||||||
try:
|
|
||||||
author = kwargs.get('author', getpass.getuser())
|
|
||||||
except Exception: # pylint: disable=broad-except
|
|
||||||
author = ''
|
|
||||||
|
|
||||||
for c in changes:
|
All changes overwrite existing values.
|
||||||
|
See inspect() to obtain current settings.
|
||||||
|
"""
|
||||||
|
author = kwargs.get('author', None) or getpass.getuser()
|
||||||
|
change = kwargs.get('change', None) or []
|
||||||
|
message = kwargs.get('message', None) or ''
|
||||||
|
pause = kwargs.get('pause', None) or True
|
||||||
|
|
||||||
|
for c in change:
|
||||||
if c.startswith('LABEL=') and c.count('=') < 2:
|
if c.startswith('LABEL=') and c.count('=') < 2:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'LABEL should have the format: LABEL=label=value, not {}'.
|
'LABEL should have the format: LABEL=label=value, not {}'.
|
||||||
format(c))
|
format(c))
|
||||||
|
|
||||||
with self._client() as podman:
|
with self._client() as podman:
|
||||||
results = podman.Commit(self._id, image_name, changes, author,
|
results = podman.Commit(self._id, image_name, change, author,
|
||||||
message, pause)
|
message, pause)
|
||||||
return results['image']
|
return results['image']
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class TestContainers(PodmanTestCase):
|
|||||||
changes.append('WORKDIR=/data/application')
|
changes.append('WORKDIR=/data/application')
|
||||||
|
|
||||||
id = self.alpine_ctnr.commit(
|
id = self.alpine_ctnr.commit(
|
||||||
'alpine3', author='Bozo the clown', changes=changes, pause=True)
|
'alpine3', author='Bozo the clown', change=changes, pause=True)
|
||||||
img = self.pclient.images.get(id)
|
img = self.pclient.images.get(id)
|
||||||
self.assertIsNotNone(img)
|
self.assertIsNotNone(img)
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ class Commit(AbstractActionBase):
|
|||||||
choices=('oci', 'docker'),
|
choices=('oci', 'docker'),
|
||||||
default='oci',
|
default='oci',
|
||||||
type=str.lower,
|
type=str.lower,
|
||||||
help='Set the format of the image manifest and metadata',
|
help='Set the format of the image manifest and metadata.'
|
||||||
|
' (Ignored.)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--iidfile',
|
'--iidfile',
|
||||||
@ -40,7 +41,8 @@ class Commit(AbstractActionBase):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--message',
|
'--message',
|
||||||
'-m',
|
'-m',
|
||||||
help='Set commit message for committed image',
|
help='Set commit message for committed image'
|
||||||
|
' (Only on docker images.)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--pause',
|
'--pause',
|
||||||
@ -80,7 +82,15 @@ class Commit(AbstractActionBase):
|
|||||||
flush=True)
|
flush=True)
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
ident = ctnr.commit(self.opts['image'][0], **self.opts)
|
ident = ctnr.commit(
|
||||||
|
self.opts['image'][0],
|
||||||
|
change=self.opts.get('change', None),
|
||||||
|
message=self.opts.get('message', None),
|
||||||
|
pause=self.opts['pause'],
|
||||||
|
author=self.opts.get('author', None),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not self.opts['quiet']:
|
||||||
print(ident)
|
print(ident)
|
||||||
except podman.ErrorOccurred as e:
|
except podman.ErrorOccurred as e:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
Reference in New Issue
Block a user