Skip to content

Commit

Permalink
feat(lambda-nodejs): support build args
Browse files Browse the repository at this point in the history
Add support for passing build arguments when building the bundling
image.

Closes aws#8117
  • Loading branch information
jogold committed Jul 13, 2020
1 parent 31d6e65 commit 760526e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
12 changes: 10 additions & 2 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import * as fs from 'fs';
import * as path from 'path';
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import { PackageJsonManager } from './package-json-manager';
import { findUp } from './util';

Expand Down Expand Up @@ -71,6 +71,13 @@ export interface ParcelBaseOptions {
* @default - 2.0.0-beta.1
*/
readonly parcelVersion?: string;

/**
* Build arguments to pass when building the bundling image.
*
* @default - no build arguments are passed
*/
readonly buildArgs?: { [key:string] : string };
}

/**
Expand Down Expand Up @@ -105,6 +112,7 @@ export class Bundling {
// Bundling image derived from runtime bundling image (lambci)
const image = cdk.BundlingDockerImage.fromAsset(path.join(__dirname, '../parcel'), {
buildArgs: {
...options.buildArgs ?? {},
IMAGE: options.runtime.bundlingDockerImage.image,
PARCEL_VERSION: options.parcelVersion ?? '2.0.0-beta.1',
},
Expand Down
24 changes: 21 additions & 3 deletions packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

import { Code, Runtime } from '@aws-cdk/aws-lambda';
import { AssetHashType } from '@aws-cdk/core';
import { version as delayVersion } from 'delay/package.json';
import * as fs from 'fs';
import * as path from 'path';
import { Code, Runtime } from '@aws-cdk/aws-lambda';
import { AssetHashType, BundlingDockerImage } from '@aws-cdk/core';
import { version as delayVersion } from 'delay/package.json';
import { Bundling } from '../lib/bundling';
import * as util from '../lib/util';

Expand All @@ -18,6 +18,7 @@ const findUpMock = jest.spyOn(util, 'findUp').mockImplementation((name: string,
}
return originalFindUp(name, directory);
});
const fromAssetMock = jest.spyOn(BundlingDockerImage, 'fromAsset');

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -157,3 +158,20 @@ test('Detects yarn.lock', () => {
}),
});
});

test('with build args', () => {
Bundling.parcel({
entry: '/project/folder/entry.ts',
runtime: Runtime.NODEJS_12_X,
projectRoot: '/project',
buildArgs: {
HELLO: 'WORLD',
},
});

expect(fromAssetMock).toHaveBeenCalledWith(expect.stringMatching(/parcel$/), expect.objectContaining({
buildArgs: expect.objectContaining({
HELLO: 'WORLD',
}),
}));
});

0 comments on commit 760526e

Please sign in to comment.