aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.38k stars 3.79k forks source link

(pipelines): allow builds to happen after UpdatePipeline #29863

Open darylteo opened 3 months ago

darylteo commented 3 months ago

Describe the feature

Ability to specify an additional build step after synth and after self-update and use this as a source for later Stages.

Use Case

Pretty frustrating that I can't do this - I am creating a Stack, which I put into a Stage. This works, except that

The intuitive solution if you're new to CDK (like I am) is to add a Wave to the Pipeline, before adding the Stage.

But the resulting Pipeline adds the "Assets" stage in between the UpdatePipeline stage and the Wave and there's no way to specify the Steps in the Wave as Outputs for the stack deployment Stage.

Proposed Solution

Allow us to specify a CodeBuildStep as a source for later Stacks I guess? 🤷‍♂️

Other Information

I've tried the following based on other topics along the same lines


    const buildArtifact = new Artifact('custom_output')
    const codeBuildAction = new CodeBuildAction({
      actionName: 'Build',
      project,
      input: sourceArtifact,
      outputs: [
        buildArtifact,
      ],
      runOrder: 2,
    })

    // pipeline.pipeline.stages[2] is the self-update stage. setting runOrder to 2 makes this run after the self-update.
    pipeline.pipeline.stages[2].addAction(codeBuildAction)

    for (const action of pipeline.pipeline.stages[3].actions) {
      // neither of this seems to work
      (action as unknown as any).props.inputs = [
        buildArtifact,
      ];

      (action as unknown as any).providedActionProperties.inputs = [
        buildArtifact,
      ]
    }

Acknowledgements

CDK version used

2.133

Environment details (OS name and version, etc.)

os x

pahud commented 2 months ago

Actually in the synth stage you can define your custom commands before the cdk synth like



    const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
      synth: new pipelines.ShellStep('Synth', {
        input,
        }),
        commands: [
          // do what ever you want here
          'npm run build',
          'npx cdk synth',
        ],
      }),
    });

   Is this something you expect?
darylteo commented 2 months ago

That is in fact what I'm doing now but from my understanding this has 2 drawbacks:

The other thing which is kind of annoying is the requirement of the Assets stage - I've already got all the artifacts I need in the same place as the output of the build... why does it need 7 CodeBuildActions to copy the files i already have into separate buckets? 😅 is there any way this could be avoided as it seems to increase build time significantly and also sporadically fails due to too many concurrent codebuild actions.

Perhaps I've been looking at this philosophically from the wrong angle.