2019-09-20 10:13:41 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from .builder import Builder, ImageExistsError, ImageNotFoundError
|
|
|
|
from .packer import Packer, PackageExistsError
|
|
|
|
|
|
|
|
class Image:
|
|
|
|
def __init__(self, lxcfile):
|
|
|
|
self.name = None
|
|
|
|
self.path = None
|
|
|
|
self.conf = {}
|
|
|
|
self.lxcfile = lxcfile
|
|
|
|
self.build_dir = os.path.dirname(lxcfile)
|
|
|
|
|
2019-09-23 15:34:37 +02:00
|
|
|
def build_and_pack(self, force):
|
2019-09-20 10:13:41 +02:00
|
|
|
self.conf['build'] = True
|
|
|
|
try:
|
|
|
|
builder = Builder()
|
|
|
|
builder.build(self, force)
|
2019-09-23 15:34:37 +02:00
|
|
|
# In case of successful build, packaging needs to happen in all cases to prevent outdated packages
|
2019-09-20 10:13:41 +02:00
|
|
|
force = True
|
|
|
|
except ImageExistsError as e:
|
|
|
|
print('Image {} already exists, skipping build tasks'.format(e))
|
|
|
|
except ImageNotFoundError as e:
|
|
|
|
print('Image {} not found, can\'t build {}'.format(e, self.name))
|
|
|
|
builder.clean()
|
|
|
|
sys.exit(1)
|
|
|
|
except:
|
|
|
|
builder.clean()
|
|
|
|
raise
|
2019-09-23 15:34:37 +02:00
|
|
|
del self.conf['build']
|
2019-09-20 10:13:41 +02:00
|
|
|
try:
|
|
|
|
packer = Packer()
|
|
|
|
packer.pack_image(self, force)
|
|
|
|
except PackageExistsError as e:
|
|
|
|
print('Package {} already exists, skipping packaging tasks'.format(e))
|