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

CodeBuild buildspec should support YAML FileAsset and project file name #1138

Closed
costleya opened this issue Nov 10, 2018 · 15 comments · Fixed by #24289
Closed

CodeBuild buildspec should support YAML FileAsset and project file name #1138

costleya opened this issue Nov 10, 2018 · 15 comments · Fixed by #24289
Labels
@aws-cdk/aws-codebuild Related to AWS CodeBuild effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p1

Comments

@costleya
Copy link
Contributor

costleya commented Nov 10, 2018

A CodeBuild project currently calls JSON.stringify on the contents of a FileAsset to make CodeBuild recognize the buildspec as inline. However, CodeBuild uses YAML files exclusively in the documentation. Attempting to use JSON also does not work.

@costleya costleya added @aws-cdk/assets Related to the @aws-cdk/assets package feature-request A feature should be added or improved. labels Nov 10, 2018
@costleya costleya changed the title CodeBuild buildspec can be a YAML FileAsset CodeBuild buildspec is a YAML FileAsset Nov 17, 2018
@eladb
Copy link
Contributor

eladb commented Dec 9, 2018

I think the issue not that you can't use JSON, because YAML is a superset of JSON, but because codebuild.Project currently assumes that you are providing the buildspec as an inline object (the typing is any, but technically it should be a strongly typed schema for the buildspec, see #1135).

I'll rename this issue to add support for assets, as it seems like a useful feature. We will probably end up with something like something like lambda.Code:

buildspec: codebuild.BuildSpec.asset('path/to/asset')
// or
buildspec: codebuild.BuildSpec.inline({
  <strong-typed-schema>
})
// or (this is also supported today by CFN):
buildspec: codebuild.BuildSpec.projectFile('my-buildspec.yaml')

@eladb eladb changed the title CodeBuild buildspec is a YAML FileAsset CodeBuild buildspec should support YAML FileAsset and project file name Dec 9, 2018
@jesterhazy
Copy link
Contributor

this would be a good feature

@eladb eladb self-assigned this Aug 12, 2019
@eladb
Copy link
Contributor

eladb commented Oct 2, 2019

Please reopen if this is still desirable

@eladb eladb closed this as completed Oct 2, 2019
@jostick
Copy link

jostick commented Apr 1, 2020

I still think this is useful and couldn't find any solution to easily use an asset as CodeBuild buildspec. Did I overlook something? Or is it just not possible? How am I supposed to put buildspecs in a CDK library?

@skinny85
Copy link
Contributor

skinny85 commented Apr 1, 2020

@jostick you're right - we had that functionality before, but we removed it.

Can you describe your use case for this? I'll be re-opening the issue either way.

Thanks,
Adam

@skinny85 skinny85 reopened this Apr 1, 2020
@jostick
Copy link

jostick commented Apr 2, 2020

We are using CDK to provide resources and build steps common in all our CodePipeline projects, e.g. cloning code from a version control system (no CodeCommit unfortunately). Cloning the repository is implemented using CodeBuild. It would be nice if it would be possible to include the buildspec for this step as an asset in the library. There are other shared build steps (like self-updating the pipeline) that would also be easier if the buildspec could be provide das FileAsset.

Our current workaround is parse the buildspec.yml and then inline it with BuildSpec.fromObject(YAML.parse(fs.readFileSync('buildspec.yaml', 'utf8'))). This currently works fine but is not nice and unnecessarily increases the template size (which is limited in Cloudformation).

@skinny85 skinny85 added effort/medium Medium work item – several days of effort @aws-cdk/aws-codebuild Related to AWS CodeBuild and removed @aws-cdk/assets Related to the @aws-cdk/assets package labels Apr 2, 2020
@skinny85 skinny85 assigned skinny85 and unassigned eladb Apr 2, 2020
@skinny85 skinny85 added the p1 label Apr 2, 2020
@skinny85
Copy link
Contributor

skinny85 commented Apr 2, 2020

That's helpful, thanks @jostick !

@soverbosch
Copy link

This is what I need, currently trying to work with cdk and one of the problems I have now is using inline buildspecs.

@ericzbeard ericzbeard added the feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. label Apr 7, 2021
@prasnitt
Copy link

prasnitt commented Aug 9, 2021

True, I also need this feature.

@whereisaaron
Copy link

whereisaaron commented Aug 5, 2022

I have a buildspec YAML file that I just what to inline into the CDK .NET generated stacks at synth time. What I am looking for but not finding in BuildSpec is BuildSpec.FromPath(string) or BuildSpec.FromFile(File) or BuildSpec.FromStream(Stream) that will accept YAML text and inline it as YAML in the stack.

The closest I found is BuildSpec.FromObjectToYaml(IDictionary<String, Object>) which requires first converting your YAML file asset to a large collection of nested dictionaries, only to then convert it straight back to YAML text. That's even less workable than any and also a lot harder that not using CDK 😀

Is there a supporting .NET library people use that can parse/deserialize YAML files into this IDictionary<String, Object> structure? I looked but nothing sprung out that didn't involve a lot of messing around to get it into that form 😭

(We need to inline the buildspec because CodeBuild doesn't support the buildspec being in a secondary git source, so BuildSpec.FromSourceFilename(String) can't help us here. In our idiom the git webhook triggers the primary application code source, but all of the build support files come from a secondary git source.)

@markreyndev in #17178 had a similar request to have a better wait to create an inline BuildSpec than having to transform YAML to IDictionary<String, Object> but the discussion only address specifying a file in Git source, with doesn't allow my use case for loading a file from CDK project to inline in stack.

@skinny85
Copy link
Contributor

skinny85 commented Aug 6, 2022

@whereisaaron I believe what you want is to read the file with a YAML parser, get it in the form of a bunch of nested Dictionaries, and then use BuildSpec.FromObject().

@whereisaaron
Copy link

Thanks @skinny85, that would be a workaround, but I don't think that - ideally - CDK users should have to do all that? The canonical type of a CodeBuild buildspec is YAML. CDK should support YAML for both in-source file and inline.

The different language versions of CDK have different, loosely typed, internal representations whether any or IDictionary<String, Object> or Map.of(). None are strongly typed YAML. For .Net CDK users my opinion is that the interface should be either/both an actual YAML string/stream or a proper .Net YAML type such as defined by YamlDotNet. I've seen comments that strongly typed (buildspec-specific) YAML is the end goal for CDK but I am not sure if project is willing to include something like YamlDotNet to achieve that?

And since I haven't rocked up with a pull request, I'll do the workaround 😄

@skinny85
Copy link
Contributor

skinny85 commented Aug 8, 2022

For .Net CDK users my opinion is that the interface should be either/both an actual YAML string/stream or a proper .Net YAML type such as defined by YamlDotNet. I've seen comments that strongly typed (buildspec-specific) YAML is the end goal for CDK but I am not sure if project is willing to include something like YamlDotNet to achieve that?

Implementing something like that would require deep changes in JSII, the technology CDK uses for multi-language support - it's definitely not just a simple PR. So, I would suggest going with the workaround for now 😉.

@madeline-k
Copy link
Contributor

See #17178 for pipelines use-case.

MrArnoldPalmer added a commit that referenced this issue Feb 23, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local
files as a project's buildspec. Uploads the file to s3 and references
the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is
not can be defined at synth time, but it exsists somewhere other  than
the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional
parameter to `toBuildSpec` method.

fixes: #1138
MrArnoldPalmer added a commit that referenced this issue Feb 23, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local
files as a project's buildspec. Uploads the file to s3 and references
the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is
not can be defined at synth time, but it exsists somewhere other  than
the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional
parameter to `toBuildSpec` method.

fixes: #1138
MrArnoldPalmer added a commit that referenced this issue Feb 23, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local
files as a project's buildspec. Uploads the file to s3 and references
the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is
not can be defined at synth time, but it exsists somewhere other  than
the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional
parameter to `toBuildSpec` method.

fixes: #1138
MrArnoldPalmer added a commit that referenced this issue Feb 23, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local
files as a project's buildspec. Uploads the file to s3 and references
the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is
not can be defined at synth time, but it exsists somewhere other  than
the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional
parameter to `toBuildSpec` method.

fixes: #1138
@mergify mergify bot closed this as completed in #24289 Feb 23, 2023
mergify bot pushed a commit that referenced this issue Feb 23, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local files as a project's buildspec. Uploads the file to s3 and references the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is not can be defined at synth time, but it exsists somewhere other  than the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional parameter to `toBuildSpec` method.

fixes: #1138

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Naumel pushed a commit that referenced this issue Feb 24, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local files as a project's buildspec. Uploads the file to s3 and references the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is not can be defined at synth time, but it exsists somewhere other  than the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional parameter to `toBuildSpec` method.

fixes: #1138

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
beck3905 pushed a commit to beck3905/aws-cdk that referenced this issue Feb 28, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local files as a project's buildspec. Uploads the file to s3 and references the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is not can be defined at synth time, but it exsists somewhere other  than the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional parameter to `toBuildSpec` method.

fixes: aws#1138

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
homakk pushed a commit to homakk/aws-cdk that referenced this issue Mar 13, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local files as a project's buildspec. Uploads the file to s3 and references the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is not can be defined at synth time, but it exsists somewhere other  than the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional parameter to `toBuildSpec` method.

fixes: aws#1138

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
homakk pushed a commit to homakk/aws-cdk that referenced this issue Mar 28, 2023
Adds `fromAsset` to the `BuildSpec` class to allow referencing local files as a project's buildspec. Uploads the file to s3 and references the object arn in the `buildSpec` property of `Codebuild.Project`.

`isImmediate` is true for AssetBuildSpec because it's actual meaning is not can be defined at synth time, but it exsists somewhere other  than the project's source code, which in this case is true.

Requires referencing of the project so adds `scope` as an optional parameter to `toBuildSpec` method.

fixes: aws#1138

----

*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/aws-codebuild Related to AWS CodeBuild effort/medium Medium work item – several days of effort feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants