From 40b8c450bd57e1c7ced56a039924372c0a16d0a1 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 11 May 2020 23:10:56 +0200 Subject: [PATCH] Add support for depend. --- example/gateway/focker-compose.yml | 4 +++- focker/compose.py | 36 +++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/example/gateway/focker-compose.yml b/example/gateway/focker-compose.yml index f076a86..d01c3fb 100644 --- a/example/gateway/focker-compose.yml +++ b/example/gateway/focker-compose.yml @@ -46,7 +46,9 @@ jails: nginx-https: image: nginx-https - depend: certbot + depend: + - certbot + - nginx-http mounts: certbot-data: /usr/local/etc/letsencrypt exec.start: | diff --git a/focker/compose.py b/focker/compose.py index 55cc809..928fa03 100644 --- a/focker/compose.py +++ b/focker/compose.py @@ -17,7 +17,8 @@ from .zfs import AmbiguousValueError, \ from .jail import jail_fs_create, \ jail_create, \ jail_remove, \ - backup_file + backup_file, \ + quote from .misc import random_sha256_hexdigest, \ find_prefix import subprocess @@ -25,6 +26,7 @@ import jailconf import os from .misc import focker_lock, \ focker_unlock +import pdb def exec_prebuild(spec, path): @@ -81,12 +83,31 @@ def build_images(spec, path, args): raise RuntimeError('Image build failed: ' + str(res.returncode)) +def setup_dependencies(spec, generated_names): + if os.path.exists('/etc/jail.conf'): + conf = jailconf.load('/etc/jail.conf') + else: + conf = jailconf.JailConf() + for (jailname, jailspec) in spec.items(): + if 'depend' not in jailspec: + continue + depend = jailspec.get('depend', []) + if isinstance(depend, str): + depend = [ depend ] + if not isinstance(depend, list): + raise ValueError('depend must be a string or a list of strings') + # pdb.set_trace() + depend = list(map(lambda a: generated_names[a], depend)) + if len(depend) == 1: + depend = depend[0] + conf[generated_names[jailname]]['depend'] = \ + depend + conf.write('/etc/jail.conf') + + def build_jails(spec): - #if os.path.exists('/etc/jail.conf'): - # conf = jailconf.load('/etc/jail.conf') - #else: - # conf = jailconf.JailConf() backup_file('/etc/jail.conf') + generated_names = {} for (jailname, jailspec) in spec.items(): try: name, _ = zfs_find(jailname, focker_type='jail') @@ -99,7 +120,8 @@ def build_jails(spec): zfs_untag([ jailname ], focker_type='jail') zfs_tag(name, [ jailname ]) path = zfs_mountpoint(name) - jail_create(path, + generated_names[jailname] = \ + jail_create(path, jailspec.get('exec.start', '/bin/sh /etc/rc'), jailspec.get('env', {}), [ [from_, on] \ @@ -111,6 +133,8 @@ def build_jails(spec): 'interface': jailspec.get('interface', 'lo1') }) + setup_dependencies(spec, generated_names) + def command_compose_build(args): if not os.path.exists(args.filename):