Pipeline¶
CDK Pipeline constructs for CI/CD workflows.
pipeline
¶
Modules¶
base
¶
Classes¶
BasePipelineStack
¶
BasePipelineStack(
scope: Construct,
id: str,
env_base: EnvBase,
config: BaseProjectConfig[GLOBAL_CONFIG, STAGE_CONFIG],
**kwargs
)
Bases: EnvBaseStack, Generic[STAGE_CONFIG, GLOBAL_CONFIG]
Defines the CI/CD Pipeline for the an Environment.
This class is meant to be subclassed to define the pipeline for a specific project.
You are required to implement the initialize_pipeline method which should return
a pipelines.CodePipeline object. You can then add stages to the pipeline by defining
methods that are decorated with the @pipeline_stage decorator.
Example:
```python
class MyPipelineStack(BasePipelineStack):
@pipeline_stage(order=1, pre_steps=[...], post_steps=[...])
def build_stage(self) -> cdk.Stage:
# Define the steps for the build stage
build_steps = [
pipelines.CodeBuildStep(
"Build",
input=self.get_pipeline_source(self.pipeline_config.source),
commands=[
"echo 'Building the project'",
"npm install",
"npm run build",
],
role_policy_statements=[
self.get_policy_with_secrets(self.pipeline_config.source.oauth_secret_name),
],
),
]
# Create the build stage
build_stage = pipelines.Stage(
self,
"BuildStage",
stage_name="Build",
actions=build_steps,
)
return build_stage
The following steps are available for pipelines inheriting from this class:
promotion_stage: A stage that is added after all other stages. This stage
is used to promote the deployment to another environment.
notifications: A notification topic that is used to send notifications. You can
enable notifications for pipeline failures and successes. This
can be configured in the `pipeline_config.notifications` attribute.
Source code in src/aibs_informatics_cdk_lib/cicd/pipeline/base.py
build_pipeline
¶Builds the pipeline. This method should be called after the pipeline is initialized.
This should not be overridden by subclasses unless you know what you are doing.
This method will
- Initialize the pipeline
- Add stages to the pipeline
- Add a promotion stage
- Build the pipeline
- Setup notifications
Source code in src/aibs_informatics_cdk_lib/cicd/pipeline/base.py
add_promotion_stage
¶Adds a promotion stage to a CodePipeline
Promotion stages are used to promote the deployment to another environment. These promotions are done through github pull requests. This is a major foundation for the deployment process.
The environment promotion definitions are defined in the global_config.stage_promotions.
This is a mapping of source environment types to target environment types.
The branch that is used for the promotion is defined in pipeline_config.source.branch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline
|
CodePipeline
|
Code Pipeline |
required |
Source code in src/aibs_informatics_cdk_lib/cicd/pipeline/base.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
get_pipeline_source
¶get_pipeline_source(
source_config: CodePipelineSourceConfig,
) -> CodePipelineSource
Constructs a Github Repo source from a config
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_config
|
CodePipelineSourceConfig
|
config |
required |
Returns:
| Type | Description |
|---|---|
CodePipelineSource
|
pipelines.CodePipelineSource: |
Source code in src/aibs_informatics_cdk_lib/cicd/pipeline/base.py
Functions¶
pipeline_stage
¶
pipeline_stage(
order: int,
name: str,
pre_steps: list[Step] | None = None,
post_steps: list[Step] | None = None,
)
Method decorator for defining a pipeline stage in a BasePipelineStack subclass.
you can decorate two types of methods: 1. A method that returns a cdk.Stage 2. A method that returns a tuple of pre_steps, cdk.Stage, post_steps where pre_steps and post_steps are lists of pipelines.Step objects.
Example:
class PipelineStack(BasePipelineStack):
...
@pipeline_stage(order=0, name="Source", pre_steps=[...])
def source_stage(self) -> cdk.Stage:
return SourceStage(self, self.get_construct_id("source-stage"))
@pipeline_stage(order=1, name="Build")
def build_stage(self) -> cdk.Stage:
return BuildStage(self, self.get_construct_id("build-stage"))
@pipeline_stage(order=2, name="Deploy")
def deploy_stage(self) -> Tuple[List[pipelines.Step], cdk.Stage, List[pipelines.Step]]:
pre_steps = [...]
post_steps = [...]
stage = DeployStage(self, self.get_construct_id("deploy-stage"))
return pre_steps, stage, post_steps
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
order
|
int
|
Order of the stage. Lower numbers are executed first. E.g. 1, 2, 3, ... You can repeat numbers, however, the order will be arbitrary. |
required |
name
|
str
|
Name of the stage |
required |
pre_steps
|
Optional[List[Step]]
|
Optional pre steps to add before the stage. Defaults to None. |
None
|
post_steps
|
Optional[List[Step]]
|
Optional post steps to add after the stage. Defaults to None. |
None
|