forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda-nodejs): permission denied on npm cache (aws#9167)
The npm cache was owned by the user 1000 so if the image was run by a user other than 1000 installing via npm (when using the `nodeModules` prop) resulted in a `EACCES` error on the cache folder. Yarn automatically falls back to `/tmp` in this case. Move npm cache folder creation to the end of the Dockerfile so that no root content has been created in it when the image starts. Set cache folder permission to 777. Also disable npm update notification and add tests for the Dockerfile. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
2 changed files
with
47 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { spawnSync } from 'child_process'; | ||
import * as path from 'path'; | ||
|
||
beforeAll(() => { | ||
spawnSync('docker', ['build', '-t', 'parcel', path.join(__dirname, '../parcel')]); | ||
}); | ||
|
||
test('parcel is available', async () => { | ||
const proc = spawnSync('docker', [ | ||
'run', 'parcel', | ||
'sh', '-c', | ||
'$(node -p "require.resolve(\'parcel\')") --version', | ||
]); | ||
expect(proc.status).toEqual(0); | ||
}); | ||
|
||
test('can npm install with non root user', async () => { | ||
const proc = spawnSync('docker', [ | ||
'run', '-u', '1000:1000', | ||
'parcel', | ||
'sh', '-c', [ | ||
'mkdir /tmp/test', | ||
'cd /tmp/test', | ||
'npm i constructs', | ||
].join(' && ')]); | ||
expect(proc.status).toEqual(0); | ||
}); | ||
|
||
test('can yarn install with non root user', async () => { | ||
const proc = spawnSync('docker', [ | ||
'run', '-u', '500:500', | ||
'parcel', | ||
'sh', '-c', [ | ||
'mkdir /tmp/test', | ||
'cd /tmp/test', | ||
'yarn add constructs', | ||
].join(' && ')]); | ||
expect(proc.status).toEqual(0); | ||
}); |