Add dnf and yum support, build podctl in centos
This commit is contained in:
parent
7a99d4cbca
commit
d984987ca9
4
pod.py
4
pod.py
@ -7,8 +7,8 @@ from podctl import *
|
|||||||
|
|
||||||
|
|
||||||
podctl = Container(
|
podctl = Container(
|
||||||
Base('alpine'),
|
Base('docker.io/centos'),
|
||||||
Packages('bash', 'python3'),
|
Packages('podman', 'buildah', 'python3'),
|
||||||
User('app', 1000, '/app'),
|
User('app', 1000, '/app'),
|
||||||
Copy(['setup.py', 'podctl'], '/app'),
|
Copy(['setup.py', 'podctl'], '/app'),
|
||||||
Pip('/app'),
|
Pip('/app'),
|
||||||
|
|||||||
@ -8,21 +8,26 @@ class Packages:
|
|||||||
upgrade='sudo apk upgrade',
|
upgrade='sudo apk upgrade',
|
||||||
install='sudo apk add',
|
install='sudo apk add',
|
||||||
),
|
),
|
||||||
|
dnf=dict(
|
||||||
|
update='sudo dnf update',
|
||||||
|
upgrade='sudo dnf upgrade',
|
||||||
|
install='sudo dnf install --setopt=install_weak_deps=False --best --assumeyes', # noqa
|
||||||
|
),
|
||||||
|
yum=dict(
|
||||||
|
update='sudo yum update',
|
||||||
|
upgrade='sudo yum upgrade',
|
||||||
|
install='sudo yum install',
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, *packages):
|
def __init__(self, *packages):
|
||||||
self.packages = list(packages)
|
self.packages = list(packages)
|
||||||
|
self.mgr = None
|
||||||
|
|
||||||
def pre_build(self, script):
|
def init_build(self, script):
|
||||||
|
base = script.container.variable('base')
|
||||||
for mgr, cmds in self.mgrs.items():
|
for mgr, cmds in self.mgrs.items():
|
||||||
cmd = [
|
cmd = ['podman', 'run', base, 'sh', '-c', f'type {mgr}']
|
||||||
'podman',
|
|
||||||
'run',
|
|
||||||
script.container.variable('base'),
|
|
||||||
'which',
|
|
||||||
mgr
|
|
||||||
]
|
|
||||||
print('+ ' + ' '.join(cmd))
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_call(cmd)
|
subprocess.check_call(cmd)
|
||||||
self.mgr = mgr
|
self.mgr = mgr
|
||||||
@ -30,6 +35,8 @@ class Packages:
|
|||||||
break
|
break
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
continue
|
continue
|
||||||
|
if not self.mgr:
|
||||||
|
raise Exception('Packages does not yet support this distro')
|
||||||
|
|
||||||
def build(self, script):
|
def build(self, script):
|
||||||
cache = f'.cache/{self.mgr}'
|
cache = f'.cache/{self.mgr}'
|
||||||
@ -49,6 +56,8 @@ class Packages:
|
|||||||
echo Cache recent enough, skipping index update.
|
echo Cache recent enough, skipping index update.
|
||||||
fi
|
fi
|
||||||
''')
|
''')
|
||||||
|
elif self.mgr == 'dnf':
|
||||||
|
script.run('sh -c "echo keepcache=True >> /etc/dnf/dnf.conf"')
|
||||||
|
|
||||||
script.run(self.cmds['upgrade'])
|
script.run(self.cmds['upgrade'])
|
||||||
script.run(' '.join([self.cmds['install']] + self.packages))
|
script.run(' '.join([self.cmds['install']] + self.packages))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user