-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Elad Ben-Israel
authored
May 29, 2019
1 parent
9a48b66
commit c52bcfc
Showing
155 changed files
with
7,371 additions
and
2,583 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ coverage/ | |
# CDK Context & Staging files | ||
cdk.context.json | ||
.cdk.staging/ | ||
cdk.out/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
packages/@aws-cdk/applet-js/test/test-multistack-expected.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.