Skip to content

Commit c52bcfc

Browse files
author
Elad Ben-Israel
authored
feat: decouple "synth" and "deploy" through cloud assemblies (#2636)
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.
1 parent 9a48b66 commit c52bcfc

File tree

155 files changed

+7371
-2583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+7371
-2583
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ coverage/
2626
# CDK Context & Staging files
2727
cdk.context.json
2828
.cdk.staging/
29+
cdk.out/
30+

Diff for: packages/@aws-cdk/applet-js/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
## AWS CDK applet host program for Javascript
2+
3+
CDK applets have been deprecated in favor of [decdk](https://github.com/awslabs/aws-cdk/tree/master/packages/decdk).
4+
25
This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.

Diff for: packages/@aws-cdk/applet-js/bin/cdk-applet-js.ts

+2-103
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,3 @@
11
#!/usr/bin/env node
2-
import 'source-map-support/register';
3-
4-
import cdk = require('@aws-cdk/cdk');
5-
import child_process = require('child_process');
6-
import fs = require('fs-extra');
7-
import os = require('os');
8-
import path = require('path');
9-
import YAML = require('yaml');
10-
11-
import { isStackConstructor, parseApplet } from '../lib/applet-helpers';
12-
13-
main().catch(e => {
14-
// tslint:disable-next-line:no-console
15-
console.error(e);
16-
process.exit(1);
17-
});
18-
19-
async function main() {
20-
const progname = path.basename(process.argv[1]);
21-
22-
const appletFile = process.argv[2];
23-
if (!appletFile) {
24-
throw new Error(`Usage: ${progname} <applet.yaml>`);
25-
}
26-
27-
// read applet(s) properties from the provided file
28-
const fileContents = YAML.parse(await fs.readFile(appletFile, { encoding: 'utf-8' }));
29-
if (typeof fileContents !== 'object') {
30-
throw new Error(`${appletFile}: should contain a YAML object`);
31-
}
32-
const appletMap = fileContents.applets;
33-
if (!appletMap) {
34-
throw new Error(`${appletFile}: must have an 'applets' key`);
35-
}
36-
37-
const searchDir = path.dirname(appletFile);
38-
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'cdkapplet'));
39-
try {
40-
const app = new cdk.App();
41-
42-
for (const [name, definition] of Object.entries(appletMap)) {
43-
await constructStack(app, searchDir, tempDir, name, definition);
44-
}
45-
app.run();
46-
} finally {
47-
await fs.remove(tempDir);
48-
}
49-
}
50-
51-
/**
52-
* Construct a stack from the given props
53-
* @param props Const
54-
*/
55-
async function constructStack(app: cdk.App, searchDir: string, tempDir: string, stackName: string, spec: any) {
56-
// the 'applet' attribute tells us how to load the applet. in the javascript case
57-
// it will be in the format <module>:<class> where <module> is technically passed to "require"
58-
// and <class> is expected to be exported from the module.
59-
const appletSpec: string | undefined = spec.type;
60-
if (!appletSpec) {
61-
throw new Error(`Applet ${stackName} missing "type" attribute`);
62-
}
63-
64-
const applet = parseApplet(appletSpec);
65-
66-
const props = spec.properties || {};
67-
68-
if (applet.npmPackage) {
69-
// tslint:disable-next-line:no-console
70-
console.error(`Installing NPM package ${applet.npmPackage}`);
71-
// Magic marker to download this package directly off of NPM
72-
// We're going to run NPM as a shell (since programmatic usage is not stable
73-
// by their own admission) and we're installing into a temporary directory.
74-
// (Installing into a permanent directory is useless since NPM doesn't do
75-
// any real caching anyway).
76-
child_process.execFileSync('npm', ['install', '--prefix', tempDir, '--global', applet.npmPackage], {
77-
stdio: 'inherit'
78-
});
79-
searchDir = path.join(tempDir, 'lib');
80-
}
81-
82-
// we need to resolve the module name relatively to where the applet file is
83-
// and not relative to this module or cwd.
84-
const modulePath = require.resolve(applet.moduleName, { paths: [ searchDir ] });
85-
86-
// load the module
87-
const pkg = require(modulePath);
88-
89-
// find the applet class within the package
90-
// tslint:disable-next-line:variable-name
91-
const appletConstructor = pkg[applet.className];
92-
if (!appletConstructor) {
93-
throw new Error(`Cannot find applet class "${applet.className}" in module "${applet.moduleName}"`);
94-
}
95-
96-
if (isStackConstructor(appletConstructor)) {
97-
// add the applet stack into the app.
98-
new appletConstructor(app, stackName, props);
99-
} else {
100-
// Make a stack THEN add it in
101-
const stack = new cdk.Stack(app, stackName, props);
102-
new appletConstructor(stack, 'Default', props);
103-
}
104-
}
2+
// tslint:disable-next-line:no-console
3+
console.error('applets are no longer supported. see: https://github.com/awslabs/aws-cdk/tree/master/packages/decdk');

Diff for: packages/@aws-cdk/applet-js/lib/applet-helpers.ts

-52
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/package.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@aws-cdk/applet-js",
33
"version": "0.32.0",
4+
"deprecated": "Applets have been deprecated in favor of 'decdk'",
45
"description": "Javascript CDK applet host program",
56
"main": "bin/cdk-applet-js.js",
67
"types": "bin/cdk-applet-js.d.ts",
@@ -25,16 +26,9 @@
2526
"license": "Apache-2.0",
2627
"devDependencies": {
2728
"@types/fs-extra": "^5.0.5",
28-
"@types/yaml": "^1.0.2",
2929
"cdk-build-tools": "^0.32.0",
3030
"pkglint": "^0.32.0"
3131
},
32-
"dependencies": {
33-
"@aws-cdk/cdk": "^0.32.0",
34-
"fs-extra": "^7.0.1",
35-
"source-map-support": "^0.5.12",
36-
"yaml": "^1.5.0"
37-
},
3832
"repository": {
3933
"url": "https://github.com/awslabs/aws-cdk.git",
4034
"type": "git",

Diff for: packages/@aws-cdk/applet-js/test/expected1.json

-35
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/expected2.json

-48
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/expected3.json

-7
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/manual-test-npm.yaml

-3
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/negative-test4.yaml

-4
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/negative-test5.yaml

-4
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/negative-test6.yaml

-4
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/negative-test7.yaml

-4
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/test-applet.ts

-44
This file was deleted.

Diff for: packages/@aws-cdk/applet-js/test/test-multistack-expected.json

-35
This file was deleted.

0 commit comments

Comments
 (0)