From ac5b6f7ac875b999b6347119160dbb237cd81f59 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 4 May 2020 14:03:37 +0200 Subject: [PATCH] Added support for chown, chmod and zfs props in volume compose. --- example/gitea/focker-compose.yml | 6 +++++- focker/compose.py | 28 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/example/gitea/focker-compose.yml b/example/gitea/focker-compose.yml index 0c7e467..d00b846 100644 --- a/example/gitea/focker-compose.yml +++ b/example/gitea/focker-compose.yml @@ -6,7 +6,11 @@ images: certbot-latest: ../certbot volumes: - gitea-data: {} + gitea-data: + chmod: 0750 + chown: 211:211 + zfs: + quota: 5G certbot-webroot: {} certbot-config-gitea: {} diff --git a/focker/compose.py b/focker/compose.py index bdfb4f6..ecffb71 100644 --- a/focker/compose.py +++ b/focker/compose.py @@ -12,7 +12,8 @@ from .zfs import AmbiguousValueError, \ zfs_tag, \ zfs_untag, \ zfs_mountpoint, \ - zfs_poolname + zfs_poolname, \ + zfs_set_props from .jail import jail_fs_create, \ jail_create, \ jail_remove @@ -25,19 +26,26 @@ import os def build_volumes(spec): poolname = zfs_poolname() - for tag in spec.keys(): + for tag, params in spec.items(): + name = None try: name, _ = zfs_find(tag, focker_type='volume') - continue - except AmbiguousValueError: - raise except ValueError: pass - sha256 = random_sha256_hexdigest() - name = find_prefix(poolname + '/focker/volumes/', sha256) - subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) - zfs_untag([ tag ], focker_type='volume') - zfs_tag(name, [ tag ]) + if name is None: + sha256 = random_sha256_hexdigest() + name = find_prefix(poolname + '/focker/volumes/', sha256) + subprocess.check_output(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name]) + zfs_untag([ tag ], focker_type='volume') + zfs_tag(name, [ tag ]) + mountpoint = zfs_mountpoint(name) + print('params:', params) + if 'chown' in params: + os.chown(mountpoint, *map(int, params['chown'].split(':'))) + if 'chmod' in params: + os.chmod(mountpoint, params['chmod']) + if 'zfs' in params: + zfs_set_props(name, params['zfs']) def build_images(spec, path):