Skip to content

Commit

Permalink
feat: decouple "synth" and "deploy" through cloud assemblies (#2636)
Browse files Browse the repository at this point in the history
Formalize the concept of a cloud assembly to allow decoupling "synth" and "deploy". the main
motivation is to allow "deploy" to run in a controlled environment without needing to execute the app for security purposes.

`cdk synth` now produces a self-contained assembly in the output directory, which we call a "cloud assembly". this directory includes synthesized templates (similar to current behavior) but also a "manifest.json" file and the asset staging directories.

`cdk deploy -a assembly-dir` will now skip synthesis and will directly deploy the assembly.

To that end, we modified the behavior of asset staging such that all synth output always goes to the output directory, which is by default `cdk.out` (can be set with `--output`). if there's a single template, it is printed to stdout, otherwise the name of output directory is printed.

This PR also includes multiple clean ups and deprecations of stale APIs and modules such as:

- `cdk.AppProps` includes various new options.
- An error is thrown if references between stacks that are not in the same app (mostly in test cases).
- Added the token creation stack trace for errors emitted by tokens
- Added `ConstructNode.root` which returns the tree root.
 

**TESTING**: verified that all integration tests passed and added a few tests to verify zip and docker assets as well as cloud assemblies. See: https://github.com/awslabs/cdk-ops/pull/364

Closes #1893 
Closes #2093 
Closes #1954 
Closes #2310 
Related #2073 
Closes #1245
Closes #341
Closes #956
Closes #233

BREAKING CHANGE: *IMPORTANT*: apps created with the CDK version 0.33.0 and above cannot be used with an older CLI version.
- `--interactive` has been removed
- `--numbered` has been removed
- `--staging` is now a boolean flag that indicates whether assets should be copied to the `--output` directory or directly referenced (`--no-staging` is useful for e.g. local debugging with SAM CLI)
- Assets (e.g. Lambda code assets) are now referenced relative to the output directory.
- `SynthUtils.templateForStackName` has been removed (use `SynthUtils.synthesize(stack).template`).
- `cxapi.SynthesizedStack` renamed to `cxapi.CloudFormationStackArtifact` with multiple API changes.
- `cdk.App.run()` now returns a `cxapi.CloudAssembly` instead of `cdk.ISynthesisSession`.
- `cdk.App.synthesizeStack` and `synthesizeStacks` has been removed. The `cxapi.CloudAssembly` object returned from `app.run()` can be used as an alternative to explore a synthesized assembly programmatically (resolves #2016).
- `cdk.CfnElement.creationTimeStamp` may now return `undefined` if there is no stack trace captured.
- `cdk.ISynthesizable.synthesize` now accepts a `cxapi.CloudAssemblyBuilder` instead of `ISynthesisSession`.
- `cdk`: The concepts of a synthesis session and session stores have been removed (`cdk.FileSystemStore`, cdk.InMemoryStore`, `cdk.SynthesisSession`, `cdk.ISynthesisSession` and `cdk.SynthesisOptions`).
- No more support for legacy manifests (`cdk.ManifestOptions` member `legacyManifest` has been removed)
- All support for build/bundle manifest have been removed (`cxapi.BuildManifest`, `cxapi.BuildStep`, etc).
- Multiple deprecations and breaking changes in the `cxapi` module (`cxapi.AppRuntime` has been renamed to `cxapi.RuntimeInfo`, `cxapi.SynthesizeResponse`, `cxapi.SynthesizedStack` has been removed)
- The `@aws-cdk/applet-js` program is no longer available. Use [decdk](https://github.com/awslabs/aws-cdk/tree/master/packages/decdk) as an alternative.
  • Loading branch information
Elad Ben-Israel authored May 29, 2019
1 parent 9a48b66 commit c52bcfc
Show file tree
Hide file tree
Showing 155 changed files with 7,371 additions and 2,583 deletions.
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",
"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

0 comments on commit c52bcfc

Please sign in to comment.