Ejemplo n.º 1
0
    def create_front_build_project(self, envs: EnvSettings, repos: dict):
        project = PipelineProject(
            self,
            "FrontendBuildProject",
            project_name=f"{envs.project_name}-build-frontend",
            environment=BuildEnvironment(
                environment_variables={
                    "NGINX_REPOSITORY_URI":
                    BuildEnvironmentVariable(
                        value=repos["nginx"].repository_uri),
                    "APP_REPOSITORY_URI":
                    BuildEnvironmentVariable(
                        value=repos["app"].repository_uri),
                    "WEBAPP_REPOSITORY_URI":
                    BuildEnvironmentVariable(
                        value=repos["webapp"].repository_uri),
                    "PUSH_IMAGES":
                    BuildEnvironmentVariable(value="1"),
                },
                build_image=LinuxBuildImage.STANDARD_2_0,
                privileged=True,
            ),
            build_spec=self.frontend_spec,
            cache=Cache.local(LocalCacheMode.DOCKER_LAYER),
        )

        for repo in repos.values():
            repo.grant_pull_push(project)

        return project
    def __init__(self, scope: core.Construct, id: str, *,
                    project_name: str,
                    github_owner,
                    github_repo,
                    buildspec_path = None,
                    environment_variables = {},
                    base_branch: str = "main",
                    release_branch: str = "bump_version",
                    create_webhooks = False):

        build_environment = BuildEnvironment(build_image=self.BUILD_IMAGE, privileged = True, compute_type = ComputeType.LARGE)

        trigger_on_pr_merged = FilterGroup.in_event_of(EventAction.PULL_REQUEST_MERGED).and_base_branch_is(base_branch).and_branch_is(release_branch).and_commit_message_is("release:.*")

        if create_webhooks:
            github_source = Source.git_hub(owner = github_owner,
                                            report_build_status = True,
                                            repo = github_repo,
                                            webhook = True,
                                            webhook_filters = [trigger_on_pr_merged])
        else:
            github_source = Source.git_hub(owner = github_owner,
                                            report_build_status = True,
                                            repo = github_repo)
            
        super().__init__(scope, id,
            project_name = project_name,
            environment_variables = environment_variables,
            build_spec=BuildSpec.from_object_to_yaml(BUILD_SPEC) if buildspec_path is None else BuildSpec.from_source_filename(buildspec_path),
            badge = True,
            source = github_source,
            environment = build_environment)
    def __init__(self,
                 scope: core.Construct,
                 id: str,
                 *,
                 project_name: str,
                 github_owner,
                 github_repo,
                 buildspec_path,
                 environment_variables={},
                 base_branch: str = "main"):

        build_environment = BuildEnvironment(build_image=self.BUILD_IMAGE,
                                             privileged=True,
                                             compute_type=ComputeType.LARGE)

        trigger_on_pr = FilterGroup.in_event_of(
            EventAction.PULL_REQUEST_CREATED,
            EventAction.PULL_REQUEST_UPDATED).and_base_branch_is(base_branch)

        super().__init__(
            scope,
            id,
            project_name=project_name,
            environment_variables=environment_variables,
            build_spec=BuildSpec.from_source_filename(buildspec_path),
            badge=True,
            source=Source.git_hub(owner=github_owner,
                                  report_build_status=True,
                                  repo=github_repo,
                                  webhook=True,
                                  webhook_filters=[trigger_on_pr]),
            environment=build_environment)
Ejemplo n.º 4
0
    def create_build_project(self, envs: EnvSettings):
        project = PipelineProject(
            self,
            "ImageResizeLambdaBuild",
            project_name=f"{envs.project_name}-build-image-resize-lambda",
            environment=BuildEnvironment(
                build_image=LinuxBuildImage.STANDARD_3_0),
            build_spec=BuildSpec.from_source_filename(
                "./infra/stacks/ci/buildspecs/image_resize.yaml"),
        )

        return project
Ejemplo n.º 5
0
 def create_synth_action(_source_artifact, _cloud_assembly_artifact,
                         _create_roles, _synth_accounts, additional_policy):
     return pipelines.SimpleSynthAction(
         source_artifact=_source_artifact,
         cloud_assembly_artifact=_cloud_assembly_artifact,
         install_command='npm install -g aws-cdk' + _create_roles,
         build_command="pip install -r requirements.txt",
         synth_command='cdk synth' + _synth_accounts +
         ' && cp cdk.json cdk.out',
         role_policy_statements=additional_policy,
         environment=BuildEnvironment(
             privileged=True,
             compute_type=ComputeType.LARGE,
             build_image=LinuxBuildImage.STANDARD_5_0),
     )
Ejemplo n.º 6
0
    def __init__(
        self, scope: Construct, id: str, envs: EnvSettings, build_stage: IStage, input_artifact: Artifacts,
    ):
        super().__init__(scope, id)

        project = PipelineProject(
            self,
            "CDKStackBuild",
            project_name=f"{envs.project_name}-build-stack",
            environment=BuildEnvironment(build_image=LinuxBuildImage.STANDARD_4_0, privileged=True,),
            build_spec=BuildSpec.from_source_filename("./infra/stacks/ci/buildspecs/cdk.yaml"),
            cache=Cache.local(LocalCacheMode.CUSTOM),
        )

        self.build_action = self.create_build_action("stack", project, input_artifact)
        build_stage.add_action(self.build_action)
Ejemplo n.º 7
0
    def create_build_projects(self, envs: EnvSettings, functions: List[Function]):
        projects = []

        for (function, code) in functions:
            function_name = self.get_function_base_name(function)
            project = PipelineProject(
                self,
                f"WorkerBuild-{function_name}",
                project_name=f"{envs.project_name}-build-{function_name}",
                environment=BuildEnvironment(build_image=LinuxBuildImage.STANDARD_3_0),
                build_spec=BuildSpec.from_source_filename("./infra/stacks/ci/buildspecs/workers.yaml"),
            )

            projects.append((project, function_name, code, function))

        return projects
Ejemplo n.º 8
0
    def create_backend_build_project(self, envs: EnvSettings,
                                     repo: Repository):
        project = PipelineProject(
            self,
            "BackendBuild",
            project_name=f"{envs.project_name}-build-backend",
            build_spec=self.backend_spec,
            environment=BuildEnvironment(
                environment_variables={
                    "REPOSITORY_URI":
                    BuildEnvironmentVariable(value=repo.repository_uri),
                    "PUSH_IMAGES":
                    BuildEnvironmentVariable(value="1"),
                },
                build_image=LinuxBuildImage.STANDARD_2_0,
                privileged=True,
            ),
            cache=Cache.local(LocalCacheMode.DOCKER_LAYER),
        )

        repo.grant_pull_push(project)

        return project
Ejemplo n.º 9
0
    def __init__(self, scope: Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

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

        pipeline = CdkPipeline(
            self,
            "Pipeline",
            pipeline_name="WebinarPipeline",
            cloud_assembly_artifact=cloud_assembly_artifact,
            source_action=codepipeline_actions.GitHubSourceAction(
                action_name="GitHub",
                output=source_artifact,
                oauth_token=SecretValue.secrets_manager("github-token"),
                trigger=codepipeline_actions.GitHubTrigger.POLL,
                # Replace these with your actual GitHub project info
                owner="rcouso",
                repo="cdkpipeline",
                branch="main"),
            synth_action=SimpleSynthAction(
                source_artifact=source_artifact,
                cloud_assembly_artifact=cloud_assembly_artifact,
                # Use this if you need a build step (if you're not using ts-node
                # or if you have TypeScript Lambdas that need to be compiled).
                install_command=
                "npm install -g aws-cdk && pip install -r requirements.txt",
                build_command="pytest pipelines_webinar/unittests",
                synth_command="cdk synth"))
        # DEV STAGE
        dev_app = WebServiceStage(self,
                                  'Dev',
                                  env={
                                      'account': '722610601746',
                                      'region': 'eu-west-1'
                                  })
        dev_stage = pipeline.add_application_stage(dev_app)
        dev_stage.add_actions(
            ShellScriptAction(
                action_name="Integ",
                run_order=dev_stage.next_sequential_run_order(),
                additional_artifacts=[source_artifact],
                environment=BuildEnvironment(
                    environment_variables={
                        'CODECOV_TOKEN':
                        aws_codebuild.BuildEnvironmentVariable(
                            value='9e4d7998-7a8e-45a2-81fe-8a9c761cb03a')
                    }),
                commands=[
                    "pip install -r requirements.txt",
                    "pytest pipelines_webinar/integtests",
                    "echo 'TOKEN='$CODECOV_TOKEN"
                    # coverage
                    # "pip install coverage",
                    # "coverage run -a --source pipelines_webinar/unittests",
                    # "coverage run -a --source pipelines_webinar/integtests",
                    # "bash pipelines_webinar/coverage.sh"
                ],
                use_outputs={
                    "SERVICE_URL": pipeline.stack_output(dev_app.url_output)
                }))
        dev_stage.add_manual_approval_action(action_name='PromoteToPro')
        # PRO STAGE
        pipeline.add_application_stage(
            WebServiceStage(self,
                            'Prod',
                            env={
                                'account': '807034265755',
                                'region': 'eu-west-1'
                            }))