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

Asset building uses incorrect temp folder on mac #8465

Closed
awijnia opened this issue Jun 10, 2020 · 4 comments · Fixed by #8469
Closed

Asset building uses incorrect temp folder on mac #8465

awijnia opened this issue Jun 10, 2020 · 4 comments · Fixed by #8469
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@awijnia
Copy link
Contributor

awijnia commented Jun 10, 2020

Building assets on macOS uses a temp folder that is not accessible on the mac. The folder /var/folders is protected. The correct folder on macOS is /private/var/folders

Reproduction Steps

    const assetPath = path.join(__dirname, 'python-lambda-handler');
    const fn = new lambda.Function(this, 'Function', {
      code: lambda.Code.fromAsset(assetPath, {
        
        bundling: {
          image: lambda.Runtime.PYTHON_3_6.bundlingDockerImage,
          command: [
            'bash', '-c', [
              'rsync -r . /asset-output',
              'cd /asset-output',
              'pip install -r requirements.txt -t .',
            ].join(' && '),
          ],
        },
      }),
      runtime: lambda.Runtime.PYTHON_3_6,
      handler: 'index.handler',
    });

Error Log

stderr: docker: Error response from daemon: Mounts denied:
The path /var/folders/51/82x5pt6s7_l8rymy5gqpf5dr0000gn/T/cdk-asset-bundle-aePfzr
is not shared from OS X and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> File Sharing.
See https://docs.docker.com/docker-for-mac/osxfs/#namespaces for more info.

Environment

  • **CLI Version : 1.45.0
  • **Framework Version: 1.45.0
  • **Node.js Version: 14.4.0
  • **OS : macOS
  • **Language (Version): Typescript

Other

To solve the error the correct temp directory should be set. The npm package temp-dir can fix this error.

The file asset-staging.js
const bundleDir = fs.mkdtempSync(path.resolve(path.join(os.tmpdir(), 'cdk-asset-bundle-')));
should then be changed in:
const bundleDir = fs.mkdtempSync(path.resolve(path.join(require('temp-dir'), 'cdk-asset-bundle-')));


This is 🐛 Bug Report

@awijnia awijnia added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 10, 2020
@jogold
Copy link
Contributor

jogold commented Jun 10, 2020

OK, temp-dir just does fs.realpathSync(os.tmpdir()), will fix this.

jogold added a commit to jogold/aws-cdk that referenced this issue Jun 10, 2020
The `os.tmpdir()` built-in doesn't return the real path when the
returned path is a symlink.

Add a `FileSystem.tmpdir` that wraps `os.tmpdir()` in a
`fs.realpathSync()` and caches the result.

Fixes aws#8465
@mergify mergify bot closed this as completed in #8469 Jun 10, 2020
mergify bot pushed a commit that referenced this issue Jun 10, 2020
The `os.tmpdir()` built-in doesn't return the real path when the
returned path is a symlink.

Add a `FileSystem.tmpdir` that wraps `os.tmpdir()` in a
`fs.realpathSync()` and caches the result.

Add a `FileSystem.mkdtemp()` to create temp directories in
the system temp directory.

Fixes #8465


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@pgarbe
Copy link
Contributor

pgarbe commented Aug 28, 2020

This seems not to be fixed. Bundling assets as part of NodeJsFunction still uses a temp folder under /var/folders (CDK v1.61.0)

@stanmarsh2
Copy link

I got the same problem as @pgarbe mentioned on 1.63.0.
As a work-around added folder as shared resource: Docker -> Preferences -> Resources -> File Sharing -> /var/folders/ng/XXXXXYYYYYZZZZZ/

@gradybarrett
Copy link

gradybarrett commented Sep 24, 2020

I'm also having this same problem:

docker: Error response from daemon: Mounts denied:
The path /var/folders/w4/8ykdwb4j1cqdmppn9_4mn_lw0000gn/T/cdk.outIbEgm6/bundling-temp-KhjHwV
is not shared from OS X and is not known to Docker.

But only when run tests. Bundling when synthesizing works.

I was also able to get past it by sharing /var/folders with docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants