Publish Factorio deployment as a Helm chart
Validate, publish and promote Factorio chart / chart (push) Failing after 10s
Validate, publish and promote Factorio chart / chart (push) Failing after 10s
This commit is contained in:
1 parent
a165094c8e
commit
bf806c886c
19 files changed
+397
-252
No files matched your search
+12
-14
@@ -1,4 +1,4 @@
|
||||
"""Boot the rendered image/configuration via Docker, including remote Docker sockets."""
|
||||
"""Boot the rendered image/configuration via Podman."""
|
||||
import secrets
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -13,7 +13,7 @@ c = next(c for c in d['spec']['template']['spec']['containers'] if c['name'] ==
|
||||
cms = {d['metadata']['name']: d['data'] for d in docs if d['kind'] == 'ConfigMap'}
|
||||
run = lambda *a, **kw: subprocess.run(a, check=True, **kw)
|
||||
volume = 'factorio-smoke-' + secrets.token_hex(6)
|
||||
run('docker', 'volume', 'create', volume, stdout=subprocess.DEVNULL)
|
||||
run('podman', 'volume', 'create', volume, stdout=subprocess.DEVNULL)
|
||||
container = None
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
@@ -26,40 +26,38 @@ try:
|
||||
file.write_text(value)
|
||||
file.chmod(0o755 if key.endswith('.sh') else 0o644)
|
||||
(root / 'credentials/rcon-password').write_text(secrets.token_urlsafe(32))
|
||||
args = ['docker', 'create']
|
||||
args = ['podman', 'create']
|
||||
for env in c['env']:
|
||||
args += ['--env', env['name'] + '=' + env['value']]
|
||||
data_mount = next(m['mountPath'] for m in c['volumeMounts'] if m['name'] == 'data')
|
||||
args += ['--volume', f'{volume}:{data_mount}']
|
||||
args += ['--entrypoint', c['command'][0], c['image'], *c['command'][1:]]
|
||||
container = subprocess.check_output(args, text=True).strip()
|
||||
# docker cp works when the daemon is outside the CI job container;
|
||||
# bind-mounting the job container's /tmp would silently mount a different directory.
|
||||
for mount in c['volumeMounts']:
|
||||
if mount['name'] != 'data':
|
||||
run('docker', 'cp', str(root / mount['name']), container + ':' + mount['mountPath'])
|
||||
run('docker', 'start', container, stdout=subprocess.DEVNULL)
|
||||
run('podman', 'cp', str(root / mount['name']), container + ':' + mount['mountPath'])
|
||||
run('podman', 'start', container, stdout=subprocess.DEVNULL)
|
||||
|
||||
def ready():
|
||||
command = c['readinessProbe']['exec']['command']
|
||||
for _ in range(90):
|
||||
if subprocess.run(['docker', 'exec', container, *command], stdout=subprocess.DEVNULL,
|
||||
if subprocess.run(['podman', 'exec', container, *command], stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL, timeout=15).returncode == 0:
|
||||
return
|
||||
time.sleep(2)
|
||||
raise RuntimeError('Server did not pass the production readiness probe')
|
||||
|
||||
ready()
|
||||
run('docker', 'exec', container, 'rcon', '/server-save')
|
||||
run('docker', 'stop', '--time', str(d['spec']['template']['spec']['terminationGracePeriodSeconds']),
|
||||
run('podman', 'exec', container, 'rcon', '/server-save')
|
||||
run('podman', 'stop', '--time', str(d['spec']['template']['spec']['terminationGracePeriodSeconds']),
|
||||
container, stdout=subprocess.DEVNULL)
|
||||
run('docker', 'start', container, stdout=subprocess.DEVNULL)
|
||||
run('podman', 'start', container, stdout=subprocess.DEVNULL)
|
||||
ready()
|
||||
run('docker', 'exec', container, 'sh', '-c',
|
||||
run('podman', 'exec', container, 'sh', '-c',
|
||||
'test -n "$(find "$1/saves" -name "*.zip")" && test -n "$(find "$1/upgrade-backups" -name "*.zip")"',
|
||||
'sh', data_mount)
|
||||
print('Actual image passed RCON readiness, persistent save, restart, and upgrade-backup checks')
|
||||
finally:
|
||||
if container:
|
||||
run('docker', 'rm', '--force', container, stdout=subprocess.DEVNULL)
|
||||
run('docker', 'volume', 'rm', volume, stdout=subprocess.DEVNULL)
|
||||
run('podman', 'rm', '--force', container, stdout=subprocess.DEVNULL)
|
||||
run('podman', 'volume', 'rm', volume, stdout=subprocess.DEVNULL)
|
||||
+8
-3
@@ -8,12 +8,17 @@ assert d['spec']['replicas']==1
|
||||
spec=d['spec']['template']['spec']
|
||||
assert not spec['automountServiceAccountToken']
|
||||
for c in spec['containers']:
|
||||
assert all(p in c for p in ('startupProbe','readinessProbe','livenessProbe','resources')), c['name']
|
||||
assert all(p in c for p in ('startupProbe','readinessProbe','livenessProbe')), c['name']
|
||||
if 'resources' in c:
|
||||
assert isinstance(c['resources'], dict), c['name']
|
||||
assert ':' in c['image'] and not c['image'].endswith(':latest')
|
||||
preference=spec['affinity']['nodeAffinity']['preferredDuringSchedulingIgnoredDuringExecution']
|
||||
assert preference == [{'weight': 100, 'preference': {'matchExpressions': [{'key': 'kubernetes.io/hostname', 'operator': 'In', 'values': ['arschrock']}]}}]
|
||||
assert 'affinity' not in spec
|
||||
assert 'tolerations' not in spec
|
||||
for service in (d for d in resources if d['kind']=='Service'):
|
||||
assert all(p['port']!=27015 for p in service['spec']['ports'])
|
||||
funkfeuer=next(s for s in resources if s['kind']=='Service' and s['metadata']['name']=='factorio-funkfeuer')
|
||||
assert 'externalIPs' not in funkfeuer['spec']
|
||||
assert 'loadBalancerIP' not in next(s for s in resources if s['kind']=='Service' and s['metadata']['name']=='factorio')['spec']
|
||||
for cm in (d for d in resources if d['kind']=='ConfigMap'):
|
||||
for name,value in cm.get('data',{}).items():
|
||||
if name.endswith('.json'): json.loads(value)
|
||||
|
||||
Reference in new issue
Block a user