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

feat: decouple "synth" and "deploy" through cloud assemblies #2636

Merged
merged 31 commits into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b5641a3
interim
May 24, 2019
971957b
feat(cli): cloud assembly - decouple synth and deploy
May 24, 2019
2aac0f9
Merge remote-tracking branch 'origin/master' into benisrae/cloud-asse…
May 24, 2019
a29f289
deprecate applets
May 24, 2019
76d4abc
a few test fixes
May 24, 2019
f49ef1b
update more tests
May 24, 2019
27323a5
fix lambda test
May 24, 2019
09a7b2f
fix codecommit test
May 24, 2019
2c6e184
fix a few more tests
May 24, 2019
e004555
fix decdk test
May 24, 2019
d4fb3c0
add missing package.lock
May 26, 2019
7d42d2f
add semver back
May 26, 2019
d0f6ae0
cli: fail if unable to resolve aws region
May 27, 2019
4f7e680
cli: support relative asset paths
May 27, 2019
2962c9b
add "deprecated" to applet-js package.json
May 28, 2019
6cc76d1
update error message when --output is undefined
May 28, 2019
d3d3e11
rename variable in test.assertions
May 28, 2019
e2cbec1
move jest config to package.json
May 28, 2019
ee39a2e
misc
May 28, 2019
8f67b13
add support for assets in testStack
May 29, 2019
a4c776a
save & emit token creation stack traces
May 29, 2019
9fe08a6
app.isApp
May 29, 2019
3330736
node.root
May 29, 2019
74ab7aa
fail if referencing tokens across apps
May 29, 2019
caac4b9
fix test.code
May 29, 2019
09e1543
Merge remote-tracking branch 'origin/master' into benisrae/cloud-asse…
May 29, 2019
ebe7109
fix some build issues
May 29, 2019
c0a7b4f
do not import SynthUtils
May 29, 2019
aea33fe
SynthUtil: always synth against root
May 29, 2019
90c1124
fix various tests
May 29, 2019
d40b6de
fix elbv2 tests
May 29, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ coverage/
# CDK Context & Staging files
cdk.context.json
.cdk.staging/
cdk.out/

3 changes: 3 additions & 0 deletions packages/@aws-cdk/applet-js/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## AWS CDK applet host program for Javascript

CDK applets have been deprecated in favor of [decdk](https://github.com/awslabs/aws-cdk/tree/master/packages/decdk).

This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.
105 changes: 2 additions & 103 deletions packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,3 @@
#!/usr/bin/env node
import 'source-map-support/register';

import cdk = require('@aws-cdk/cdk');
import child_process = require('child_process');
import fs = require('fs-extra');
import os = require('os');
import path = require('path');
import YAML = require('yaml');

import { isStackConstructor, parseApplet } from '../lib/applet-helpers';

main().catch(e => {
// tslint:disable-next-line:no-console
console.error(e);
process.exit(1);
});

async function main() {
const progname = path.basename(process.argv[1]);

const appletFile = process.argv[2];
if (!appletFile) {
throw new Error(`Usage: ${progname} <applet.yaml>`);
}

// read applet(s) properties from the provided file
const fileContents = YAML.parse(await fs.readFile(appletFile, { encoding: 'utf-8' }));
if (typeof fileContents !== 'object') {
throw new Error(`${appletFile}: should contain a YAML object`);
}
const appletMap = fileContents.applets;
if (!appletMap) {
throw new Error(`${appletFile}: must have an 'applets' key`);
}

const searchDir = path.dirname(appletFile);
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'cdkapplet'));
try {
const app = new cdk.App();

for (const [name, definition] of Object.entries(appletMap)) {
await constructStack(app, searchDir, tempDir, name, definition);
}
app.run();
} finally {
await fs.remove(tempDir);
}
}

/**
* Construct a stack from the given props
* @param props Const
*/
async function constructStack(app: cdk.App, searchDir: string, tempDir: string, stackName: string, spec: any) {
// the 'applet' attribute tells us how to load the applet. in the javascript case
// it will be in the format <module>:<class> where <module> is technically passed to "require"
// and <class> is expected to be exported from the module.
const appletSpec: string | undefined = spec.type;
if (!appletSpec) {
throw new Error(`Applet ${stackName} missing "type" attribute`);
}

const applet = parseApplet(appletSpec);

const props = spec.properties || {};

if (applet.npmPackage) {
// tslint:disable-next-line:no-console
console.error(`Installing NPM package ${applet.npmPackage}`);
// Magic marker to download this package directly off of NPM
// We're going to run NPM as a shell (since programmatic usage is not stable
// by their own admission) and we're installing into a temporary directory.
// (Installing into a permanent directory is useless since NPM doesn't do
// any real caching anyway).
child_process.execFileSync('npm', ['install', '--prefix', tempDir, '--global', applet.npmPackage], {
stdio: 'inherit'
});
searchDir = path.join(tempDir, 'lib');
}

// we need to resolve the module name relatively to where the applet file is
// and not relative to this module or cwd.
const modulePath = require.resolve(applet.moduleName, { paths: [ searchDir ] });

// load the module
const pkg = require(modulePath);

// find the applet class within the package
// tslint:disable-next-line:variable-name
const appletConstructor = pkg[applet.className];
if (!appletConstructor) {
throw new Error(`Cannot find applet class "${applet.className}" in module "${applet.moduleName}"`);
}

if (isStackConstructor(appletConstructor)) {
// add the applet stack into the app.
new appletConstructor(app, stackName, props);
} else {
// Make a stack THEN add it in
const stack = new cdk.Stack(app, stackName, props);
new appletConstructor(stack, 'Default', props);
}
}
// tslint:disable-next-line:no-console
console.error('applets are no longer supported. see: https://github.com/awslabs/aws-cdk/tree/master/packages/decdk');
52 changes: 0 additions & 52 deletions packages/@aws-cdk/applet-js/lib/applet-helpers.ts

This file was deleted.

8 changes: 1 addition & 7 deletions packages/@aws-cdk/applet-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@aws-cdk/applet-js",
"version": "0.32.0",
"deprecated": "Applets have been deprecated in favor of 'decdk'",
"description": "Javascript CDK applet host program",
"main": "bin/cdk-applet-js.js",
"types": "bin/cdk-applet-js.d.ts",
Expand All @@ -25,16 +26,9 @@
"license": "Apache-2.0",
"devDependencies": {
"@types/fs-extra": "^5.0.5",
"@types/yaml": "^1.0.2",
eladb marked this conversation as resolved.
Show resolved Hide resolved
"cdk-build-tools": "^0.32.0",
"pkglint": "^0.32.0"
},
"dependencies": {
"@aws-cdk/cdk": "^0.32.0",
"fs-extra": "^7.0.1",
"source-map-support": "^0.5.12",
"yaml": "^1.5.0"
},
"repository": {
"url": "https://github.com/awslabs/aws-cdk.git",
"type": "git",
Expand Down
35 changes: 0 additions & 35 deletions packages/@aws-cdk/applet-js/test/expected1.json

This file was deleted.

48 changes: 0 additions & 48 deletions packages/@aws-cdk/applet-js/test/expected2.json

This file was deleted.

7 changes: 0 additions & 7 deletions packages/@aws-cdk/applet-js/test/expected3.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@aws-cdk/applet-js/test/manual-test-npm.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions packages/@aws-cdk/applet-js/test/negative-test4.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions packages/@aws-cdk/applet-js/test/negative-test5.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions packages/@aws-cdk/applet-js/test/negative-test6.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions packages/@aws-cdk/applet-js/test/negative-test7.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions packages/@aws-cdk/applet-js/test/test-applet.ts

This file was deleted.

35 changes: 0 additions & 35 deletions packages/@aws-cdk/applet-js/test/test-multistack-expected.json

This file was deleted.

Loading