Skip to content

Commit a2c633f

Browse files
authored
chore: remodel the aws-cdk repo to support v2 development only (#24376)
Restructures the repository to reflect the current state of package publishing. Combines all of the stable packages within @aws-cdk/* namespace into aws-cdk-lib, and separates the unstable portions of the alpha modules into their own packages depending on `aws-cdk-lib` for their L1s. Changes how code generation works to run during the build of `aws-cdk-lib` and new cloudformation resources are added automatically when the spec is updated. Removed all of the integration tests and put them into their own package to avoid cyclic dependencies. Integ tests for alpha packages remain with their package source. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5003cad commit a2c633f

File tree

14,321 files changed

+263845
-345706
lines changed

Some content is hidden

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

14,321 files changed

+263845
-345706
lines changed

CONTRIBUTING.md

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,35 @@ The CDK uses [jsii](https://github.com/aws/jsii/) as its primary build system. j
8888
typescript-compliant source code and produce polyglot libraries, such as, in Java, .NET, Python and Go.
8989

9090
The repo contains `packages/` directory that contains the CDK public modules. The source code for the IAM module in the
91-
CDK can be found at the location `packages/@aws-cdk/aws-iam`.
91+
CDK can be found at the location `packages/aws-cdk-lib/aws-iam`.
9292
The repo also contains the `tools/` directory that holds custom build tooling (modeled as private npm packages)
9393
specific to the CDK.
9494

9595
### Build
9696

97-
The full build of the CDK takes a long time to complete; 1-2 hours depending on the performance of the build machine.
98-
However, most first time contributions will require changing only one CDK module, sometimes two. A full build of the
99-
CDK is not required in these cases.
100-
101-
If you want to work on the `@aws-cdk/aws-ec2` module, the following command will build just the EC2 module and any
102-
necessary dependencies.
97+
The full build of all of the packages within the repository can take a few minutes, about 20 when all tests are run.
98+
Most contributions only require working on a single package, usually `aws-cdk-lib`. To build this package for the first
99+
time, you can execute the following to build it and it's dependencies.
103100

104101
```console
105-
$ cd packages/@aws-cdk/aws-ec2
102+
$ cd packages/aws-cdk-lib
106103
$ ../../../scripts/buildup
107104
```
108105

109106
Note: The `buildup` command is resumable. If your build fails, you can fix the issue and run `buildup --resume` to
110107
resume.
111108

112-
At this point, you can run build and test the `aws-ec2` module by running
109+
At this point, you can run build and test the `aws-cdk-lib` module by running
113110

114111
```console
115-
$ cd packages/@aws-cdk/aws-ec2
112+
$ cd packages/aws-cdk-lib
116113
$ yarn build
117114
$ yarn test
118115
```
119116

117+
To cut down on iteration time as you develop, you can run `yarn watch` within the `aws-cdk-lib` directory to keep
118+
some of the build state in memory and incrementally rebuild as you make changes.
119+
120120
However, if you wish to build the entire repository, the following command will achieve this.
121121

122122
```console
@@ -137,12 +137,12 @@ Packing involves generating CDK code in the various target languages and packagi
137137
respective package managers. Once in a while, these will need to be generated either to test the experience of a new
138138
feature, or reproduce a packaging failure.
139139

140-
To package a specific module, say the `@aws-cdk/aws-ec2` module:
140+
To package a specific module, say the `aws-cdk-lib` module:
141141

142142
```console
143143
$ cd <root-of-cdk-repo>
144144
$ docker run --rm --net=host -it -v $PWD:$PWD -w $PWD jsii/superchain:1-buster-slim
145-
docker$ cd packages/@aws-cdk/aws-ec2
145+
docker$ cd packages/aws-cdk-lib
146146
docker$ ../../../scripts/foreach.sh --up yarn run package
147147
docker$ exit
148148
```
@@ -317,12 +317,12 @@ CDK integration tests.
317317
We've added a watch feature to the CDK that builds your code as you type it. Start this by running `yarn watch` for
318318
each module that you are modifying.
319319

320-
For example, watch the EC2 and IAM modules in a second terminal session:
320+
For example, watch the aws-cdk-lib and aws-cdk modules in a second terminal session:
321321

322322
```console
323-
$ cd packages/@aws-cdk/aws-ec2
323+
$ cd packages/aws-cdk-lib
324324
$ yarn watch & # runs in the background
325-
$ cd packages/@aws-cdk/aws-iam
325+
$ cd packages/aws-cdk
326326
$ yarn watch & # runs in the background
327327
```
328328

@@ -637,10 +637,10 @@ The README file contains code snippets written as typescript code. Code snippets
637637
(such as `` ```ts ``) will be automatically extracted, compiled and translated to other languages when the
638638
during the [pack](#pack) step. We call this feature 'rosetta'.
639639

640-
You can run rosetta on the EC2 module (or any other module) by running:
640+
You can run rosetta on the aws-cdk-lib module (or any other module) by running:
641641

642642
```console
643-
$ cd packages/@aws-cdk/aws-ec2
643+
$ cd packages/aws-cdk-lib
644644
$ yarn rosetta:extract --strict
645645
```
646646

@@ -696,14 +696,14 @@ cases where some of those do not apply - good judgement is to be applied):
696696
- Types from the documented module should be **un-qualified**:
697697

698698
```ts
699-
// An example in the @aws-cdk/core library, which defines Duration
699+
// An example in the aws-cdk-lib library, which defines Duration
700700
Duration.minutes(15);
701701
```
702702

703703
- Types from other modules should be **qualified**:
704704

705705
```ts
706-
// An example in the @aws-cdk/core library, using something from @aws-cdk/aws-s3
706+
// An example in the aws-cdk-lib library, using something from aws-cdk-lib/aws-s3
707707
const bucket = new s3.Bucket(this, 'Bucket');
708708
// ...rest of the example...
709709
```
@@ -712,7 +712,7 @@ cases where some of those do not apply - good judgement is to be applied):
712712
necessary for compilation but unimportant to the example:
713713

714714
```ts
715-
// An example about adding a stage to a pipeline in the @aws-cdk/pipelines library
715+
// An example about adding a stage to a pipeline in the aws-cdk-lib/pipelines library
716716
declare const pipeline: pipelines.CodePipeline;
717717
declare const myStage: Stage;
718718
pipeline.addStage(myStage);
@@ -766,7 +766,7 @@ Consequently, there are two useful scripts that are built on top of `foreach.sh`
766766
All linters are executed automatically as part of the build script, `yarn build`.
767767

768768
They can also be executed independently of the build script. From the root of a specific package (e.g.
769-
`packages/@aws-cdk/aws-ec2`), run the following command to execute all the linters on that package -
769+
`packages/aws-cdk-lib`), run the following command to execute all the linters on that package -
770770

771771
```bash
772772
yarn lint
@@ -878,88 +878,24 @@ $ cdk -a some.app.js synth | $awscdk/scripts/template-deps-to-dot | dot -Tpng >
878878

879879
You can use `find-cycles` to print a list of internal dependency cycles:
880880

881-
```shell
882-
$ scripts/find-cycles.sh
883-
Cycle: @aws-cdk/aws-iam => @aws-cdk/assert => aws-cdk => @aws-cdk/aws-s3 => @aws-cdk/aws-kms => @aws-cdk/aws-iam
884-
Cycle: @aws-cdk/assert => aws-cdk => @aws-cdk/aws-s3 => @aws-cdk/aws-kms => @aws-cdk/assert
885-
Cycle: @aws-cdk/aws-iam => @aws-cdk/assert => aws-cdk => @aws-cdk/aws-s3 => @aws-cdk/aws-iam
886-
Cycle: @aws-cdk/assert => aws-cdk => @aws-cdk/aws-s3 => @aws-cdk/assert
887-
Cycle: @aws-cdk/assert => aws-cdk => @aws-cdk/aws-cloudformation => @aws-cdk/assert
888-
Cycle: @aws-cdk/aws-iam => @aws-cdk/assert => aws-cdk => @aws-cdk/util => @aws-cdk/aws-iam
889-
Cycle: @aws-cdk/aws-sns => @aws-cdk/aws-lambda => @aws-cdk/aws-codecommit => @aws-cdk/aws-sns
890-
Cycle: @aws-cdk/aws-sns => @aws-cdk/aws-lambda => @aws-cdk/aws-codecommit => @aws-cdk/aws-codepipeline => @aws-cdk/aws-sns
891-
```
892-
893881
## Running CLI integration tests
894882

895883
The CLI package (`packages/aws-cdk`) has some integration tests that aren't
896884
run as part of the regular build, since they have some particular requirements.
897885
See the [CLI CONTRIBUTING.md file](packages/aws-cdk/CONTRIBUTING.md) for
898886
more information on running those tests.
899887

900-
## Building aws-cdk-lib
901-
902-
In AWS CDK v2, all stable libraries are packaged into a single monolithic
903-
package and published as `aws-cdk-lib`. In most cases, you can iterate on a
904-
single module's directory as previously described in this document (e.g.
905-
`packages/@aws-cdk/aws-s3`). In some cases, you might need to build
906-
`aws-cdk-lib`:
907-
908-
```
909-
# Generate all of the L1s first. If you have already done a full build in the repository, you can skip this.
910-
cd <CDK repo root>/
911-
./scripts/gen.sh
912-
913-
# Generate and build `aws-cdk-lib`
914-
cd packages/aws-cdk-lib
915-
yarn build
916-
```
917-
918-
The commands above perform the following steps:
919-
1. Run `yarn install` to install all dependencies
920-
2. Generate `.generated.ts` files in each `packages/@aws-cdk/aws-<service>`
921-
directory. These files contain TypeScript source code for all of the L1 (Cfn)
922-
Constructs, and are generated from the [CloudFormation Resource
923-
Specification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-resource-specification.html).
924-
3. Copy the `.ts` source code files from each `packages/@aws-cdk/aws-<service>`
925-
directory to the corresponding `packages/aws-cdk-lib/aws-<service>`
926-
directory.
927-
4. Compile `aws-cdk-lib`.
928-
929-
Running unit tests and integration tests still has to be performed in each
930-
module's `packages/@aws-cdk` directory.
931-
932888
## Building and testing v2 -alpha packages
933889

934-
In AWS CDK v2, all experimental libraries are published separately with an
935-
-alpha suffix. In most cases, you can iterate on a single module's directory as
936-
already described in this document (e.g. `packages/@aws-cdk/aws-amplify`). If
937-
you need to generate and iterate on the alpha package, here are the steps. The
938-
main differences between the alpha package is naming of the package, and import
939-
statements.
940-
941-
First, make sure the following packages are built:
942-
- packages/@aws-cdk/assert
943-
- packages/aws-cdk-lib
944-
- tools/individual-pkg-gen
945-
946-
The following command will create all of the alpha packages by copying files
947-
from their source directories under `packages/@aws-cdk/aws-<service>`, and it
948-
will build and run unit tests for all of them. This is sometimes too much for a
949-
developer machine or laptop.
890+
Modules that are not stable are vended separately from `aws-cdk-lib`. These packages are found in the
891+
`packages/@aws-cdk` directory and are marked `stability: 'experimental'` in their package.json files.
892+
This means they will be given the `alpha` version from the `version.v2.json` when published and they
893+
cannot be taken as dependencies by `aws-cdk-lib`
950894

951-
```
952-
<CDK repo root>/scripts/transform.sh
953-
```
954-
955-
To only copy and transform the source files, and then build and test one
956-
alpha package at a time, use the following:
895+
Experimental packages are used to develop new constructs and experiment with their APIs before marking
896+
them as stable and including them within `aws-cdk-lib`. Once they are included in `aws-cdk-lib`, no
897+
more breaking api changes can be made.
957898

958-
```
959-
<CDK repo root>/scripts/transform.sh --skip-build
960-
cd packages/individual-packages/aws-<service>
961-
yarn build+test
962-
```
963899
## Changing Cloud Assembly Schema
964900

965901
If you plan on making changes to the `cloud-assembly-schema` package, make sure you familiarize yourself with

buildspec-pr.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ phases:
2525
build:
2626
commands:
2727
- /bin/bash ./build.sh
28-
- /bin/bash ./scripts/transform.sh
2928
# After compilation, run Rosetta (using the cache if available).
3029
# This will print errors, and fail the build if there are compilation errors in any packages marked as 'strict'.
3130
- /bin/bash ./scripts/run-rosetta.sh

buildspec-remodel.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: 0.2
2+
3+
env:
4+
secrets-manager:
5+
TOKEN: $TOKEN_SECRET_ARN
6+
variables:
7+
NODE_OPTIONS: --max_old_space_size=8192
8+
9+
phases:
10+
install:
11+
commands:
12+
# CodeBuild always runs as root, allow npm to operate as such
13+
- npm config set unsafe-perm true
14+
- mkdir ${HOME}/aws-cdk && cd ${HOME}/aws-cdk
15+
# Configure git and git credentials
16+
- git config --global user.email "${COMMIT_EMAIL}"
17+
- git config --global user.name "${COMMIT_USERNAME}"
18+
- echo "Retrieving gh token from secretsmanager"
19+
- git clone https://[email protected]/aws/aws-cdk -b feat/repo-restructure .
20+
- git checkout ${CODEBUILD_RESOLVED_SOURCE_VERSION}
21+
# Install yarn if it wasn't already present in the image
22+
- yarn --version || npm -g install yarn
23+
- yarn install --frozen-lockfile
24+
- /sbin/sysctl -w vm.max_map_count=2251954
25+
build:
26+
commands:
27+
- cd ${HOME}/aws-cdk
28+
- npx lerna run build --scope @aws-cdk/remodel --include-dependencies
29+
- npx remodel ${PWD} --tmp-dir ${HOME}/remodel --no-clean --dry-run
30+
post_build:
31+
commands:
32+
- cd ${HOME}/remodel
33+
- git add -A
34+
- git commit -m "Execute remodel"
35+
- git remote add aws-cdk https://[email protected]/aws/aws-cdk
36+
- git fetch aws-cdk
37+
- git push aws-cdk +feat/repo-restructure:feat/remodel
38+
artifacts:
39+
files:
40+
- "**/*"
41+
base-directory: ${HOME}/remodel

buildspec.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ phases:
2727
- 'if ${BUMP_CANDIDATE:-false}; then /bin/bash ./scripts/bump-candidate.sh; fi'
2828
- /bin/bash ./scripts/align-version.sh
2929
- /bin/bash ./build.sh
30-
- /bin/bash ./scripts/transform.sh
3130
post_build:
3231
commands:
3332
# Short-circuit: Don't run pack if the above build failed.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const baseConfig = require('../../../tools/@aws-cdk/cdk-build-tools/config/eslintrc');
2+
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
3+
module.exports = {
4+
...baseConfig,
5+
ignorePatterns: [
6+
...baseConfig.ignorePatterns,
7+
'**/*.snapshot/**/*'
8+
],
9+
rules: {
10+
...baseConfig.rules,
11+
'import/order': 'off',
12+
}
13+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.LAST_BUILD
3+
*.snk
4+
junit.xml
5+
!.eslintrc.js
6+
.nyc_output
7+
coverage
8+
nyc.config.js
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
.LAST_BUILD
3+
*.snk
4+
junit.xml
5+
.eslintrc.js
6+
# exclude cdk artifacts
7+
**/cdk.out
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
AWS Cloud Development Kit (AWS CDK)
2+
Copyright 2018-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
Third party attributions of this package can be found in the THIRD_PARTY_LICENSES file
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@aws-cdk-testing/framework-integ",
3+
"description": "Integration tests for aws-cdk-lib",
4+
"private": true,
5+
"version": "0.0.0",
6+
"scripts": {
7+
"build": "cdk-build",
8+
"watch": "cdk-watch",
9+
"lint": "cdk-lint",
10+
"pkglint": "pkglint -f",
11+
"test": "cdk-test",
12+
"package": "cdk-package",
13+
"build+test": "yarn build && yarn test",
14+
"build+extract": "yarn build",
15+
"build+test+package": "yarn build+test && yarn package",
16+
"build+test+extract": "yarn build+test"
17+
},
18+
"pkglint": {
19+
"exclude": [
20+
"package-info/repository",
21+
"dependencies/cdk-point-dependencies"
22+
]
23+
},
24+
"author": {
25+
"name": "Amazon Web Services",
26+
"url": "https://aws.amazon.com",
27+
"organization": true
28+
},
29+
"license": "Apache-2.0",
30+
"devDependencies": {
31+
"@aws-cdk/cdk-build-tools": "0.0.0",
32+
"delay": "5.0.0",
33+
"@aws-cdk/pkglint": "0.0.0"
34+
},
35+
"dependencies": {
36+
"@aws-cdk/lambda-layer-kubectl-v24": "^2.0.100",
37+
"aws-cdk-lib": "0.0.0",
38+
"aws-sdk": "^2.1317.0",
39+
"aws-sdk-mock": "5.6.0",
40+
"cdk8s": "^2.7.15",
41+
"cdk8s-plus-24": "2.4.40",
42+
"constructs": "^10.0.0",
43+
"@aws-cdk/integ-tests-alpha": "0.0.0"
44+
},
45+
"repository": {
46+
"url": "https://github.com/aws/aws-cdk.git",
47+
"type": "git",
48+
"directory": "packages/@aws-cdk-testing/framework-integ"
49+
},
50+
"keywords": [
51+
"aws",
52+
"cdk"
53+
],
54+
"homepage": "https://github.com/aws/aws-cdk",
55+
"engines": {
56+
"node": ">= 14.15.0"
57+
},
58+
"stability": "experimental",
59+
"maturity": "experimental",
60+
"publishConfig": {
61+
"tag": "latest"
62+
}
63+
}

0 commit comments

Comments
 (0)