Example #1
0
def _deploy_package(path, layer, logger, dependencies, params):
    """Creates a deployment package for multi-file lambda with deps."""
    with utils.move_aside(path) as tmppath:
        # removes __* and .* dirs
        _cleanup_dir(tmppath)
        # render Jinja2 templated files
        template_params = layer.loader_params
        template_params.update(params)
        _preprocess_dir(tmppath, template_params)
        setup_file = os.path.join(tmppath, 'setup.py')
        if os.path.isfile(setup_file):
            # Install all depedendencies in the same dir
            subprocess.check_call([
                sys.executable, '-m', 'pip', 'install', tmppath, '-t', tmppath
            ])
        requirements_file = os.path.join(tmppath, 'requirements.txt')
        if os.path.isfile(requirements_file):
            subprocess.check_call([
                sys.executable, '-m', 'pip', 'install', '-r',
                requirements_file, '-t', tmppath
            ])

        if dependencies:
            _install_dependencies(layer, tmppath, dependencies)

        suffix = str(uuid.uuid4())
        tmpdir = tempfile.mkdtemp()
        basename = os.path.basename(path)
        zipfile = os.path.join(tmpdir, "{}{}{}".format(basename, suffix,
                                                       '.zip'))
        with ZipFile(zipfile, 'w') as myzip:
            utils.zipdir(tmppath, myzip)
        yield zipfile
        shutil.rmtree(tmpdir)
Example #2
0
def _deploy_package(path, layer, logger, dependencies, params):
    """Creates a deployment package for multi-file lambda with deps."""
    with utils.move_aside(path) as tmppath:
        # removes __* and .* dirs
        _cleanup_dir(tmppath)
        # render Jinja2 templated files
        template_params = layer.loader_params
        template_params.update(params)
        _preprocess_dir(tmppath, template_params)
        setup_file = os.path.join(tmppath, 'setup.py')
        if os.path.isfile(setup_file):
            # Install all depedendencies in the same dir
            pip.main(['install', tmppath, '-t', tmppath])
        requirements_file = os.path.join(tmppath, 'requirements.txt')
        if os.path.isfile(requirements_file):
            pip.main(['install', '-r', requirements_file, '-t', tmppath])

        if dependencies:
            _install_dependencies(layer, tmppath, dependencies)

        # Adding the HEAD hash is needed for CF to detect that the contents of
        # of the .zip file have changed when requesting a stack update.
        gc = _git_head()
        suffix = ('-' + gc + str(uuid.uuid4()), str(uuid.uuid4()))[gc is None]
        tmpdir = tempfile.mkdtemp()
        basename = os.path.basename(path)
        zipfile = os.path.join(tmpdir, "{}{}{}".format(basename, suffix,
                                                       '.zip'))
        with ZipFile(zipfile, 'w') as myzip:
            utils.zipdir(tmppath, myzip)
        yield zipfile
        shutil.rmtree(tmpdir)
Example #3
0
def _deploy_package(path, layer, logger, dependencies=None):
    """Creates a deployment package for multi-file lambda with deps."""
    with utils.move_aside(path) as tmppath:
        # removes __* and .* dirs
        _cleanup_dir(tmppath)
        # render Jinja2 templated files
        _preprocess_dir(tmppath, layer.loader_params)
        setup_file = os.path.join(tmppath, 'setup.py')
        if os.path.isfile(setup_file):
            # Install all depedendencies in the same dir
            pip.main(['install', tmppath, '-t', tmppath])
        requirements_file = os.path.join(tmppath, 'requirements.txt')
        if os.path.isfile(requirements_file):
            pip.main(['install', '-r', requirements_file, '-t', tmppath])

        if dependencies:
            _install_dependencies(layer, tmppath, dependencies)

        # Adding the HEAD hash is needed for CF to detect that the contents of
        # of the .zip file have changed when requesting a stack update.
        gc = _git_head()
        suffix = ('-' + gc, '')[gc is None]
        tmpdir = tempfile.mkdtemp()
        basename = os.path.basename(path)
        zipfile = os.path.join(tmpdir, "{}{}{}".format(basename, suffix,
                                                       '.zip'))
        with ZipFile(zipfile, 'w') as myzip:
            utils.zipdir(tmppath, myzip)
        yield zipfile
        shutil.rmtree(tmpdir)
Example #4
0
def _simple_deploy_package(path, layer, logger):
    """Creates a deployment package for a one-file no-deps lambda."""
    logger.info("Creating deployment package for '{}'".format(path))
    with utils.move_aside(path) as tmppath:
        _preprocess_file(tmppath, layer.loader_params)
        path_no_ext, ext = os.path.splitext(tmppath)
        basename = os.path.basename(path_no_ext)
        gc = _git_head()
        suffix = ('-' + gc, '')[gc is None]
        tmpdir = tempfile.mkdtemp()
        zipfile = os.path.join(tmpdir,
                               "{}{}{}".format(basename, suffix, '.zip'))
        with ZipFile(zipfile, 'w') as myzip:
            myzip.write(tmppath, arcname=basename + ext)
        yield zipfile
        shutil.rmtree(tmpdir)
Example #5
0
def _simple_deploy_package(path, layer, logger, params):
    """Creates a deployment package for a one-file no-deps lambda."""
    logger.info("Creating deployment package for '{}'".format(path))
    with utils.move_aside(path) as tmppath:
        template_params = layer.loader_params
        template_params.update(params)
        _preprocess_file(tmppath, template_params)
        path_no_ext, ext = os.path.splitext(tmppath)
        basename = os.path.basename(path_no_ext)
        gc = _git_head()
        suffix = ('-' + gc, '')[gc is None]
        tmpdir = tempfile.mkdtemp()
        zipfile = os.path.join(tmpdir, "{}{}{}".format(basename, suffix,
                                                       '.zip'))
        with ZipFile(zipfile, 'w') as myzip:
            myzip.write(tmppath, arcname=basename + ext)
        yield zipfile
        shutil.rmtree(tmpdir)