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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

81 lignes
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. feed = {
  40. 'focker:sha256': st_sha256
  41. }
  42. def atomic():
  43. st.execute(zfs_mountpoint(name), args=args)
  44. zfs_set_props(name, feed)
  45. snap_name = new_snapshot(base, atomic, name)
  46. # zfs_set_props(name, feed)
  47. # zfs_set_props(snap_name, feed)
  48. base = snap_name
  49. base_sha256 = st_sha256
  50. return (base, base_sha256)
  51. def command_image_build(args):
  52. # os.chdir(args.focker_dir)
  53. fname = os.path.join(args.focker_dir, 'Fockerfile')
  54. print('fname:', fname)
  55. if not os.path.exists(fname):
  56. raise ValueError('No Fockerfile could be found in the specified directory')
  57. with open(fname, 'r') as f:
  58. spec = yaml.safe_load(f)
  59. print('spec:', spec)
  60. image, image_sha256 = build(spec, args)
  61. zfs_untag(args.tag)
  62. zfs_tag(image.split('@')[0], args.tag)
  63. def command_image_untag(args):
  64. zfs_untag(args.tags)