Exemplo n.º 1
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Creates a CodeCommit repository called 'WorkshopRepo'
        repo = codecommit.Repository(self,
                                     'WorkshopRepo',
                                     repository_name="WorkshopRepo")

        # Defines the artifact representing the sourcecode
        source_artifact = codepipeline.Artifact()
        # Defines the artifact representing the cloud assembly
        # (cloudformation template + all other assets)
        cloud_assembly_artifact = codepipeline.Artifact()

        pipeline = pipelines.CdkPipeline(
            self,
            'Pipeline',
            cloud_assembly_artifact=cloud_assembly_artifact,

            # Generates the source artifact from the repo we created in the last step
            source_action=codepipeline_actions.CodeCommitSourceAction(
                action_name='CodeCommit',  # Any Git-based source control
                output=source_artifact,  # Indicates where the artifact is stored
                repository=repo  # Designates the repo to draw code from
            ),

            # Builds our source code outlined above into a could assembly artifact
            synth_action=pipelines.SimpleSynthAction(
                install_commands=[
                    'npm install -g aws-cdk',  # Installs the cdk cli on Codebuild
                    'pip install -r requirements.txt'  # Instructs Codebuild to install required packages
                ],
                synth_command='npx cdk synth',
                source_artifact=
                source_artifact,  # Where to get source code to build
                cloud_assembly_artifact=
                cloud_assembly_artifact,  # Where to place built source
            ))

        deploy = WorkshopPipelineStage(self, 'Deploy')
        deploy_stage = pipeline.add_application_stage(deploy)
        deploy_stage.add_actions(
            pipelines.ShellScriptAction(action_name='TestViewerEndpoint',
                                        use_outputs={
                                            'ENDPOINT_URL':
                                            pipeline.stack_output(
                                                deploy.hc_viewer_url)
                                        },
                                        commands=['curl -Ssf $ENDPOINT_URL']))
        deploy_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name='TestAPIGatewayEndpoint',
                use_outputs={
                    'ENDPOINT_URL': pipeline.stack_output(deploy.hc_endpoint)
                },
                commands=[
                    'curl -Ssf $ENDPOINT_URL', 'curl -Ssf $ENDPOINT_URL/hello',
                    'curl -Ssf $ENDPOINT_URL/test'
                ]))
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()
        cloud_assembly_artifact = codepipeline.Artifact()

        # Install_command - installs CDK
        pipeline = pipelines.CdkPipeline(
            self,
            'Pipeline',
            cloud_assembly_artifact=cloud_assembly_artifact,
            pipeline_name='Webinar_Pipeline',
            source_action=cpactions.GitHubSourceAction(
                action_name='GitHub',
                output=source_artifact,
                oauth_token=core.SecretValue.secrets_manager('github-token'),
                owner='kevinggrimm',
                repo='aws-cdk-pipeline',
                trigger=cpactions.GitHubTrigger.POLL),
            synth_action=pipelines.SimpleSynthAction(
                source_artifact=source_artifact,
                cloud_assembly_artifact=cloud_assembly_artifact,
                install_command=
                'npm install -g aws-cdk && pip install -r requirements.txt',
                build_command='pytest unittests',
                synth_command='cdk synth'))

        # Can be a different account and region
        # Easy ability to deploy to different regions, accounts
        pre_prod_app = WebServiceStage(self,
                                       'Pre-prod',
                                       env=core.Environment(
                                           account="893961191302",
                                           region="us-west-1"))

        pre_prod_stage = pipeline.add_application_stage(pre_prod_app)

        # use_outputs - give env var to fill; ask pipeline for stack output represented by URL
        pre_prod_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name='Integ',
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    'pip install -r requirements.txt',
                    'pytest integtests',
                ],

                # Output represented by URL output
                # Can create identifiable outputs for usage in pipeline
                use_outputs={
                    'SERVICE_URL':
                    pipeline.stack_output(pre_prod_app.url_output)
                }))

        pipeline.add_application_stage(
            WebServiceStage(self,
                            'Prod',
                            env=core.Environment(account="893961191302",
                                                 region="us-west-1")))
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()
        cloud_assembly_artifact = codepipeline.Artifact()

        pipeline = pipelines.CdkPipeline(
            self,
            'Pipeline',
            cloud_assembly_artifact=cloud_assembly_artifact,
            pipeline_name='CdkPipeline',
            source_action=cpactions.GitHubSourceAction(
                action_name='Github',
                oauth_token=core.SecretValue.secrets_manager('github-token'),
                output=source_artifact,
                owner='bgreengo',
                repo='aws-cdk-python-pipelines',
                trigger=cpactions.GitHubTrigger.POLL),
            synth_action=pipelines.SimpleSynthAction(
                source_artifact=source_artifact,
                cloud_assembly_artifact=cloud_assembly_artifact,
                install_command=
                'npm install -g aws-cdk && pip install -r requirements.txt',
                build_command='pytest unittests',
                synth_command='cdk synth'))

        pre_prod_app = WebServiceStage(self,
                                       'Pre-Prod',
                                       env={
                                           'account': '987092829714',
                                           'region': 'us-west-2'
                                       })

        pre_prod_stage = pipeline.add_application_stage(pre_prod_app)

        pre_prod_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name='Integ',
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    'pip install -r requirements.txt',
                    'pytest integtests',
                ],
                use_outputs={
                    'SERVICE_URL':
                    pipeline.stack_output(pre_prod_app.url_output)
                }))

        pipeline.add_application_stage(
            WebServiceStage(self,
                            'Prod',
                            env={
                                'account': '987092829714',
                                'region': 'us-west-2'
                            }))
Exemplo n.º 4
0
    def __init__(self, scope: core.Construct, id: str, **kwargs):
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()
        cloud_assembly_artifact = codepipeline.Artifact()

        pipeline = pipelines.CdkPipeline(
            self,
            'Pipeline',
            cloud_assembly_artifact=cloud_assembly_artifact,
            pipeline_name='WebinarPipeline',
            source_action=cpactions.GitHubSourceAction(
                action_name='GitHub',
                output=source_artifact,
                oauth_token=core.SecretValue.secrets_manager('GITHUB-TOKEN'),
                owner='ajaykumar011',
                repo='my-pipeline',
                branch='main',
                trigger=cpactions.GitHubTrigger.POLL),
            synth_action=pipelines.SimpleSynthAction(
                source_artifact=source_artifact,
                cloud_assembly_artifact=cloud_assembly_artifact,
                install_command=
                'npm install -g aws-cdk && pip install -r requirements.txt && pip install pytest',
                build_command='pytest unittests',
                synth_command='cdk synth'))

        pre_prod_app = WebServiceStage(
            self,
            'Pre-Prod',
            env={
                'account': PRE_PROD_ACCOUNT,
                'region':
                'ap-south-1',  #This is the same region where pipeline is
            })
        pre_prod_stage = pipeline.add_application_stage(pre_prod_app)
        pre_prod_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name='Integ',
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    'pip install -r requirements.txt',
                    'pip install requests',
                    'pip install pytest',
                    'pytest integtests',
                ],
                use_outputs={
                    'SERVICE_URL':
                    pipeline.stack_output(pre_prod_app.url_output)
                }))
 def shellscript_action(source_artifact, pipeline, app_stage,
                        policy_statement):
     return pipelines.ShellScriptAction(
         action_name="deployToS3",
         additional_artifacts=[source_artifact],
         commands=[
             "echo $sourceBucketName",
             "npm install",
             "npm run build",
             "aws s3 sync ./public s3://$sourceBucketName/ --delete",
         ],
         use_outputs={
             "sourceBucketName":
             pipeline.stack_output(app_stage.sourceBucketName),
         },
         role_policy_statements=policy_statement)
Exemplo n.º 6
0
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, **kwargs)
        source_artifact = codepipeline.Artifact()
        cloud_assembly_artifact = codepipeline.Artifact()

        pipeline = pipelines.CdkPipeline(
            self,
            "Pipeline",
            cloud_assembly_artifact=cloud_assembly_artifact,
            pipeline_name="WebinarPipeline",
            source_action=cpactions.GitHubSourceAction(
                action_name="GitHub",
                output=source_artifact,
                oauth_token=core.SecretValue.secrets_manager("github-token"),
                owner="bwarren2",
                repo="webinar-pipeline",
                trigger=cpactions.GitHubTrigger.POLL,
            ),
            synth_action=pipelines.SimpleSynthAction(
                source_artifact=source_artifact,
                cloud_assembly_artifact=cloud_assembly_artifact,
                install_command=
                "npm install -g aws-cdk && pip install -r requirements.txt",
                synth_command="cdk synth",
            ),
        )
        pre_prod_app = WebServiceStage(
            self,
            "Pre-Prod",
            env={
                "account": "871089662319",
                "region": "us-east-1",
            },
        )
        pre_prod_stage = pipeline.add_application_stage(pre_prod_app)
        pre_prod_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name="UnitTest",
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    "pip install -r requirements.txt", "pytest unittests"
                ],
            ),
            pipelines.ShellScriptAction(
                action_name="Integ",
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    "pip install -r requirements.txt", "pytest integtests"
                ],
                use_outputs={
                    "SERVICE_URL":
                    pipeline.stack_output(pre_prod_app.url_output)
                },
            ),
        )
        pipeline.add_application_stage(
            WebServiceStage(
                self,
                "Prod",
                env={
                    "account": "871089662319",
                    "region": "us-east-1",
                },
            ))
Exemplo n.º 7
0
    def __init__(self, scope: core.Construct, id: str, config: BaseSettings,
                 **kwargs):
        super().__init__(scope, id, **kwargs)

        source_artifact = codepipeline.Artifact()

        cloud_assembly_artifact = codepipeline.Artifact()

        source_action = pipeline_actions.GitHubSourceAction(
            action_name="GitHub",
            output=source_artifact,
            oauth_token=core.SecretValue.secrets_manager("github-token"),
            owner=config.gh_username,
            repo=config.gh_repo,
            trigger=pipeline_actions.GitHubTrigger.POLL,
        )

        synth_action = pipelines.SimpleSynthAction(
            source_artifact=source_artifact,
            cloud_assembly_artifact=cloud_assembly_artifact,
            install_commands=[
                "npm install -g aws-cdk",
                "pip install -r requirements.txt",
            ],
            test_commands=["pytest lambdas -v -m 'not integration'"],
            synth_command="cdk synth application",
            environment=codebuild.BuildEnvironment(privileged=True),
        )

        pipeline = pipelines.CdkPipeline(
            self,
            "pipeline",
            cloud_assembly_artifact=cloud_assembly_artifact,
            pipeline_name="hello-pipeline",
            source_action=source_action,
            synth_action=synth_action,
        )

        pre_prod_app = WebServiceStage(
            self,
            "preprod",
            env={
                "account": config.account,
                "region": config.region,
            },
        )

        pre_prod_stage = pipeline.add_application_stage(pre_prod_app)

        pre_prod_stage.add_actions(
            pipelines.ShellScriptAction(
                action_name="integration_tests",
                run_order=pre_prod_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                commands=[
                    "pip install -r requirements.txt",
                    "pytest lambdas -v -m integration",
                ],
                use_outputs={
                    "http_api_url":
                    pipeline.stack_output(pre_prod_app.service.http_api_url)
                },
            ))

        pre_prod_stage.add_manual_approval_action(action_name="PromoteToProd")

        prod_app = WebServiceStage(
            self,
            "Prod",
            env={
                "account": config.account,
                "region": config.region,
            },
        )

        pipeline.add_application_stage(prod_app)