@@ -15,6 +15,7 @@ def create_parser(): | |||||
parser = subparsers.add_parser('build') | parser = subparsers.add_parser('build') | ||||
parser.set_defaults(func=command_image_build) | parser.set_defaults(func=command_image_build) | ||||
parser.add_argument('focker_dir', type=str) | parser.add_argument('focker_dir', type=str) | ||||
parser.add_argument('--tag', '-t', type=str, nargs='+', default=[]) | |||||
return parser_top | return parser_top | ||||
@@ -51,11 +51,13 @@ def build(spec): | |||||
feed = { | feed = { | ||||
'focker:sha256': st_sha256 | 'focker:sha256': st_sha256 | ||||
} | } | ||||
zfs_tag(name, feed) | |||||
# zfs_tag(snap_name, feed) | |||||
zfs_set_props(name, feed) | |||||
# zfs_set_props(snap_name, feed) | |||||
base = snap_name | base = snap_name | ||||
base_sha256 = st_sha256 | base_sha256 = st_sha256 | ||||
return (base, base_sha256) | |||||
def command_image_build(args): | def command_image_build(args): | ||||
fname = os.path.join(args.focker_dir, 'Fockerfile') | fname = os.path.join(args.focker_dir, 'Fockerfile') | ||||
@@ -65,4 +67,6 @@ def command_image_build(args): | |||||
with open(fname, 'r') as f: | with open(fname, 'r') as f: | ||||
spec = yaml.safe_load(f) | spec = yaml.safe_load(f) | ||||
print('spec:', spec) | print('spec:', spec) | ||||
build(spec) | |||||
image, image_sha256 = build(spec) | |||||
zfs_untag(args.tag) | |||||
zfs_tag(image.split('@')[0], args.tag) |
@@ -44,7 +44,7 @@ def zfs_exists(name): | |||||
return True | return True | ||||
def zfs_tag(name, props): | |||||
def zfs_set_props(name, props): | |||||
for (k, v) in props.items(): | for (k, v) in props.items(): | ||||
zfs_run(['zfs', 'set', k + '=' + v, name]) | zfs_run(['zfs', 'set', k + '=' + v, name]) | ||||
@@ -72,6 +72,23 @@ def zfs_snapshot_by_sha256(sha256): | |||||
return lst[0][1] | return lst[0][1] | ||||
def zfs_tag(name, tags): | |||||
if len(tags) > 0: | |||||
zfs_run(['zfs', 'set', 'focker:tags=' + ' '.join(tags), name]) | |||||
else: | |||||
zfs_run(['zfs', 'inherit', 'focker:tags', name]) | |||||
def zfs_untag(tags): | |||||
lst = zfs_parse_output(['zfs', 'list', '-o', 'name,focker:tags', '-H']) | |||||
lst = filter(lambda a: any([b in a[1].split(' ') for b in tags]), lst) | |||||
for row in lst: | |||||
cur_tags = row[1].split(' ') | |||||
for t in tags: | |||||
cur_tags.remove(t) | |||||
zfs_tag(row[0], cur_tags) | |||||
def zfs_init(): | def zfs_init(): | ||||
poolname = zfs_parse_output(['zfs', 'list', '-H', '/']) | poolname = zfs_parse_output(['zfs', 'list', '-H', '/']) | ||||
if len(poolname) == 0: | if len(poolname) == 0: | ||||