@aligent/nx-cdk 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/generators/helpers/configs/base-package/package.json +10 -27
- package/src/generators/preset/files/.gitignore.template +3 -3
- package/src/generators/preset/files/README.md.template +1 -21
- package/src/generators/preset/files/application/README.md.template +16 -6
- package/src/generators/preset/files/libs/infra/src/index.ts.template +3 -22
- package/src/generators/preset/files-example/libs/infra/src/index.ts.template +49 -0
- package/src/generators/preset/preset.js +6 -2
- package/src/generators/preset/schema.json +2 -1
- package/src/generators/service/files/src/index.ts.template +1 -3
- package/src/generators/service/files-example/src/index.ts.template +45 -0
- package/src/generators/service/files-example/src/infra/stepfunctions/example.yml.template +7 -0
- package/src/generators/service/files-example/src/runtime/handlers/example.ts.template +7 -0
- package/src/generators/service/generator.js +6 -2
- package/src/generators/service/schema.d.ts +1 -0
- package/src/generators/service/schema.json +6 -0
- package/src/generators/preset/files/.github/dependabot.yml.template +0 -7
- package/src/generators/preset/files/parameters/dev.csv.template +0 -2
package/package.json
CHANGED
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"@aligent/microservice-util-lib": "^1.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@aligent/cdk-aspects": "^0.5.
|
|
25
|
-
"@aligent/cdk-
|
|
26
|
-
"@aligent/
|
|
27
|
-
"@aligent/
|
|
24
|
+
"@aligent/cdk-aspects": "^0.5.5",
|
|
25
|
+
"@aligent/cdk-nodejs-function-from-entry": "^0.2.1",
|
|
26
|
+
"@aligent/cdk-step-function-from-file": "^0.5.1",
|
|
27
|
+
"@aligent/nx-openapi": "^2.2.1",
|
|
28
|
+
"@aligent/ts-code-standards": "^4.2.1",
|
|
28
29
|
"@nx/eslint": "22.1.3",
|
|
29
30
|
"@nx/eslint-plugin": "22.1.3",
|
|
30
31
|
"@nx/js": "22.1.3",
|
|
@@ -39,10 +40,10 @@
|
|
|
39
40
|
"@typescript-eslint/parser": "8.44.0",
|
|
40
41
|
"@vitest/coverage-v8": "^3.2.4",
|
|
41
42
|
"@vitest/ui": "^3.2.4",
|
|
42
|
-
"aws-cdk": "^2.
|
|
43
|
-
"aws-cdk-lib": "^2.
|
|
44
|
-
"cdk-nag": "^2.
|
|
45
|
-
"constructs": "^10.
|
|
43
|
+
"aws-cdk": "^2.1120.0",
|
|
44
|
+
"aws-cdk-lib": "^2.251.0",
|
|
45
|
+
"cdk-nag": "^2.38.2",
|
|
46
|
+
"constructs": "^10.6.0",
|
|
46
47
|
"eslint": "^9.32.0",
|
|
47
48
|
"eslint-config-prettier": "^10.1.8",
|
|
48
49
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -52,7 +53,6 @@
|
|
|
52
53
|
"nx": "22.1.3",
|
|
53
54
|
"prettier": "^3.6.2",
|
|
54
55
|
"rolldown": "1.0.0-rc.1",
|
|
55
|
-
"store-parameters": "^1.1.3",
|
|
56
56
|
"tslib": "^2.8.1",
|
|
57
57
|
"tsx": "^4.21.0",
|
|
58
58
|
"typescript": "~5.9.2",
|
|
@@ -60,24 +60,7 @@
|
|
|
60
60
|
"vitest": "^3.2.4"
|
|
61
61
|
},
|
|
62
62
|
"nx": {
|
|
63
|
-
"includedScripts": []
|
|
64
|
-
"targets": {
|
|
65
|
-
"parameters": {
|
|
66
|
-
"executor": "nx:run-commands",
|
|
67
|
-
"options": {
|
|
68
|
-
"color": true,
|
|
69
|
-
"cwd": "parameters"
|
|
70
|
-
},
|
|
71
|
-
"configurations": {
|
|
72
|
-
"import": {
|
|
73
|
-
"command": "store-parameters import {args.file} --delimiter=|"
|
|
74
|
-
},
|
|
75
|
-
"export": {
|
|
76
|
-
"command": "store-parameters export {args.file} --path={args.path} --delimiter=|"
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
63
|
+
"includedScripts": []
|
|
81
64
|
},
|
|
82
65
|
"workspaces": [
|
|
83
66
|
"application",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
!collection
|
|
44
44
|
!collection/*
|
|
45
45
|
!collection/**/*
|
|
46
|
+
!clients
|
|
47
|
+
!clients/*
|
|
48
|
+
!clients/**/*
|
|
46
49
|
!docs
|
|
47
50
|
!docs/*
|
|
48
51
|
!docs/**/*
|
|
49
52
|
!libs
|
|
50
53
|
!libs/*
|
|
51
54
|
!libs/**/*
|
|
52
|
-
!parameters
|
|
53
|
-
!parameters/*
|
|
54
|
-
!parameters/**/*
|
|
55
55
|
!services
|
|
56
56
|
!services/*
|
|
57
57
|
!services/**/*
|
|
@@ -53,15 +53,6 @@ yarn install
|
|
|
53
53
|
Before committing this repository, review and update the following generated defaults:
|
|
54
54
|
|
|
55
55
|
- **`.github/CODEOWNERS`** — The default file references Aligent's GitHub teams (`@aligent/microservices`, `@aligent/devops`). Replace these with your own organisation's team handles.
|
|
56
|
-
- **`package.json` `pg:*` scripts** — The playground scripts use `--profile playground`. Ensure you have a matching profile in your `~/.aws/config` file:
|
|
57
|
-
|
|
58
|
-
```ini
|
|
59
|
-
[profile playground]
|
|
60
|
-
source_profile = default
|
|
61
|
-
role_arn = arn:aws:iam::11111111111:role/RoleName
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
If your profile has a different name, update the `pg:*` scripts in the root `package.json` to match.
|
|
65
56
|
|
|
66
57
|
### Deployment
|
|
67
58
|
|
|
@@ -89,18 +80,7 @@ To add a new service to the monorepo:
|
|
|
89
80
|
- `services/{service-name}/src/index.ts`
|
|
90
81
|
- `services/{service-name}/src/infra/`
|
|
91
82
|
3. Add Lambda handlers in `services/{service-name}/src/runtime/handlers/`
|
|
92
|
-
|
|
93
|
-
## Environment Parameters Management
|
|
94
|
-
|
|
95
|
-
Parameters are managed through the `parameters/{env}.csv` file by default
|
|
96
|
-
|
|
97
|
-
```bash
|
|
98
|
-
# Import values from `parameters/{env}.csv` to Parameter Store in AWS
|
|
99
|
-
yarn nx run <%= name %>-int:parameters:import --file=dev.csv
|
|
100
|
-
|
|
101
|
-
# Custom filename and parameter path can be passed in as arguments
|
|
102
|
-
yarn nx run <%= name %>-int:parameters:export --file=dev.csv --path=/my/dev/path
|
|
103
|
-
```
|
|
83
|
+
4. Run `yarn install` again so Yarn Workspace get synced.
|
|
104
84
|
|
|
105
85
|
## License
|
|
106
86
|
|
|
@@ -6,11 +6,21 @@ This application manages the deployment of microservices and their shared infras
|
|
|
6
6
|
|
|
7
7
|
### Using yarn script from workspace root (Recommended)
|
|
8
8
|
|
|
9
|
+
**The `pg:*` scripts** — The playground scripts use `--profile playground`. Ensure you have a matching profile in your `~/.aws/config` file:
|
|
10
|
+
|
|
11
|
+
```ini
|
|
12
|
+
[profile playground]
|
|
13
|
+
source_profile = default
|
|
14
|
+
role_arn = arn:aws:iam::11111111111:role/RoleName
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If your profile has a different name, update the `pg:*` scripts in the root `package.json` to match.
|
|
18
|
+
|
|
9
19
|
##### Synthesize
|
|
10
20
|
|
|
11
21
|
```bash
|
|
12
22
|
# Synthesize for default environment/stage (dev)
|
|
13
|
-
yarn pg:synth
|
|
23
|
+
yarn pg:synth --args="dev/**"
|
|
14
24
|
|
|
15
25
|
# Synthesize for a custom environment/stage
|
|
16
26
|
yarn pg:synth --args="plg/** -c environment=plg"
|
|
@@ -20,7 +30,7 @@ yarn pg:synth --args="plg/** -c environment=plg"
|
|
|
20
30
|
|
|
21
31
|
```bash
|
|
22
32
|
# Deploy for default environment/stage (dev)
|
|
23
|
-
yarn pg:deploy
|
|
33
|
+
yarn pg:deploy --args="dev/**"
|
|
24
34
|
|
|
25
35
|
# Deploy to a custom environment/stage
|
|
26
36
|
yarn pg:deploy --args="plg/** -c environment=plg"
|
|
@@ -30,20 +40,20 @@ yarn pg:deploy --args="plg/** -c environment=plg"
|
|
|
30
40
|
|
|
31
41
|
```bash
|
|
32
42
|
# Diff checking for default environment/stage (dev)
|
|
33
|
-
yarn pg:diff
|
|
43
|
+
yarn pg:diff --args="dev/**"
|
|
34
44
|
|
|
35
45
|
# Diff checking for a custom environment/stage
|
|
36
|
-
yarn pg:diff --args="-c environment=plg"
|
|
46
|
+
yarn pg:diff --args="plg/** -c environment=plg"
|
|
37
47
|
```
|
|
38
48
|
|
|
39
49
|
##### Destroy
|
|
40
50
|
|
|
41
51
|
```bash
|
|
42
52
|
# Destroy default environment/stage (dev)
|
|
43
|
-
yarn pg:destroy
|
|
53
|
+
yarn pg:destroy --args="dev/**"
|
|
44
54
|
|
|
45
55
|
# Destroy a custom environment/stage
|
|
46
|
-
yarn pg:destroy --args="-c environment=plg"
|
|
56
|
+
yarn pg:destroy --args="plg/** -c environment=plg"
|
|
47
57
|
```
|
|
48
58
|
|
|
49
59
|
### Direct Nx Commands
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Stack, Stage, StackProps, Tags } from 'aws-cdk-lib';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
|
-
<% if (example) { %>import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
|
|
4
|
-
import { IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';<% } %>
|
|
5
3
|
|
|
6
4
|
export interface SharedInfraProps {
|
|
7
|
-
|
|
8
|
-
secretExample: Secret;<% } %>
|
|
5
|
+
// TODO: Add shared infrastructure properties (e.g. SSM parameters, secrets)
|
|
9
6
|
}
|
|
10
7
|
|
|
11
8
|
export class SharedInfraStack extends Stack {
|
|
12
|
-
|
|
13
|
-
readonly secretExample: Secret;<% } %>
|
|
9
|
+
// TODO: Add readonly properties for shared resources
|
|
14
10
|
|
|
15
11
|
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
16
12
|
super(scope, id, props);
|
|
@@ -20,24 +16,9 @@ export class SharedInfraStack extends Stack {
|
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
Tags.of(this).add('SERVICE', id);
|
|
23
|
-
<% if (example) { %>
|
|
24
|
-
this.paramExample = StringParameter.fromStringParameterName(
|
|
25
|
-
this,
|
|
26
|
-
'ParamExample',
|
|
27
|
-
`/example/param`
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
this.secretExample = new Secret(this, 'SecretExample', {
|
|
31
|
-
description: 'Example secret shared across services',
|
|
32
|
-
});
|
|
33
|
-
<% } %>
|
|
34
19
|
}
|
|
35
20
|
|
|
36
21
|
getProps(): SharedInfraProps {
|
|
37
|
-
return {
|
|
38
|
-
<% if (example) { %>paramExample: this.paramExample,
|
|
39
|
-
secretExample: this.secretExample,
|
|
40
|
-
<% } %>
|
|
41
|
-
};
|
|
22
|
+
return {};
|
|
42
23
|
}
|
|
43
24
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Stack, Stage, StackProps, Tags } from 'aws-cdk-lib';
|
|
2
|
+
import { Construct } from 'constructs';
|
|
3
|
+
import { Secret } from 'aws-cdk-lib/aws-secretsmanager';
|
|
4
|
+
import { IStringParameter, StringParameter } from 'aws-cdk-lib/aws-ssm';
|
|
5
|
+
|
|
6
|
+
export interface SharedInfraProps {
|
|
7
|
+
paramExample: IStringParameter;
|
|
8
|
+
secretExample: Secret;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class SharedInfraStack extends Stack {
|
|
12
|
+
readonly paramExample: IStringParameter;
|
|
13
|
+
readonly secretExample: Secret;
|
|
14
|
+
|
|
15
|
+
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
16
|
+
super(scope, id, props);
|
|
17
|
+
|
|
18
|
+
if (!Stage.of(this)?.stageName) {
|
|
19
|
+
throw new Error('This construct must be used within a CDK Stage');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Tags.of(this).add('SERVICE', id);
|
|
23
|
+
|
|
24
|
+
this.paramExample = new StringParameter(this,'ParamExample',
|
|
25
|
+
{
|
|
26
|
+
parameterName: `/example/param`,
|
|
27
|
+
stringValue: 'example-value'
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
this.secretExample = new Secret(this, 'SecretExample', {
|
|
32
|
+
description: 'Example secret shared across services',
|
|
33
|
+
generateSecretString: {
|
|
34
|
+
secretStringTemplate: JSON.stringify({
|
|
35
|
+
username: 'placeholder',
|
|
36
|
+
password: 'placeholder',
|
|
37
|
+
}),
|
|
38
|
+
generateStringKey: '_generatedKey',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getProps(): SharedInfraProps {
|
|
44
|
+
return {
|
|
45
|
+
paramExample: this.paramExample,
|
|
46
|
+
secretExample: this.secretExample,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -10,13 +10,17 @@ async function presetGenerator(tree, options) {
|
|
|
10
10
|
const [nodeVersionMajor] = nodeVersion.split('.');
|
|
11
11
|
const nameParts = (0, utilities_1.splitInputName)(name);
|
|
12
12
|
const projectName = nameParts.join(' ');
|
|
13
|
-
|
|
13
|
+
const templateVars = {
|
|
14
14
|
...options,
|
|
15
15
|
projectName,
|
|
16
16
|
folderName: destination || name,
|
|
17
17
|
nodeRuntime: `${nodeVersionMajor}_X`,
|
|
18
18
|
template: '',
|
|
19
|
-
}
|
|
19
|
+
};
|
|
20
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), '.', templateVars);
|
|
21
|
+
if (options.example) {
|
|
22
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files-example'), '.', templateVars);
|
|
23
|
+
}
|
|
20
24
|
(0, devkit_1.updateNxJson)(tree, { ...nxJson_1.NX_JSON });
|
|
21
25
|
const packageJson = (0, utilities_1.constructPackageJsonFile)({
|
|
22
26
|
name: options.name,
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"example": {
|
|
37
37
|
"type": "boolean",
|
|
38
38
|
"description": "Generate example code with sample resources",
|
|
39
|
-
"default": false
|
|
39
|
+
"default": false,
|
|
40
|
+
"x-prompt": "Would you like to generate example code with sample resources?"
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
"required": ["name"]
|
|
@@ -20,8 +20,6 @@ interface Props extends StackProps, SharedInfraProps {
|
|
|
20
20
|
/**
|
|
21
21
|
* Entrypoint for the <%= name %> service
|
|
22
22
|
*
|
|
23
|
-
* Instantiate in a CDK Application Stage to deploy to AWS.
|
|
24
|
-
*
|
|
25
23
|
* @note Aligent provides the following standard CDK constructs:
|
|
26
24
|
* - {@link NodejsFunctionFromEntry} from '@aligent/cdk-nodejs-function-from-entry'
|
|
27
25
|
* - {@link StepFunctionFromFile} from '@aligent/cdk-step-function-from-file'
|
|
@@ -34,7 +32,7 @@ interface Props extends StackProps, SharedInfraProps {
|
|
|
34
32
|
*
|
|
35
33
|
* new StepFunctionFromFile(this, 'ExampleStepFunction', {
|
|
36
34
|
* baseDir: import.meta.dirname,
|
|
37
|
-
* filepath: 'infra/stepfunctions/example.
|
|
35
|
+
* filepath: 'infra/stepfunctions/example.yml',
|
|
38
36
|
* });
|
|
39
37
|
*/
|
|
40
38
|
export class <%= stack %> extends Stack {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SharedInfraProps } from '@libs/infra';
|
|
2
|
+
import { Stack, StackProps, Stage, Tags } from 'aws-cdk-lib';
|
|
3
|
+
import { Construct } from 'constructs';
|
|
4
|
+
import { NodejsFunctionFromEntry } from '@aligent/cdk-nodejs-function-from-entry';
|
|
5
|
+
import { StepFunctionFromFile } from '@aligent/cdk-step-function-from-file';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @important
|
|
9
|
+
* Due to the immutable nature of CloudFormation,
|
|
10
|
+
* CDK will generate new CloudFormation template and deploy if you change stack name
|
|
11
|
+
*/
|
|
12
|
+
export const <%= constant %> = {
|
|
13
|
+
NAME: '<%= name %>',
|
|
14
|
+
DESCRIPTION: '<%= name %> service description'
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
type Id = typeof <%= constant %>.NAME | (string & {});
|
|
18
|
+
interface Props extends StackProps, SharedInfraProps {
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Entrypoint for the <%= name %> service
|
|
24
|
+
*/
|
|
25
|
+
export class <%= stack %> extends Stack {
|
|
26
|
+
constructor(scope: Construct, id: Id, props: Props) {
|
|
27
|
+
super(scope, id, props);
|
|
28
|
+
|
|
29
|
+
if (!Stage.of(this)?.stageName) {
|
|
30
|
+
throw new Error('This construct must be used within a CDK Stage');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Tags.of(this).add('SERVICE', id);
|
|
34
|
+
|
|
35
|
+
new NodejsFunctionFromEntry(this, 'ExampleLambda', {
|
|
36
|
+
baseDir: import.meta.dirname,
|
|
37
|
+
entry: 'runtime/handlers/example.ts',
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
new StepFunctionFromFile(this, 'ExampleStepFunction', {
|
|
41
|
+
baseDir: import.meta.dirname,
|
|
42
|
+
filepath: 'infra/stepfunctions/example.yml',
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -23,13 +23,17 @@ async function serviceGenerator(tree, options) {
|
|
|
23
23
|
if (!tree.exists(SERVICES_FOLDER)) {
|
|
24
24
|
tree.write(`${SERVICES_FOLDER}/.gitkeep`, '');
|
|
25
25
|
}
|
|
26
|
-
|
|
26
|
+
const templateVars = {
|
|
27
27
|
...options,
|
|
28
28
|
serviceName: nameParts.join(' '),
|
|
29
29
|
constant,
|
|
30
30
|
stack,
|
|
31
31
|
template: '',
|
|
32
|
-
}
|
|
32
|
+
};
|
|
33
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files'), projectRoot, templateVars);
|
|
34
|
+
if (options.example) {
|
|
35
|
+
(0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, 'files-example'), projectRoot, templateVars);
|
|
36
|
+
}
|
|
33
37
|
// Generate service's tsconfigs
|
|
34
38
|
const { tsConfig, tsConfigLib, tsConfigSpec } = (0, utilities_1.constructProjectTsConfigFiles)('service');
|
|
35
39
|
(0, devkit_1.writeJson)(tree, `${projectRoot}/tsconfig.json`, tsConfig);
|
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
"x-prompt": "What is the name of the service?",
|
|
15
15
|
"pattern": "^(?!.*[Ss]tack|.*[Ss]ervice).*$",
|
|
16
16
|
"patternErrorMessage": "Service name cannot contain '[Ss]tack' or '[Ss]ervice'"
|
|
17
|
+
},
|
|
18
|
+
"example": {
|
|
19
|
+
"type": "boolean",
|
|
20
|
+
"description": "Generate example code with sample resources",
|
|
21
|
+
"default": false,
|
|
22
|
+
"x-prompt": "Would you like to generate example code with sample resources?"
|
|
17
23
|
}
|
|
18
24
|
},
|
|
19
25
|
"required": ["name"]
|