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)
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
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)
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
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)
class ApiCiConfig(Construct): backend_spec: BuildSpec = BuildSpec.from_source_filename( "./infra/stacks/ci/buildspecs/app.yaml") frontend_spec: BuildSpec = BuildSpec.from_source_filename( "./infra/stacks/ci/buildspecs/frontend.yaml") input_artifact: Artifact = None def __init__( self, scope: Construct, id: str, envs: EnvSettings, build_stage: IStage, repos: List[Repository], input_artifact: Artifact, ): super().__init__(scope, id) self.input_artifact = input_artifact backend_build_project = self.create_backend_build_project( envs, repos["app"]) front_build_project = self.create_front_build_project(envs, repos) build_stage.add_action( self.create_build_action("backend", backend_build_project, order=1)) build_stage.add_action( self.create_build_action("frontend", front_build_project, order=2)) 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 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 create_build_action(self, name: str, project: PipelineProject, order: int): return CodeBuildAction(action_name=f"build-{name}", project=project, input=self.input_artifact, run_order=order) @staticmethod def prepare_api_changes(envs: EnvSettings, cdk_artifact: Artifact): return CloudFormationCreateReplaceChangeSetAction( action_name="prepare-app-changes", stack_name=f"{envs.project_name}-api", change_set_name="APIStagedChangeSet", admin_permissions=True, template_path=cdk_artifact.at_path( "infra/cdk.out/schema-cms-api.template.json"), run_order=2, ) @staticmethod def execute_api_changes(envs: EnvSettings): return CloudFormationExecuteChangeSetAction( action_name="execute-app-changes", stack_name=f"{envs.project_name}-api", change_set_name="APIStagedChangeSet", run_order=4, )