Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create(self,
ident=None,
cgroupparent=None,
labels=None,
share=None,
infra=False):
"""Create a new empty pod."""
config = ConfigDict(
name=ident,
cgroupParent=cgroupparent,
labels=labels,
share=share,
infra=infra,
)
with self._client() as podman:
result = podman.CreatePod(config)
details = podman.GetPod(result['pod'])
return Pod(self._client, result['pod'], details['pod'])
def create(self, **kwargs):
"""Create container from image.
Pulls defaults from image.inspect()
"""
details = self.inspect()
config = ConfigDict(image_id=self._id, **kwargs)
config["command"] = details.config.get("cmd")
config["env"] = self._split_token(details.config.get("env"))
config["image"] = copy.deepcopy(details.repotags[0])
config["labels"] = copy.deepcopy(details.labels)
# TODO: Are these settings still required?
config["net_mode"] = "bridge"
config["network"] = "bridge"
config["args"] = flatten([config["image"], config["command"]])
logging.debug("Image %s: create config: %s", self._id, config)
with self._client() as podman:
id_ = podman.CreateContainer(config)["container"]
cntr = podman.GetContainer(id_)
return Container(self._client, id_, cntr["container"])
if not containerfiles:
containerfiles = []
for entry in os.walk(context_directory):
containerfiles.append(entry)
if containerfiles and not isinstance(containerfiles, (list, tuple)):
raise ValueError(
'"containerfiles" is required to be a list or tuple.'
)
if not tags:
raise ValueError('"tags" is a required argument.')
if not isinstance(tags, (list, tuple)):
raise ValueError('"tags" is required to be a list or tuple.')
config = ConfigDict(
dockerfiles=containerfiles, tags=tags[1:], output=tags[0], **kwargs
)
with io.BytesIO() as stream:
# Compile build context in memory tar file
with tarfile.open(mode="w:gz", fileobj=stream) as tar:
for name in containerfiles:
tar.addfile(tar.gettarinfo(fileobj=open(name)))
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
# If debugging save a copy of the tar file we're going
# to send to service
tar = os.path.join(tempfile.gettempdir(), "buildContext.tgz")
with open(tar, "wb") as file:
file.write(stream.getvalue())