Exemple #1
0
def generate_pipeline(ctx, codebuild_image, source, buildspec_file, filename):
    # type: (click.Context, str, str, str, str) -> None
    """Generate a cloudformation template for a starter CD pipeline.

    This command will write a starter cloudformation template to
    the filename you provide.  It contains a CodeCommit repo,
    a CodeBuild stage for packaging your chalice app, and a
    CodePipeline stage to deploy your application using cloudformation.

    You can use any AWS SDK or the AWS CLI to deploy this stack.
    Here's an example using the AWS CLI:

        \b
        $ chalice generate-pipeline pipeline.json
        $ aws cloudformation deploy --stack-name mystack \b
            --template-file pipeline.json --capabilities CAPABILITY_IAM
    """
    from chalice import pipeline
    factory = ctx.obj['factory']  # type: CLIFactory
    config = factory.create_config_obj()
    p = pipeline.CreatePipelineTemplate()
    params = pipeline.PipelineParameters(
        app_name=config.app_name,
        lambda_python_version=config.lambda_python_version,
        codebuild_image=codebuild_image,
        code_source=source,
    )
    output = p.create_template(params)
    if buildspec_file:
        extractor = pipeline.BuildSpecExtractor()
        buildspec_contents = extractor.extract_buildspec(output)
        with open(buildspec_file, 'w') as f:
            f.write(buildspec_contents)
    with open(filename, 'w') as f:
        f.write(serialize_to_json(output))
Exemple #2
0
def test_default_version_range_locks_minor_version():
    parts = [int(p) for p in chalice_version.split('.')]
    min_version = '%s.%s.%s' % (parts[0], parts[1], 0)
    max_version = '%s.%s.%s' % (parts[0], parts[1] + 1, 0)
    params = pipeline.PipelineParameters('appname', 'python2.7')
    assert params.chalice_version_range == '>=%s,<%s' % (min_version,
                                                         max_version)
Exemple #3
0
def pipeline_params():
    return pipeline.PipelineParameters('appname', 'python2.7')
Exemple #4
0
def test_can_create_buildspec_v2():
    params = pipeline.PipelineParameters('myapp', 'python3.7')
    buildspec = pipeline.create_buildspec_v2(params)
    assert buildspec['phases']['install']['runtime-versions'] == {
        'python': '3.7',
    }
Exemple #5
0
def test_can_extract_python_version():
    assert pipeline.PipelineParameters('app',
                                       'python3.7').py_major_minor == ('3.7')
Exemple #6
0
def test_can_validate_python_version():
    with pytest.raises(InvalidCodeBuildPythonVersion):
        pipeline.PipelineParameters('myapp',
                                    lambda_python_version='bad-python-value')