(core): BundlingDockerImage.cp() needs to be explained more in the README
See original GitHub issueWhen using lambda.Code.fromAsset
and cdk.BundlingDockerImage.fromAsset
together, synth fails to find anything in \asset-output
Reproduction Steps
- Create a Dockerfile that compiles and copies files to an
/asset-output
directory
FROM python:3.7-slim
COPY . /asset-input
COPY . /asset-output
WORKDIR /asset-input
RUN apt-get update && apt-get -y install curl make automake gcc g++ subversion python3-dev
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -
ENV PATH "/root/.poetry/bin:/opt/venv/bin:${PATH}"
RUN poetry export -f requirements.txt -o requirements.txt
RUN pip3 install -r requirements.txt -t /asset-output
- Use the following snippet when creating the lambda using cdk:
code: lambda.Code.fromAsset(PROJECT_DIR, {
bundling: {
image: cdk.BundlingDockerImage.fromAsset(PROJECT_DIR)
}
}),
- Run
tsc && 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
- CDK CLI Version : 1.75.0
- Framework Version: 1.75.0
- Node.js Version: v15.3.0
- OS : Mac Catalina 10.15.7
- Language (Version): TypeScript 4.1.2
Other
If I use an implementation of ILocalBundling that is mostly copied from asset-staging.ts but calls both run
and cp
the synth works but I don’t believe that should be necessary:
class LocalBundling implements ILocalBundling {
tryBundle(outputDir: string, options: BundlingOptions): boolean {
let user: string;
if (options.user) {
user = options.user;
} else {
// Default to current user
const userInfo = os.userInfo();
user =
userInfo.uid !== -1 // uid is -1 on Windows
? `${userInfo.uid}:${userInfo.gid}`
: "1000:1000";
}
// Always mount input and output dir
const volumes = [
{
hostPath: PROJECT_DIR, // this.sourcePath
containerPath: AssetStaging.BUNDLING_INPUT_DIR,
},
{
hostPath: outputDir, // bundleDir
containerPath: AssetStaging.BUNDLING_OUTPUT_DIR ?? outputDir,
},
...(options.volumes ?? []),
];
options.image.run({
command: options.command,
user,
volumes,
environment: options.environment,
workingDirectory:
options.workingDirectory ?? AssetStaging.BUNDLING_INPUT_DIR,
});
options.image.cp(AssetStaging.BUNDLING_OUTPUT_DIR ?? outputDir, outputDir);
return true;
}
}
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (10 by maintainers)
Top Results From Across the Web
aws-cdk/core module
Sometimes you will need to put together or pick apart Amazon Resource Names (ARNs). The functions stack.formatArn() and stack.parseArn() exist for this purpose....
Read more >cdk-lambda-subminute - Python Package Health Analysis - Snyk
Learn more about cdk-lambda-subminute: package health score, ... BundlingDockerImage.cp() needs to be explained more in the README #11914 ...
Read more >Cdk-lambda-subminute - npm.io
You only need to craft a Lambda function and then assign it as an argument into ... BundlingDockerImage.cp() needs to be explained more...
Read more >aws-cdk | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. ... Display full readme Display full readme ...
Read more >README
Parallel computing has became an important tool to analysis large and complex ... The core component of DockerParallel , as its name implies,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the API for
BundlingDockerImage
can be improved:And then, we can also add something like:
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.
docker cp
will be much faster to extract files from the built image as oppose to running a command inside the image.@jogold what do you think?