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

feat(core): BundlingDockerImage now supports run() and cp() utilities #9728

Merged
merged 10 commits into from
Oct 11, 2020

Conversation

misterjoshua
Copy link
Contributor

@misterjoshua misterjoshua commented Aug 14, 2020

This PR introduces run() and cp() utility methods to BundlingDockerImage. After building their own Docker images, users can more easily run the image or copy files out of the image to create their own assets without using the bundling mechanism.

Possibly closes #9329


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@misterjoshua misterjoshua marked this pull request as ready for review August 14, 2020 23:45
@misterjoshua misterjoshua marked this pull request as draft August 15, 2020 01:50
@misterjoshua misterjoshua changed the title feat(lambda): add lambda.Code.fromDocker() feat(lambda): add lambda.Code.fromDockerBuild() Aug 15, 2020
@misterjoshua misterjoshua marked this pull request as ready for review August 16, 2020 17:08
@misterjoshua misterjoshua changed the title feat(lambda): add lambda.Code.fromDockerBuild() chore(core): add copyFromImagePath to the bundler options Aug 18, 2020
@misterjoshua
Copy link
Contributor Author

New changes to reflect the following:

  • Changed the bundler option name to copyFromImagePath. The former is a better option name than imageStaticAssetPath because it better conveys what the bundler will do.
  • Removed lambda.Code.fromDockerBuild as lambda.Code.fromAsset supports the new bundler option out of the box.

@nija-at nija-at assigned eladb and unassigned nija-at Aug 21, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR is adding a new feature, mark the title as a 'feat' instead of 'chore'

@mergify mergify bot dismissed nija-at’s stale review August 21, 2020 17:10

Pull request has been modified.

@misterjoshua misterjoshua changed the title chore(core): add copyFromImagePath to the bundler options feat(core): add copyFromImagePath to the bundler options Aug 21, 2020
@eladb
Copy link
Contributor

eladb commented Aug 26, 2020

@jogold could spare some cycles to work with @misterjoshua on this?

@misterjoshua something with the mental model is not intuitive to me at first glance. I am not sure I fully understand the use case and then the terminology of copyFromImagePath doesn't intuitively represent neither intent (the user's final goal) nor mechanism (what's mechanically happening).

@misterjoshua
Copy link
Contributor Author

FYI, I plan to fix the conflict and resume work on this PR as soon as I can, but I'm swamped this week.

@eladb
Copy link
Contributor

eladb commented Sep 7, 2020

@jogold can you take a look?

packages/@aws-cdk/aws-s3-assets/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-s3-assets/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-s3-assets/lib/asset.ts Outdated Show resolved Hide resolved
@eladb
Copy link
Contributor

eladb commented Sep 22, 2020

What's the status here?

@misterjoshua
Copy link
Contributor Author

misterjoshua commented Sep 22, 2020

What's the status here?

@eladb I believe @jogold requested some feedback on whether we should consider implementing a different asset type. Overall, I'm not sure whether supporting my use case is out of scope for CDK bundling or the project as a whole, considering that I can handle this in a stage that happens before CDK runs.

@eladb
Copy link
Contributor

eladb commented Sep 23, 2020

What's the status here?

@eladb I believe @jogold requested some feedback on whether we should consider implementing a different asset type. Overall, I'm not sure whether supporting my use case is out of scope for CDK bundling or the project as a whole, considering that I can handle this in a stage that happens before CDK runs.

You can also just write some code in your CDK app that prepares the asset directory (in whatever way) and then defines an asset that refers to this directory (no need to use bundling in this case).

What's the benefit of using the asset bundling mechanism? Is it just to run docker? Can we extract some of that logic into e.g. utility functions maybe?

@misterjoshua
Copy link
Contributor Author

misterjoshua commented Sep 23, 2020

What's the status here?

@eladb I believe @jogold requested some feedback on whether we should consider implementing a different asset type. Overall, I'm not sure whether supporting my use case is out of scope for CDK bundling or the project as a whole, considering that I can handle this in a stage that happens before CDK runs.

You can also just write some code in your CDK app that prepares the asset directory (in whatever way) and then defines an asset that refers to this directory (no need to use bundling in this case).

What's the benefit of using the asset bundling mechanism? Is it just to run docker? Can we extract some of that logic into e.g. utility functions maybe?

@eladb Yes, I'd say the benefit lies in the ease of controlling docker to prepare such a directory. BundlingDockerImage is particularly convenient for building the image. And yes, I suspect that we can extract the docker logic into some utility functions to make it easier.

Does an API like this make sense?

// Build a Docker image
const image = BundlingDockerImage.fromAsset(contextPath, {
  // Added in this PR, lets you override the Dockerfile path - very useful for me
  file: dockerfilePath,
});

// My use case - copy files out of the image from `imagePath` to `localPath` on this computer via `docker cp`
image.copyOut(imagePath, localPath);
// Or alternatively, run the docker image with options.
image.run(dockerRunOptions);

Edit: I've pushed up a POC. It's a much smaller change. :) I'll see about adding an integration test in S3 assets. I ran out of time today.

eladb
eladb previously requested changes Sep 24, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this direction. See some comments

@@ -110,6 +110,7 @@ export class BundlingDockerImage {

const dockerArgs: string[] = [
'build', '-q',
...(options.file ? ['-f', options.file] : []),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vaguely recall this is already supported. Did you rebase?

Copy link
Contributor Author

@misterjoshua misterjoshua Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladb I wiped out my previous branch and started fresh from the master branch today - the old commits were not practical to revert. I used the force to push it over the branch in this PR.

I didn't see pre-existing support for this in master. However, I've got practically the same code in PR #9582, which I believe you've previously reviewed. Maybe it was seen there? Not sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's currently supported in cdk-assets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API of the Docker class in cdk-assets looks pretty handy to use. But, both core and cdk-assets seem to have minimal dependencies. Any ideas what I should do here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing at this stage, I was just mentioning from where @eladb might have thought that this was already supported.

Not for this PR but at some point it might be interesting to correctly define the "roles" of core vs cdk-assets. I think that this was already discussed in another issue about where zipping should occur.

packages/@aws-cdk/core/lib/bundling.ts Outdated Show resolved Hide resolved
@@ -110,6 +110,7 @@ export class BundlingDockerImage {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jogold does it make sense to rename this to DockerImage? What's "bundling" about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the docker image used when bundling an asset/accepted in the bundling options... but I agree that there's nothing specific to bundling in its implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this for a future change

@mergify mergify bot dismissed eladb’s stale review September 24, 2020 06:20

Pull request has been modified.

@misterjoshua misterjoshua changed the title feat(core): add copyFromImagePath to the bundler options feat(core): add run and copyOut methods to BundlingDockerImage Sep 24, 2020
@misterjoshua
Copy link
Contributor Author

@eladb I've pushed up changes from your review. It's time to sleep, so I'll check in later. :)

@eladb eladb changed the title feat(core): add run and copyOut methods to BundlingDockerImage feat(core): BundlingDockerImage now supports run and cp methods Sep 24, 2020
@eladb eladb changed the title feat(core): BundlingDockerImage now supports run and cp methods feat(core): BundlingDockerImage now supports run() and cp() utilities Sep 24, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor

packages/@aws-cdk/core/lib/bundling.ts Outdated Show resolved Hide resolved
@misterjoshua
Copy link
Contributor Author

misterjoshua commented Sep 24, 2020

@eladb I've made your cp() change and updated from the master branch. Is there anything else you'd like to see added or changed?

eladb
eladb previously approved these changes Oct 4, 2020
@misterjoshua
Copy link
Contributor Author

I see some merge conflicts have arisen. I'll see what's required and push up a commit.

@mergify mergify bot dismissed eladb’s stale review October 6, 2020 16:09

Pull request has been modified.

@misterjoshua
Copy link
Contributor Author

@eladb I resolved a conflict due to the new nodeunitShim, so I think this may need another review. Though the fix was basically a parenthesis.

@eladb eladb added the pr-linter/exempt-readme The PR linter will not require README changes label Oct 6, 2020
@mergify
Copy link
Contributor

mergify bot commented Oct 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: c35b0f7
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Oct 11, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aws-lambda] Lambda zip from DockerFile
5 participants