Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stages/org.osbuild.qemu: make qcow2 compression optional #5

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions stages/org.osbuild.bootupd.gen-metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
"""
Transforms /usr/lib/ostree-boot into a bootupd-compatible update payload.

Scrapes metadata (e.g. RPM versions) about shim/grub and puts them along with their component files in
`/usr/lib/bootupd/updates/`.

Notes:
- Requires 'chroot' in the buildroot.
- Runs the 'bootupctl' binary from the image in the chroot.
"""

import os
import subprocess
import sys

import osbuild.api
from osbuild.util.mnt import MountGuard

SCHEMA_2 = r"""
"options": {
"additionalProperties": false
}
"""


def main(tree):
with MountGuard() as mounter:
for source in ("/dev", "/sys", "/proc"):
target = os.path.join(tree, source.lstrip("/"))
os.makedirs(target, exist_ok=True)
mounter.mount(source, target, ro=True)

# Using a non-default sysroot is not supported by the generate-update-metadata command, so we need to chroot
# into the tree and run against /
cmd = ['chroot', tree, '/usr/bin/bootupctl', 'backend', 'generate-update-metadata', '/']
subprocess.run(cmd, check=True)

return 0


if __name__ == '__main__':
_args = osbuild.api.arguments()
r = main(_args["tree"])
sys.exit(r)
9 changes: 9 additions & 0 deletions stages/org.osbuild.ostree.config
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ SCHEMA = """
"type": "string",
"enum": ["none", "auto", "grub2", "syslinux", "uboot", "zipl", "aboot"]
},
"bootprefix": {
"description": "If set to true, the bootloader entries generated will include /boot as a prefix.",
"type": "boolean"
},
"readonly": {
"description": "Read only sysroot and boot",
"type": "boolean"
Expand All @@ -63,6 +67,11 @@ def main(tree, options):
if bootloader:
ostree.cli("config", "set", "sysroot.bootloader", bootloader, repo=repo)

bootprefix = sysroot_options.get("bootprefix")
if bootprefix is not None: # can be False, which we would want to set
bp = "true" if bootprefix else "false"
ostree.cli("config", "set", "sysroot.bootprefix", bp, repo=repo)

readonly = sysroot_options.get("readonly")
if readonly is not None: # can be False, which we would want to set
ro = "true" if readonly else "false"
Expand Down
23 changes: 21 additions & 2 deletions stages/org.osbuild.qemu
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ SCHEMA_2 = r"""
"type": "string",
"enum": ["qcow2"]
},
"compression": {
"description": "Enable/disable compression of the qcow2 image",
"type": "boolean",
"default": true
},
"compat": {
"description": "The qcow2-compatibility-version to use",
"type": "string"
Expand Down Expand Up @@ -61,6 +66,11 @@ SCHEMA_2 = r"""
"type": "string",
"enum": ["vmdk"]
},
"compression": {
"description": "Enable/disable compression of the vmdk image",
"type": "boolean",
"default": true
},
"subformat": {
"description": "VMDK flat extent format",
"type": "string",
Expand Down Expand Up @@ -140,17 +150,26 @@ SCHEMA_2 = r"""


def qcow2_arguments(options):
argv = ["-c"]
argv = []
compression = options.get("compression", True)
compat = options.get("compat")

if compression:
argv += ["-c"]

if compat:
argv += ["-o", f"compat={compat}"]
return argv


def vmdk_arguments(options):
argv = ["-c"]
argv = []
compression = options.get("compression", True)
subformat = options.get("subformat")

if compression:
argv += ["-c"]

if subformat:
argv += ["-o", f"subformat={subformat}"]
return argv
Expand Down
3 changes: 2 additions & 1 deletion test/data/manifests/fedora-coreos-container.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@
"sysroot": {
"readonly": true,
"bootloader": "none",
"bls-append-except-default": "grub_users=\"\""
"bls-append-except-default": "grub_users=\"\"",
"bootprefix": true
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/data/manifests/fedora-coreos-container.mpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pipelines:
readonly: true
bootloader: none
bls-append-except-default: grub_users=""
bootprefix: true
- type: org.osbuild.mkdir
options:
paths:
Expand Down Expand Up @@ -611,4 +612,5 @@ pipelines:
filename: qemu.qcow2
format:
type: qcow2
compression: false
compat: '1.1'
1,139 changes: 1,139 additions & 0 deletions test/data/stages/bootupd.gen-metadata/a.json

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions test/data/stages/bootupd.gen-metadata/a.mpp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
version: '2'
pipelines:
- mpp-import-pipelines:
path: ../manifests/fedora-vars.ipp.yaml
- mpp-import-pipeline:
path: ../manifests/fedora-build-v2.ipp.yaml
id: build
runner:
mpp-format-string: org.osbuild.fedora{release}
- name: tree
build: name:build
stages:
- type: org.osbuild.rpm
inputs:
packages:
type: org.osbuild.files
origin: org.osbuild.source
mpp-depsolve:
architecture: $arch
module-platform-id: $module_platform_id
repos:
mpp-eval: repos
packages:
- bootupd
- kernel
- rpm-ostree
- selinux-policy-targeted
- shim-x64
options:
dbpath: /usr/share/rpm
ostree_booted: true
gpgkeys:
mpp-eval: gpgkeys
exclude:
docs: true
- type: org.osbuild.ostree.preptree
Loading