question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(core): BundlingDockerImage.cp() needs to be explained more in the README

See original GitHub issue

When using lambda.Code.fromAsset and cdk.BundlingDockerImage.fromAsset together, synth fails to find anything in \asset-output

Reproduction Steps

  1. 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
  1. Use the following snippet when creating the lambda using cdk:
code: lambda.Code.fromAsset(PROJECT_DIR, {
        bundling: {
          image: cdk.BundlingDockerImage.fromAsset(PROJECT_DIR)
        }
      }),
  1. 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:closed
  • Created 3 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
eladbcommented, Dec 28, 2020
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 BundlingDockerImage can be improved:

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',
});
1reaction
eladbcommented, Dec 10, 2020

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.

  1. In this case the asset input is meaningless.
  2. Ideally 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found