forked from openshift/os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply-manifest
executable file
·54 lines (40 loc) · 1.66 KB
/
apply-manifest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python3 -u
# This is a hacky temporary script to apply an rpm-ostree manifest as part of a
# derived container build. It's only required because we're in this transitional
# state where some streams use the old way, and others use layering. Once all
# streams use layering, we could stop using manifests for the layered bits. (An
# obvious question here is whether we should keep extending the `rpm-ostree ex
# rebuild` stuff to keep using manifests even in a layered build. Though likely
# similar functionality will live in dnf instead.)
# Note this only supports the subset of the manifest spec actually used in
# `packages-openshift.yaml`.
import os
import shutil
import subprocess
import sys
import yaml
def runcmd(args):
print("Running:", ' '.join(args))
subprocess.check_call(args)
manifest_file = sys.argv[1]
manifest_dir = os.path.dirname(manifest_file)
with open(manifest_file) as f:
manifest = yaml.safe_load(f)
if len(manifest.get('packages', [])):
packages = []
for pkg in manifest['packages']:
packages += pkg.split()
dnf_install = ['dnf', 'install', '--setopt=tsflags=nodocs', '--noplugins', '-y'] + packages
# XXX: temporary hack for cri-o, which wants to create dirs under /opt
# https://github.com/CentOS/centos-bootc/issues/393
if 'cri-o' in packages:
os.makedirs("/var/opt", exist_ok=True)
runcmd(dnf_install)
if len(manifest.get('postprocess', [])):
for i, script in enumerate(manifest['postprocess']):
name = f"/tmp/postprocess-script-{i}"
with open(name, 'w') as f:
f.write(script)
os.chmod(name, 0o755)
runcmd([name])
os.unlink(name)