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

[WIP] chore: clarify build dependencies for future hermetic builds #10039

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4d3d48d
chore: cleanup build commands
rix0rrr Jul 9, 2020
f526503
Merge remote-tracking branch 'origin/master' into huijbers/cleanup-build
rix0rrr Jul 10, 2020
2bf1c29
Fix build errors
rix0rrr Jul 10, 2020
e1f076d
Ignore nazel.json
rix0rrr Jul 10, 2020
d0a4339
Need to move junit-dep to top to make it correct
rix0rrr Jul 10, 2020
1eaf9b2
Fixing assumptions on source tree layout
rix0rrr Jul 10, 2020
99c1b5c
Always chasing after lambda-nodejs
rix0rrr Jul 19, 2020
1af9d2a
Rewrite package.jsons to match rename nazel => nozem
rix0rrr Jul 29, 2020
ed96171
Rename NZL_PACKAGE_SOURCE => NZM_PACKAGE_SOURCE
rix0rrr Jul 29, 2020
1d4f5bc
Merge remote-tracking branch 'origin/master' into huijbers/cleanup-build
rix0rrr Jul 29, 2020
cc69d96
Fixing eslint references
rix0rrr Jul 29, 2020
d770189
More renames to NZM
rix0rrr Jul 31, 2020
496661a
Add dependency
rix0rrr Jul 31, 2020
34b56a4
Merge remote-tracking branch 'origin/master' into huijbers/cleanup-build
rix0rrr Aug 28, 2020
e4576b8
Commit missing change
rix0rrr Aug 28, 2020
05067a3
Fix incorrect `constructs` version
rix0rrr Aug 28, 2020
3fbe588
Some more broken references
rix0rrr Aug 28, 2020
7ee5c4e
Fix engine spec
rix0rrr Aug 28, 2020
c9f896e
Except canary source file from gitignore
rix0rrr Aug 28, 2020
e8a75fc
make aws-lambda-python build
rix0rrr Aug 28, 2020
8fe0f06
Update aws-lambda expectations
rix0rrr Aug 28, 2020
cd05018
Make aws-lambda-nodejs build
rix0rrr Aug 28, 2020
989da8e
Fix jest.config.js reference
rix0rrr Aug 28, 2020
9f0d6c3
Make lambda-python less stringent about its testing requirements
rix0rrr Aug 28, 2020
98446f8
Make aws-certificatemanager not accidentally run the tests from the
rix0rrr Aug 29, 2020
52de92d
Update version
rix0rrr Aug 29, 2020
69aed52
Fix decdk build
rix0rrr Sep 1, 2020
781b5f4
Merge remote-tracking branch 'origin/master' into huijbers/cleanup-build
rix0rrr Sep 30, 2020
5cb1200
Don't disable pkglint
rix0rrr Sep 30, 2020
704e65e
Build rule tweaks
rix0rrr Sep 30, 2020
6341603
Watch using `cdk-watch`
rix0rrr Sep 30, 2020
0dae350
NO longer need yaml
rix0rrr Sep 30, 2020
a2da71d
Commmaaaaaa
rix0rrr Sep 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ yarn-error.log

# Parcel default cache directory
.parcel-cache
nozem.json

# Cloud9
.c9
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"build-all": "tsc -b"
},
"devDependencies": {
"@types/jest": "^26.0.10",
"@types/node": "^10.17.25",
"@typescript-eslint/parser": "^2.19.2",
"conventional-changelog-cli": "^2.1.0",
"fs-extra": "^9.0.1",
"graceful-fs": "^4.2.4",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/assert/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './assertion';
export * from './canonicalize-assets';
export * from './expect';
export * from './canonicalize-assets';
export * from './inspector';
export * from './synth-utils';

Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
"engines": {
"node": ">= 10.13.0 <13 || >=13.7.0"
},
"nozem": {
"ostools": ["rm", "tar"]
},
"stability": "deprecated",
"maturity": "deprecated",
"awscdkio": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const baseConfig = require('cdk-build-tools/config/eslintrc');
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
module.exports = baseConfig;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
},
"license": "Apache-2.0",
"devDependencies": {
"cdk-build-tools": "0.0.0",
"aws-sdk": "^2.596.0",
"aws-sdk-mock": "^5.0.0",
"sinon": "^9.0.2",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.19.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codedeploy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ nyc.config.js
.LAST_PACKAGE
*.snk
!.eslintrc.js

junit.xml
!test/lambda/*/*.js
junit.xml
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-codeguruprofiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"pkglint": "0.0.0"
},
"dependencies": {
"constructs": "^3.0.4",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/core": "0.0.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"aws-sdk": "^2.596.0",
"aws-sdk-mock": "^5.0.0",
"eslint": "^6.8.0",
"sinon": "^9.0.2",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-node": "^10.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@aws-cdk/assert": "0.0.0",
"@types/jest": "^26.0.10",
"aws-sdk": "^2.739.0",
"@types/sinon": "^9.0.4",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ec2/test/userdata.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Bucket } from '@aws-cdk/aws-s3';
import { Stack } from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { Stack } from '../../core/lib';
import * as ec2 from '../lib';

nodeunitShim({
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ecr-assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/minimatch": "^3.0.3",
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.31",
"@types/proxyquire": "^1.3.28",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-eks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/sinon": "^9.0.4",
"@types/nodeunit": "^0.0.31",
"@types/yaml": "1.2.0",
"aws-sdk": "^2.739.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-events-targets/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ nyc.config.js
*.snk
.cdk.staging

!build-tools/*

lib/sdk-api-metadata.json
!.eslintrc.js
!jest.config.js
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-glue/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const baseConfig = require('../../../tools/cdk-build-tools/config/jest.config');
const baseConfig = require('cdk-build-tools/config/jest.config');
module.exports = baseConfig;
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-iam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@
"license": "Apache-2.0",
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/aws-lambda": "^8.10.39",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
"jest": "^25.5.4",
"pkglint": "0.0.0",
"aws-sdk": "^2.739.0",
"@types/sinon": "^9.0.4",
"sinon": "^9.0.3"
},
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@aws-cdk/assert": "0.0.0",
"aws-sdk": "^2.713.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"delay": "4.4.0",
Expand All @@ -85,6 +87,10 @@
"awscdkio": {
"announce": false
},
"nozem": {
"ostools": ["docker"],
"copyAllSourcesForTest": true
},
"cdk-build": {
"jest": true
}
Expand Down
24 changes: 19 additions & 5 deletions packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { Stack } from '@aws-cdk/core';
import { NodejsFunction } from '../lib';
import { Bundling } from '../lib/bundling';

const PROJECT_ROOT = process.env.NZM_SOURCE_PACKAGE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to avoid taking this dependency on the nozem
Environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I'll be honest with you, the aws-lambda-nodejs package is the bane of my existence here.

In this case, this exists to tell it where the .git directory of the source repository is. I don't know why it needs to know that, but right now I'm just telling it in an attempt to get the build to pass.

Copy link
Contributor

@jogold jogold Aug 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lookup the project root because this is what we mount as /asset-input to be sure to have access to all node modules and dependencies when bundling in the container. Would a fallback on looking for a lockfile (yarn.lock, package-lock.json) improve things here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel auto discovery of the project root is a source of confusion and odd issues for many users. Maybe we should just make that explicitly required?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice to have it auto discovered.

What about this?

// Find project root
const projectRoot = options.projectRoot
  ?? findUp(`.git${path.sep}`)
  ?? findUp('yarn.lock')
  ?? findUp('package-lock.json')
  ?? findUp('package.json');

here

// Find project root
const projectRoot = options.projectRoot ?? findUp(`.git${path.sep}`);
if (!projectRoot) {
throw new Error('Cannot find project root. Please specify it with `projectRoot`.');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a lockfile in this case also doesn't help me. I'm trying to do an isolated build of the package. There's a yarn.lock somewhere but you shouldn't care about that.

My build script has set up the build environment exactly as Node-based tools should expect it (node_modules in the right place and everything). There's no yarn.lock or package-lock.json in sight.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there's a package.json right? so it should work.

? process.env.NZM_SOURCE_PACKAGE
: path.join(__dirname, '..');

jest.mock('../lib/bundling', () => {
return {
Bundling: {
Expand All @@ -28,10 +32,12 @@ beforeEach(() => {

test('NodejsFunction with .ts handler', () => {
// WHEN
new NodejsFunction(stack, 'handler1');
new NodejsFunction(stack, 'handler1', {
projectRoot: PROJECT_ROOT,
});

expect(Bundling.parcel).toHaveBeenCalledWith(expect.objectContaining({
entry: expect.stringContaining('function.test.handler1.ts'), // Automatically finds .ts handler file
entry: expect.stringContaining('function.test.handler1.'), // Automatically finds .ts handler file
}));

expect(stack).toHaveResource('AWS::Lambda::Function', {
Expand All @@ -41,7 +47,9 @@ test('NodejsFunction with .ts handler', () => {

test('NodejsFunction with .js handler', () => {
// WHEN
new NodejsFunction(stack, 'handler2');
new NodejsFunction(stack, 'handler2', {
projectRoot: PROJECT_ROOT,
});

// THEN
expect(Bundling.parcel).toHaveBeenCalledWith(expect.objectContaining({
Expand All @@ -52,6 +60,7 @@ test('NodejsFunction with .js handler', () => {
test('NodejsFunction with container env vars', () => {
// WHEN
new NodejsFunction(stack, 'handler1', {
projectRoot: PROJECT_ROOT,
parcelEnvironment: {
KEY: 'VALUE',
},
Expand All @@ -67,6 +76,7 @@ test('NodejsFunction with container env vars', () => {
test('throws when entry is not js/ts', () => {
expect(() => new NodejsFunction(stack, 'Fn', {
entry: 'handler.py',
projectRoot: PROJECT_ROOT,
})).toThrow(/Only JavaScript or TypeScript entry files are supported/);
});

Expand All @@ -85,15 +95,19 @@ test('accepts tsx', () => {
test('throws when entry does not exist', () => {
expect(() => new NodejsFunction(stack, 'Fn', {
entry: 'notfound.ts',
projectRoot: PROJECT_ROOT,
})).toThrow(/Cannot find entry file at/);
});

test('throws when entry cannot be automatically found', () => {
expect(() => new NodejsFunction(stack, 'Fn')).toThrow(/Cannot find entry file./);
expect(() => new NodejsFunction(stack, 'Fn', {
projectRoot: PROJECT_ROOT,
})).toThrow(/Cannot find entry file./);
});

test('throws with the wrong runtime family', () => {
expect(() => new NodejsFunction(stack, 'handler1', {
projectRoot: PROJECT_ROOT,
runtime: Runtime.PYTHON_3_8,
})).toThrow(/Only `NODEJS` runtimes are supported/);
});
Expand All @@ -105,7 +119,7 @@ test('resolves entry to an absolute path', () => {
});

expect(Bundling.parcel).toHaveBeenCalledWith(expect.objectContaining({
entry: expect.stringMatching(/@aws-cdk\/aws-lambda-nodejs\/lib\/index.ts$/),
entry: path.resolve(__dirname, '..', 'lib', 'index.ts'),
}));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ class TestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const projectRoot = process.env.NZM_PACKAGE_SOURCE
? path.join(process.env.NZM_PACKAGE_SOURCE, '..', '..', '..')
: undefined;

// This function uses aws-sdk but it will not be included
new lambda.NodejsFunction(this, 'external', {
projectRoot,
entry: path.join(__dirname, 'integ-handlers/dependencies.ts'),
runtime: Runtime.NODEJS_12_X,
minify: true,
Expand Down
13 changes: 11 additions & 2 deletions packages/@aws-cdk/aws-lambda-nodejs/test/integ.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ class TestStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

const projectRoot = process.env.NZM_PACKAGE_SOURCE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels odd that we will need to do that everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the least odd part about it. If we need to do it once we need to do it everywhere :)

? path.join(process.env.NZM_PACKAGE_SOURCE, '..', '..', '..')
: undefined;
const testRoot = process.env.NZM_PACKAGE_SOURCE
? path.join(process.env.NZM_PACKAGE_SOURCE, 'test')
: __dirname;

new lambda.NodejsFunction(this, 'ts-handler', {
entry: path.join(__dirname, 'integ-handlers/ts-handler.ts'),
projectRoot,
entry: path.join(testRoot, 'integ-handlers/ts-handler.ts'),
runtime: Runtime.NODEJS_12_X,
minify: true,
});

new lambda.NodejsFunction(this, 'js-handler', {
entry: path.join(__dirname, 'integ-handlers/js-handler.js'),
projectRoot,
entry: path.join(testRoot, 'integ-handlers/js-handler.js'),
runtime: Runtime.NODEJS_12_X,
});
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-lambda-nodejs/test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { findUp } from '../lib/util';

test('findUp', () => {
// Starting at process.cwd()
expect(findUp('README.md')).toMatch(/aws-lambda-nodejs$/);
expect(findUp('README.md')).toEqual(path.resolve(__dirname, '..'));

// Non existing file
expect(findUp('non-existing-file.unknown')).toBe(undefined);

// Starting at a specific path
expect(findUp('util.test.ts', path.join(__dirname, 'integ-handlers'))).toMatch(/aws-lambda-nodejs\/test$/);
expect(findUp('util.test.ts', path.join(__dirname, 'integ-handlers'))).toEqual(__dirname);

// Non existing file starting at a non existing relative path
expect(findUp('not-to-be-found.txt', 'non-existing/relative/path')).toBe(undefined);

// Starting at a relative path
expect(findUp('util.test.ts', 'test/integ-handlers')).toMatch(/aws-lambda-nodejs\/test$/);
expect(findUp('util.test.ts', 'test/integ-handlers')).toEqual(__dirname);
});
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
]
},
"stability": "stable",
"nozem": {
"ostools": ["docker"]
},
"awscdkio": {
"announce": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"Properties": {
"Code": {
"S3Bucket": {
"Ref": "AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34S3BucketB47CCF1E"
"Ref": "AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cS3BucketE8900D83"
},
"S3Key": {
"Fn::Join": [
Expand All @@ -49,7 +49,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34S3VersionKey80D7B84B"
"Ref": "AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cS3VersionKeyFD066EB8"
}
]
}
Expand All @@ -62,7 +62,7 @@
"Fn::Split": [
"||",
{
"Ref": "AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34S3VersionKey80D7B84B"
"Ref": "AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cS3VersionKeyFD066EB8"
}
]
}
Expand Down Expand Up @@ -127,17 +127,17 @@
}
},
"Parameters": {
"AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34S3BucketB47CCF1E": {
"AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cS3BucketE8900D83": {
"Type": "String",
"Description": "S3 bucket for asset \"8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34\""
"Description": "S3 bucket for asset \"5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3c\""
},
"AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34S3VersionKey80D7B84B": {
"AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cS3VersionKeyFD066EB8": {
"Type": "String",
"Description": "S3 key for asset version \"8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34\""
"Description": "S3 key for asset version \"5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3c\""
},
"AssetParameters8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34ArtifactHash70E274C4": {
"AssetParameters5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3cArtifactHashD5562C20": {
"Type": "String",
"Description": "Artifact hash for asset \"8811a2632ac5564a08fd269e159298f7e497f259578b0dc5e927a1f48ab24d34\""
"Description": "Artifact hash for asset \"5bfcc5e85793015838d125d6e30f1a931da22ebe768a9bad5cd1b17fd6bd0a3c\""
}
}
}
Loading