Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pipelines] Running additional actions in the default "Build" stage #9021

Closed
2 tasks done
asterikx opened this issue Jul 11, 2020 · 4 comments · Fixed by #10148
Closed
2 tasks done

[Pipelines] Running additional actions in the default "Build" stage #9021

asterikx opened this issue Jul 11, 2020 · 4 comments · Fixed by #10148
Assignees
Labels
@aws-cdk/pipelines CDK Pipelines library effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2

Comments

@asterikx
Copy link
Contributor

asterikx commented Jul 11, 2020

Possibility to run additional actions during the default Build phase. Apart from the CDK build, other builds such as website builds might be required. A website might be built and deployed along with the CDK app within the same pipeline.

Use Case

Running additional build actions in the default Build phase such as website builds.

Proposed Solution

Making the build stage a public property of pipelines.CdkPipeline so that custom actions can be added.

Let the user specify an array of buildActions instead of a single synthAction, e.g.

const synthAction = pipelines.SimpleSynthAction.standardYarnSynth({
  sourceArtifact,
  cloudAssemblyArtifact,
});

const pipeline = new pipelines.CdkPipeline(this, 'Pipeline', {
  pipelineName: 'MyAppPipeline',
  cloudAssemblyArtifact,
  sourceAction,
  buildActions: [synthAction, /* more actions */],
});

I think this covers all possible needs. Also, it is consistent with codepipeline.StageProps.actions:

/**
* The list of Actions to create this Stage with.
* You can always add more Actions later by calling {@link IStage#addAction}.
*/
readonly actions?: IAction[];

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@asterikx asterikx added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2020
@asterikx asterikx changed the title [Pipelines] Running additional actions in the Build stage [Pipelines] Running additional actions in the default "Build" stage Jul 11, 2020
@SomayaB SomayaB added the @aws-cdk/pipelines CDK Pipelines library label Jul 13, 2020
@nija-at nija-at assigned ericzbeard and unassigned NetaNir and nija-at Jul 14, 2020
@ericzbeard ericzbeard added effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 15, 2020
@ericzbeard ericzbeard assigned rix0rrr and unassigned ericzbeard Jul 15, 2020
@asterikx
Copy link
Contributor Author

In my case, I have to build several subprojects - a frontend, lambdas (Golang), lambdas (TS), and email templates. The build outputs are referenced from the CDK code, i.e. using lambda.Code.fromAsset or s3deploy.BucketDeplyoment.

This means that the synth action (a CodeBuild project) needs to accept the build outputs of the subprojects builds (parallel CodeBuild projects) and copy them to the location where cdk synth would expect them. I'm not sure to what degree this process can be automated by the CDK. Still, I think that it makes sense to let users implement this themselves.

@tneely
Copy link
Contributor

tneely commented Aug 3, 2020

I was able to work around this by having my infrastructure, frontend, and lambda code all in the same package. My build command also builds the frontend + lambdas and then packages them into secondary artifacts that I can upload to S3 and pass along to the application stage.

It's not too pretty, and I still don't have a good way of passing the frontend/lambda assets to the application stage without relying on hardcoded bucket names, but it does work for the most part. The one catch I've found so far is that it doesn't trigger changes to s3deploy.BucketDeplyoment in my application stage, since CFn can't tell the asset bucket was updated. It may be possible to work around this by turning the bucket keys into unique timestamps.

code

@asterikx
Copy link
Contributor Author

asterikx commented Aug 3, 2020

@tneely I do not completely follow.

Instead of using additional outputs and introducing a custom UploadAssets stage to deploy those outputs to S3, I would just add two s3deploy.BucketDeployments to the stack that is being deployed (this one).
CDK Pipeline already has a PublishAssets stage and takes care of uploading assets during pipeline execution.

Also, your install/build commands build process your projects in sequential order.

My intention was to speed the build phase by executing separate CodeBuild projects in parallel. For pure TypeScript projects, a single CodeBuild project might work well with Lerna/Yarn workspaces, but when you use different languages or different setup it gets complicated.
I think dedicated CodeBuild projects have other advantages too, e.g. you can clearly see which project failed, can use customized CodeBuild environments for each build, ...

@rix0rrr rix0rrr added the p2 label Aug 4, 2020
@rix0rrr rix0rrr added this to the [CDK Pipelines] Soon milestone Aug 12, 2020
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort and removed effort/medium Medium work item – several days of effort labels Aug 12, 2020
@asterikx
Copy link
Contributor Author

I have not thought through this completely.

My goal was/is to separate and parallelize builds from the synth action using separate CodeBuild projects. For the synth action to work, we must provide it with the output artifacts from the build projects and copy/move them to the location where cdk synth is expecting them.

This issue will allow the user to implement the required build logic herself, but I wonder if the CDK could/should handle this as well ... in any case, that might better be tackled in a different issue. What do you think @rix0rrr?

rix0rrr added a commit that referenced this issue Sep 3, 2020
For people with specific requirements:

* Allow supplying an existing (preconfigured) CodePipeline object,
  via the `codePipeline` argument. This pipeline may already have
  Source and Build stages, in which case `sourceAction` and
  `synthAction` are no longer required.
* Allow access to the underlying CodePipeline object via the
  `.codePipeline` property, and allow modifying it via
  `pipeline.stage("Source").addAction(...)`.

Fixes #9021.
@mergify mergify bot closed this as completed in #10148 Sep 3, 2020
mergify bot pushed a commit that referenced this issue Sep 3, 2020
For people with specific requirements:

* Allow supplying an existing (preconfigured) CodePipeline object,
  via the `codePipeline` argument. This pipeline may already have
  Source and Build stages, in which case `sourceAction` and
  `synthAction` are no longer required.
* Allow access to the underlying CodePipeline object via the
  `.codePipeline` property, and allow modifying it via
  `pipeline.stage("Source").addAction(...)`.

Fixes #9021.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants