Exemple #1
0
def create_build_stage(osutils, ui, swagger_gen):
    # type: (OSUtils, UI, SwaggerGenerator) -> BuildStage
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils),
                           osutils=osutils)
    dependency_builder = PipDependencyBuilder(
        osutils=osutils,
        pip_runner=pip_runner
    )
    build_stage = BuildStage(
        steps=[
            InjectDefaults(),
            DeploymentPackager(
                packager=LambdaDeploymentPackager(
                    osutils=osutils,
                    dependency_builder=dependency_builder,
                    ui=ui,
                ),
            ),
            PolicyGenerator(
                policy_gen=AppPolicyGenerator(
                    osutils=osutils
                ),
                osutils=osutils,
            ),
            SwaggerBuilder(
                swagger_generator=swagger_gen,
            ),
            LambdaEventSourcePolicyInjector(),
            WebsocketPolicyInjector()
        ],
    )
    return build_stage
Exemple #2
0
def create_default_deployer(session, config, ui):
    # type: (Session, Config, UI) -> Deployer
    client = TypedAWSClient(session)
    osutils = OSUtils()
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils), osutils=osutils)
    dependency_builder = PipDependencyBuilder(osutils=osutils,
                                              pip_runner=pip_runner)
    return Deployer(
        application_builder=ApplicationGraphBuilder(),
        deps_builder=DependencyBuilder(),
        build_stage=BuildStage(steps=[
            InjectDefaults(),
            DeploymentPackager(packager=LambdaDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=UI(),
            ), ),
            PolicyGenerator(policy_gen=AppPolicyGenerator(osutils=osutils), ),
            SwaggerBuilder(swagger_generator=TemplatedSwaggerGenerator(), )
        ], ),
        plan_stage=PlanStage(
            osutils=osutils,
            remote_state=RemoteState(
                client, config.deployed_resources(config.chalice_stage)),
        ),
        sweeper=UnreferencedResourcePlanner(),
        executor=Executor(client, ui),
        recorder=ResultsRecorder(osutils=osutils),
    )
Exemple #3
0
def test_does_handle_missing_dependency_error(tmpdir, capsys):
    appdir = _create_app_structure(tmpdir)
    builder = mock.Mock(spec=DependencyBuilder)
    fake_package = mock.Mock(spec=Package)
    fake_package.identifier = 'foo==1.2'
    builder.build_site_packages.side_effect = MissingDependencyError(
        set([fake_package]))
    packager = LambdaDeploymentPackager(dependency_builder=builder)
    packager.create_deployment_package(str(appdir), 'python2.7')

    out, _ = capsys.readouterr()
    assert 'Could not install dependencies:\nfoo==1.2' in out
Exemple #4
0
def create_default_deployer(session, prompter=None):
    # type: (botocore.session.Session, NoPrompt) -> Deployer
    if prompter is None:
        prompter = NoPrompt()
    aws_client = TypedAWSClient(session)
    api_gateway_deploy = APIGatewayDeployer(aws_client)

    osutils = OSUtils()
    packager = LambdaDeploymentPackager(osutils=osutils)
    lambda_deploy = LambdaDeployer(
        aws_client, packager, prompter, osutils,
        ApplicationPolicyHandler(osutils, AppPolicyGenerator(osutils)))
    return Deployer(api_gateway_deploy, lambda_deploy)
Exemple #5
0
def create_app_packager(config):
    # type: (Config) -> AppPackager
    osutils = OSUtils()
    # The config object does not handle a default value
    # for autogen'ing a policy so we need to handle this here.
    return AppPackager(
        # We're add place holder values that will be filled in once the
        # lambda function is deployed.
        SAMTemplateGenerator(
            CFNSwaggerGenerator('{region}', {}),
            PreconfiguredPolicyGenerator(
                config,
                ApplicationPolicyHandler(osutils,
                                         AppPolicyGenerator(osutils)))),
        LambdaDeploymentPackager())
Exemple #6
0
 def create_deployment_package(self,
                               project_dir,
                               python_version,
                               package_filename=None):
     deployment_package_filename = self.deployment_package_filename(
         project_dir, python_version)
     if os.path.exists(deployment_package_filename):
         self.inject_latest_app(deployment_package_filename, project_dir)
         return deployment_package_filename
     else:
         return LambdaDeploymentPackager.create_deployment_package(
             self,
             project_dir,
             python_version,
             package_filename=package_filename)
Exemple #7
0
def create_default_deployer(session, ui=None):
    # type: (botocore.session.Session, UI) -> Deployer
    if ui is None:
        ui = UI()
    aws_client = TypedAWSClient(session)
    api_gateway_deploy = APIGatewayDeployer(aws_client, ui)

    osutils = OSUtils()
    dependency_builder = DependencyBuilder(osutils)
    packager = LambdaDeploymentPackager(osutils=osutils,
                                        dependency_builder=dependency_builder,
                                        ui=ui)
    lambda_deploy = LambdaDeployer(
        aws_client, packager, ui, osutils,
        ApplicationPolicyHandler(osutils, AppPolicyGenerator(osutils)))
    return Deployer(api_gateway_deploy, lambda_deploy, ui)
Exemple #8
0
def test_does_handle_missing_dependency_error(tmpdir):
    appdir = _create_app_structure(tmpdir)
    builder = mock.Mock(spec=DependencyBuilder)
    fake_package = mock.Mock(spec=Package)
    fake_package.identifier = 'foo==1.2'
    builder.build_site_packages.side_effect = MissingDependencyError(
        set([fake_package]))
    ui = mock.Mock(spec=chalice.utils.UI)
    osutils = chalice.utils.OSUtils()
    packager = LambdaDeploymentPackager(
        osutils=osutils,
        dependency_builder=builder,
        ui=ui,
    )
    packager.create_deployment_package(str(appdir), 'python2.7')

    output = ''.join([call[0][0] for call in ui.write.call_args_list])
    assert 'Could not install dependencies:\nfoo==1.2' in output
Exemple #9
0
def create_build_stage(osutils, ui, swagger_gen, config):
    # type: (OSUtils, UI, SwaggerGenerator, Config) -> BuildStage
    pip_runner = PipRunner(pip=SubprocessPip(osutils=osutils), osutils=osutils)
    dependency_builder = PipDependencyBuilder(osutils=osutils,
                                              pip_runner=pip_runner)
    deployment_packager = cast(BaseDeployStep, None)
    if config.automatic_layer:
        deployment_packager = ManagedLayerDeploymentPackager(
            lambda_packager=AppOnlyDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ),
            layer_packager=LayerDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ))
    else:
        deployment_packager = DeploymentPackager(
            packager=LambdaDeploymentPackager(
                osutils=osutils,
                dependency_builder=dependency_builder,
                ui=ui,
            ))
    build_stage = BuildStage(steps=[
        InjectDefaults(), deployment_packager,
        PolicyGenerator(
            policy_gen=AppPolicyGenerator(osutils=osutils),
            osutils=osutils,
        ),
        SwaggerBuilder(swagger_generator=swagger_gen, ),
        LambdaEventSourcePolicyInjector(),
        WebsocketPolicyInjector()
    ], )
    return build_stage