stages: org.osbuild.container-deploy
This commit is contained in:
parent
ad8fd2f532
commit
fdc5bf3b98
2 changed files with 72 additions and 1 deletions
71
stages/org.osbuild.container-deploy
Executable file
71
stages/org.osbuild.container-deploy
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/python3
|
||||
"""
|
||||
Deploy a container.
|
||||
|
||||
Buildhost commands used: podman
|
||||
"""
|
||||
import contextlib
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import osbuild.api
|
||||
from osbuild.util import containers
|
||||
|
||||
SCHEMA_2 = r"""
|
||||
"inputs": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["images"],
|
||||
"properties": {
|
||||
"images": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"options": {
|
||||
"additionalProperties": false
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mount_container(store, image):
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["podman", "--imagestore", store, "image", "mount", image],
|
||||
capture_output=True,
|
||||
encoding="utf-8",
|
||||
check=True,
|
||||
)
|
||||
|
||||
yield result.stdout.strip()
|
||||
|
||||
finally:
|
||||
subprocess.run(
|
||||
["podman", "--imagestore", store, "image", "umount", image],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def main(inputs, output):
|
||||
images = containers.parse_containers_input(inputs)
|
||||
assert len(images) == 1
|
||||
image = list(images.values())[0]
|
||||
|
||||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
with containers.container_source(image) as (_, source):
|
||||
subprocess.run(
|
||||
["skopeo", "copy", source, f"containers-storage:[overlay@{tmp}]image"],
|
||||
check=True,
|
||||
)
|
||||
|
||||
with mount_container(tmp, "image") as img:
|
||||
subprocess.run(["cp", "-a", f"{img}/.", f"{output}/"], check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = osbuild.api.arguments()
|
||||
r = main(args["inputs"], args["tree"])
|
||||
sys.exit(r)
|
||||
|
|
@ -1602,7 +1602,7 @@ class ManifestFileV2(ManifestFile):
|
|||
|
||||
def _process_container(self, stage):
|
||||
if stage.get("type", "") not in \
|
||||
["org.osbuild.skopeo", "org.osbuild.ostree.deploy.container"]:
|
||||
["org.osbuild.skopeo", "org.osbuild.ostree.deploy.container", "org.osbuild.container-deploy"]:
|
||||
return
|
||||
|
||||
inputs = element_enter(stage, "inputs", {})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue