Beispiel #1
0
def create_pkg_file(request):
    workdir = empty_dir(request)

    remote_path = "pkg.tar.gz"
    local_path = os.path.join(workdir, remote_path)
    d = tarfile.TarInfo('home')
    d.type = tarfile.DIRTYPE
    tar = tarfile.open(local_path, "w:gz")
    tar.addfile(d)
    tar.close()

    upaas_config = load_main_config()
    storage = load_handler(upaas_config.storage.handler,
                           upaas_config.storage.settings)
    storage.put(local_path, remote_path)

    def cleanup():
        try:
            storage.delete(remote_path)
        except FileNotFound:
            pass
    request.addfinalizer(cleanup)

    request.instance.storage = storage
    request.instance.pkg_file_path = remote_path
Beispiel #2
0
    def handle_flag(self, flag):

        app = flag.application
        self.app_name = app.name
        current_package = app.current_package
        force_fresh = flag.options.get(
            NeedsBuildingFlag.Options.build_fresh_package, False)
        interpreter_version = flag.options.get(
            NeedsBuildingFlag.Options.build_interpreter_version)

        system_filename = None
        current_revision = None
        if not force_fresh and current_package:
            system_filename = current_package.filename
            current_revision = current_package.revision_id
            interpreter_version = current_package.interpreter_version

        log.info(_("Building new package for {name} [{id}]").format(
            name=app.name, id=app.safe_id))

        task = self.create_task(app, flag.title, flag=flag.name)

        metadata = flag.application.metadata
        metadata_obj = flag.application.metadata_config
        if not metadata or not metadata_obj:
            log.error(_("Missing or invalid application metadata"))
            self.fail_flag(flag, task)

        upaas_config = load_main_config()
        if not upaas_config:
            log.error(_("Missing or invalid uPaaS configuration"))
            self.fail_flag(flag, task)

        log.info(_("Building package for application {name} "
                   "[{id}]").format(name=flag.application.name,
                                    id=flag.application.safe_id))
        log.info(_("Fresh package: {fresh}").format(fresh=force_fresh))
        log.info(_("Base image: {name}").format(name=system_filename))
        log.info(_("Interpreter version: {ver}").format(
            ver=interpreter_version))
        log.info(_("Current revision: {rev}").format(
            rev=current_revision))

        env = {'UPAAS_SYSTEM_DOMAIN': app.system_domain}
        for feature in app.feature_helper.load_enabled_features():
            feature.before_building(app)
            env = feature.update_env(app, env)

        build_result = None
        try:
            builder = Builder(upaas_config, metadata_obj)
            for result in builder.build_package(
                    system_filename=system_filename,
                    interpreter_version=interpreter_version,
                    current_revision=current_revision,
                    env=env):
                log.debug(_("Build progress: {proc}%").format(
                    proc=result.progress))
                build_result = result
                task.update(set__progress=result.progress)
        except BuildError:
            self.fail_flag(flag, task)
        else:
            self.create_package(app, task, metadata_obj, metadata,
                                build_result, current_package)
        self.mark_task_successful(task)
Beispiel #3
0
from pymongo import ReadPreference

from upaas_admin.config import load_main_config
import upaas_admin as project_module

from django.conf.global_settings import *   # pylint: disable=W0614,W0401


# basic logger needed to print startup errors
log = logging.basicConfig()


# =============================================================================
# UPaaS configuraton file
# =============================================================================
UPAAS_CONFIG = load_main_config()

if not UPAAS_CONFIG:
    print("Missing or invalid configuration file!")
    sys.exit(1)


# =============================================================================
# Generic Django project settings
# =============================================================================

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.dummy'
    }
}