Skip to content

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

@dmlook-pillpack

Description

@dmlook-pillpack

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

Metadata

Metadata

Assignees

Labels

@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.docs/inlineRelated to inline documentation of the API ReferencedocumentationThis is a problem with documentation.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions