IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.2KB

  1. from .zfs import *
  2. import os
  3. import yaml
  4. from .steps import create_step
  5. from .snapshot import new_snapshot
  6. def process_step(step, name):
  7. cmd=['jail', '-c']
  8. cmd.append('path=' + '/focker/' + name)
  9. def process_steps(steps, name):
  10. if isinstance(steps, list):
  11. for step in steps:
  12. process_step(step, name)
  13. else:
  14. process_step(steps, name)
  15. def build(spec, args):
  16. if 'base' not in spec:
  17. raise ValueError('Missing base in specification')
  18. if 'steps' not in spec:
  19. raise ValueError('Missing steps in specification')
  20. base = spec['base']
  21. base, base_sha256 = zfs_snapshot_by_tag_or_sha256(base)
  22. root = '/'.join(base.split('/')[:-1])
  23. print('base:', base, 'root:', root)
  24. steps = spec['steps']
  25. if not isinstance(steps, list):
  26. steps = [ steps ]
  27. for st in steps:
  28. st = create_step(st)
  29. st_sha256 = st.hash(base_sha256, args=args)
  30. if zfs_exists_snapshot_sha256(st_sha256):
  31. base = zfs_snapshot_by_sha256(st_sha256)
  32. base_sha256 = st_sha256
  33. print('Reusing:', base)
  34. continue
  35. for pre in range(7, 64):
  36. name = root + '/' + st_sha256[:pre]
  37. if not zfs_exists(name):
  38. break
  39. snap_name = new_snapshot(base, lambda: st.execute(zfs_mountpoint(name), args=args), name)
  40. feed = {
  41. 'focker:sha256': st_sha256
  42. }
  43. zfs_set_props(name, feed)
  44. # zfs_set_props(snap_name, feed)
  45. base = snap_name
  46. base_sha256 = st_sha256
  47. return (base, base_sha256)
  48. def command_image_build(args):
  49. # os.chdir(args.focker_dir)
  50. fname = os.path.join(args.focker_dir, 'Fockerfile')
  51. print('fname:', fname)
  52. if not os.path.exists(fname):
  53. raise ValueError('No Fockerfile could be found in the specified directory')
  54. with open(fname, 'r') as f:
  55. spec = yaml.safe_load(f)
  56. print('spec:', spec)
  57. image, image_sha256 = build(spec, args)
  58. zfs_untag(args.tag)
  59. zfs_tag(image.split('@')[0], args.tag)
  60. def command_image_untag(args):
  61. zfs_untag(args.tags)