-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(core): BundlingDockerImage.cp() needs to be explained more in the README #11914
(core): BundlingDockerImage.cp() needs to be explained more in the README #11914
Comments
I think that what you are looking for is
aws-cdk/packages/@aws-cdk/core/lib/bundling.ts Lines 178 to 181 in cbe7a10
|
So what is the appropriate use of the default bundling behavior? I would assume the snippet in step 2 above would work without needing to implement |
The default behavior is to run a command in a container where the source path is mounted at
|
Gotcha, so anything put in |
anything put in
yes, you can do whatever you want as long as you put content in |
I also ran into a situation where I just wanted to use some content from the built image as the asset output. I think our APIs can probably offer a better experience for this.
@jogold what do you think? |
You can already do this: const assetPath = '/path/to/my/asset';
const image = cdk.BundlingDockerImage.fromAsset('/path/to/docker');
image.cp('/path/in/the/image', assetPath);
new lambda.Function(this, 'Fn', {
code: lambda.Code.fromAsset(assetPath),
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
}); Is it this that you want to improve?
|
My issue was that the Dockerfile put everything needed in What I would like to see improved is either better documentation around the behavior of the |
const image = BundlingDockerImage.fromAsset('/path/to/docker');
new lambda.Function(this, 'Fn', {
code: lambda.Code.fromAsset(image.fetch('/path/in/the/image')),
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
}); I think the API for const image = Docker.build('/path/to/docker');
const tmpdir = image.cp('/path/in/the/image');
// alternatively, users can specify the destination for "cp"
image.cp('/path/in/the/image', tmpdir); And then, we can also add something like: new lambda.Function(this, 'Fn', {
code: lambda.Code.fromDockerBuildAsset('/path/in/the/image'),
runtime: lambda.Runtime.NODEJS_12_X,
handler: 'index.handler',
}); |
|
Haha... so perhaps |
yes |
shouldn't this be /**
* Loads the function code from an asset created by a Docker build.
*
* The asset is expected to be located at `/asset` in the image.
*
* @param path The path to the directory containing the Docker file
* @param options Docker build options
*/
public static fromDockerBuildAsset(path: string, options: cdk.DockerBuildOptions = {}): AssetCode {
const assetPath = cdk.DockerImage.fromBuild(path, options).cp('/asset');
return new AssetCode(assetPath);
} |
Use the result of a Docker build as code. The runtime code is expected to be located at `/asset` in the image. Also deprecate `BundlingDockerImage` in favor of `DockerImage`. Closes #11914 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Use the result of a Docker build as code. The runtime code is expected to be located at `/asset` in the image. Also deprecate `BundlingDockerImage` in favor of `DockerImage`. Closes aws#11914 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
When using
lambda.Code.fromAsset
andcdk.BundlingDockerImage.fromAsset
together, synth fails to find anything in\asset-output
Reproduction Steps
/asset-output
directorytsc && cdk synth -o cdk.out
What did you expect to happen?
Docker should find the compiled assets in
/asset-output
What actually happened?
Error: Bundling did not produce any output. Check that content is written to /asset-output.
Environment
Other
If I use an implementation of ILocalBundling that is mostly copied from asset-staging.ts but calls both
run
andcp
the synth works but I don't believe that should be necessary:This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: