Skip to content

Commit

Permalink
fix(asset-staging): call os.userInfo() only when not bundling locally
Browse files Browse the repository at this point in the history
The user is only needed when bundling via Docker so there is no need to always call os.userInfo() as a default fallback even when bundling locally.

Additionally, calling os.userInfo() can easily fail when already running inside a Docker container with non-existent uid and gid (e.g. when using the Jenkins Docker plugin).
  • Loading branch information
Alexander Kuntsch authored and Alexander Kuntsch committed Jun 25, 2021
1 parent 94eb3a8 commit 6f50ee9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions packages/@aws-cdk/core/lib/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,6 @@ export class AssetStaging extends CoreConstruct {
// Chmod the bundleDir to full access.
fs.chmodSync(bundleDir, 0o777);

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 = [
{
Expand All @@ -457,6 +447,16 @@ export class AssetStaging extends CoreConstruct {

localBundling = options.local?.tryBundle(bundleDir, options);
if (!localBundling) {
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';
}

options.image.run({
command: options.command,
user,
Expand Down

0 comments on commit 6f50ee9

Please sign in to comment.