@aligent/nx-cdk 0.0.1 → 0.1.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/README.md +4 -4
- package/generators.json +1 -1
- package/package.json +1 -1
- package/src/generators/helpers/configs/nxJson.js +7 -17
- package/src/generators/helpers/configs/packageJson.d.ts +27 -5
- package/src/generators/helpers/configs/packageJson.js +22 -5
- package/src/generators/helpers/configs/tsConfigs.js +3 -3
- package/src/generators/helpers/utilities.d.ts +24 -3
- package/src/generators/helpers/utilities.js +7 -4
- package/src/generators/preset/files/.github/workflows/pull-request.yml.template +11 -0
- package/src/generators/preset/files/.github/workflows/release.yml.template +17 -0
- package/src/generators/preset/files/.github/workflows/stg-deployment.yml.template +17 -0
- package/src/generators/preset/files/.gitignore.template +5 -1
- package/src/generators/preset/files/README.md.template +17 -2
- package/src/generators/preset/files/application/README.md.template +0 -17
- package/src/generators/preset/files/application/_internal/log-group-defaults-aspect.ts.template +83 -0
- package/src/generators/preset/files/application/_internal/nodejs-function-defaults-aspect.ts.template +72 -0
- package/src/generators/preset/files/application/_internal/step-function-defaults-aspect.ts.template +83 -0
- package/src/generators/preset/files/application/bin/main.ts.template +34 -38
- package/src/generators/preset/files/application/cdk.json.template +1 -1
- package/src/generators/preset/files/application/lib/service-stacks.ts.template +3 -0
- package/src/generators/preset/files/application/package.json.template +0 -6
- package/src/generators/preset/files/eslint.config.mjs.template +1 -2
- package/src/generators/preset/files/libs/infra/README.md.template +61 -0
- package/src/generators/preset/files/libs/infra/eslint.config.mjs.template +20 -0
- package/src/generators/preset/files/libs/infra/package.json.template +19 -0
- package/src/generators/preset/files/libs/infra/src/index.ts.template +44 -0
- package/src/generators/preset/files/libs/infra/tsconfig.json.template +6 -0
- package/src/generators/preset/files/parameters/dev.csv.template +2 -0
- package/src/generators/preset/files/tsconfig.json.template +1 -1
- package/src/generators/preset/preset.js +2 -4
- package/src/generators/service/files/README.md.template +2 -2
- package/src/generators/service/files/package.json.template +3 -2
- package/src/generators/service/files/src/index.ts.template +2 -1
- package/src/generators/service/files/vitest.config.mjs.template +1 -1
- package/src/generators/preset/files/.github/workflows/ci-cd.yml.template +0 -27
- package/src/generators/preset/files/application/_internal/log-group-defaults-injector.ts.template +0 -100
- package/src/generators/preset/files/application/_internal/microservice-checks.ts.template +0 -58
- package/src/generators/preset/files/application/_internal/nodejs-function-defaults-injector.ts.template +0 -110
- package/src/generators/preset/files/application/_internal/step-function-defaults-injector.ts.template +0 -126
- package/src/generators/preset/files/application/_internal/version-functions-aspect.ts.template +0 -74
- package/src/generators/preset/files/cdk-config.yml.template +0 -16
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ The preset generator scaffolds:
|
|
|
42
42
|
- `cdk.context.json` - CDK context
|
|
43
43
|
- `bin/main.ts` - CDK app entry point
|
|
44
44
|
- `lib/service-stacks.ts` - Service stacks definition
|
|
45
|
-
- TypeScript configurations (`tsconfig.json`, `tsconfig.
|
|
45
|
+
- TypeScript configurations (`tsconfig.json`, `tsconfig.spec.json`)
|
|
46
46
|
|
|
47
47
|
### Service Generator
|
|
48
48
|
|
|
@@ -51,7 +51,7 @@ The service generator creates a new CDK service within the `services/` folder of
|
|
|
51
51
|
#### Usage
|
|
52
52
|
|
|
53
53
|
```bash
|
|
54
|
-
|
|
54
|
+
yarn nx g @aligent/nx-cdk:service <service-name>
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
#### Options
|
|
@@ -83,10 +83,10 @@ The service generator creates a new service in `services/<service-name>/` with:
|
|
|
83
83
|
|
|
84
84
|
```bash
|
|
85
85
|
# Create a new service named "user-management"
|
|
86
|
-
|
|
86
|
+
yarn nx g @aligent/nx-cdk:service user-management
|
|
87
87
|
|
|
88
88
|
# Create a new service named "payment-processing"
|
|
89
|
-
|
|
89
|
+
yarn nx g @aligent/nx-cdk:service payment-processing
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
## Project Structure
|
package/generators.json
CHANGED
package/package.json
CHANGED
|
@@ -4,20 +4,20 @@ exports.NX_JSON = void 0;
|
|
|
4
4
|
exports.NX_JSON = {
|
|
5
5
|
$schema: './node_modules/nx/schemas/nx-schema.json',
|
|
6
6
|
defaultBase: 'origin/staging',
|
|
7
|
+
sync: { applyChanges: true },
|
|
7
8
|
plugins: [
|
|
8
9
|
{ plugin: '@nx/eslint/plugin', options: {} },
|
|
9
|
-
{ plugin: '@nx/vite/plugin', options: {} },
|
|
10
10
|
{ plugin: '@nx/js/typescript', options: { build: false } },
|
|
11
|
+
{ plugin: '@nx/vitest', options: { testMode: 'run' } },
|
|
11
12
|
],
|
|
12
13
|
namedInputs: {
|
|
13
14
|
default: ['{projectRoot}/**/*', 'sharedGlobals'],
|
|
14
15
|
production: [
|
|
15
16
|
'default',
|
|
16
|
-
'!{projectRoot}/.eslintrc.json',
|
|
17
17
|
'!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
|
|
18
|
+
'!{projectRoot}/tests/*',
|
|
18
19
|
'!{projectRoot}/tsconfig.spec.json',
|
|
19
20
|
'!{projectRoot}/vitest.config.m[jt]s',
|
|
20
|
-
'!{projectRoot}/src/test-setup.[jt]s',
|
|
21
21
|
],
|
|
22
22
|
sharedGlobals: [],
|
|
23
23
|
},
|
|
@@ -28,25 +28,15 @@ exports.NX_JSON = {
|
|
|
28
28
|
inputs: ['production', '^production'],
|
|
29
29
|
outputs: ['{projectRoot}/dist'],
|
|
30
30
|
},
|
|
31
|
-
cdk: { dependsOn: ['^build'
|
|
32
|
-
lint: { cache: true, inputs: ['default'] },
|
|
31
|
+
cdk: { dependsOn: ['^build'], inputs: ['production', '^production'] },
|
|
32
|
+
lint: { cache: true, inputs: ['default', '^production'] },
|
|
33
33
|
test: {
|
|
34
34
|
cache: true,
|
|
35
35
|
inputs: ['default', '^production'],
|
|
36
36
|
outputs: ['{projectRoot}/coverage'],
|
|
37
|
-
// Stack tests may require lambda handlers to be built first
|
|
38
|
-
dependsOn: ['^build', 'build:lambda'],
|
|
37
|
+
dependsOn: ['^build'], // Stack tests may require lambda handlers to be built first
|
|
39
38
|
configurations: { coverage: { coverage: true } },
|
|
40
39
|
},
|
|
41
|
-
typecheck: { cache: true,
|
|
42
|
-
parameters: {
|
|
43
|
-
executor: 'nx:run-commands',
|
|
44
|
-
options: { color: true, cwd: '{projectRoot}/parameters', file: '.env.csv' },
|
|
45
|
-
defaultConfiguration: 'export',
|
|
46
|
-
configurations: {
|
|
47
|
-
import: { command: 'store-parameters import {args.file}' },
|
|
48
|
-
export: { command: 'store-parameters export {args.file} --path={args.path}' },
|
|
49
|
-
},
|
|
50
|
-
},
|
|
40
|
+
typecheck: { cache: true, inputs: ['default', '^production'] },
|
|
51
41
|
},
|
|
52
42
|
};
|
|
@@ -11,22 +11,24 @@ export declare const PACKAGE_JSON: {
|
|
|
11
11
|
readonly typecheck: "nx affected -t typecheck";
|
|
12
12
|
readonly 'typecheck:all': "nx run-many -t typecheck";
|
|
13
13
|
readonly postinstall: "[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true";
|
|
14
|
-
readonly 'pg:synth': "nx run application:cdk synth '
|
|
15
|
-
readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' '
|
|
16
|
-
readonly 'pg:destroy': "nx run application:cdk destroy '
|
|
14
|
+
readonly 'pg:synth': "nx run application:cdk synth 'dev/**' --exclusively --profile playground";
|
|
15
|
+
readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' 'dev/**' --exclusively --require-approval never --profile playground";
|
|
16
|
+
readonly 'pg:destroy': "nx run application:cdk destroy 'dev/**' --profile playground";
|
|
17
17
|
readonly audit: "nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache";
|
|
18
18
|
};
|
|
19
19
|
readonly dependencies: {
|
|
20
20
|
readonly '@aligent/microservice-util-lib': "^1.2.0";
|
|
21
21
|
};
|
|
22
22
|
readonly devDependencies: {
|
|
23
|
+
readonly '@aligent/cdk-aspects': "^0.2.0";
|
|
23
24
|
readonly '@aligent/cdk-step-function-from-file': "^0.3.2";
|
|
24
25
|
readonly '@aligent/nx-openapi': "^1.0.0";
|
|
25
26
|
readonly '@aligent/ts-code-standards': "^4.1.0";
|
|
26
27
|
readonly '@nx/eslint': "22.1.3";
|
|
27
28
|
readonly '@nx/eslint-plugin': "22.1.3";
|
|
28
29
|
readonly '@nx/js': "22.1.3";
|
|
29
|
-
readonly '@nx/
|
|
30
|
+
readonly '@nx/vitest': "22.1.3";
|
|
31
|
+
readonly '@nx/workspace': "22.1.3";
|
|
30
32
|
readonly '@swc-node/register': "^1.10.10";
|
|
31
33
|
readonly '@swc/core': "^1.13.3";
|
|
32
34
|
readonly '@swc/helpers': "^0.5.17";
|
|
@@ -37,7 +39,7 @@ export declare const PACKAGE_JSON: {
|
|
|
37
39
|
readonly '@vitest/coverage-v8': "^3.2.4";
|
|
38
40
|
readonly '@vitest/ui': "^3.2.4";
|
|
39
41
|
readonly 'aws-cdk': "^2.1033.0";
|
|
40
|
-
readonly 'aws-cdk-lib': "^2.
|
|
42
|
+
readonly 'aws-cdk-lib': "^2.235.1";
|
|
41
43
|
readonly 'cdk-nag': "^2.37.55";
|
|
42
44
|
readonly constructs: "^10.4.3";
|
|
43
45
|
readonly eslint: "^9.32.0";
|
|
@@ -56,6 +58,26 @@ export declare const PACKAGE_JSON: {
|
|
|
56
58
|
readonly vite: "^7.2.6";
|
|
57
59
|
readonly vitest: "^3.2.4";
|
|
58
60
|
};
|
|
61
|
+
readonly nx: {
|
|
62
|
+
readonly includedScripts: readonly [];
|
|
63
|
+
readonly targets: {
|
|
64
|
+
readonly parameters: {
|
|
65
|
+
readonly executor: "nx:run-commands";
|
|
66
|
+
readonly options: {
|
|
67
|
+
readonly color: true;
|
|
68
|
+
readonly cwd: "parameters";
|
|
69
|
+
};
|
|
70
|
+
readonly configurations: {
|
|
71
|
+
readonly import: {
|
|
72
|
+
readonly command: "store-parameters import {args.file} --delimiter=|";
|
|
73
|
+
};
|
|
74
|
+
readonly export: {
|
|
75
|
+
readonly command: "store-parameters export {args.file} --path={args.path} --delimiter=|";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
59
81
|
readonly workspaces: readonly ["application", "clients", "libs/*", "services/*"];
|
|
60
82
|
readonly packageManager: "yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8";
|
|
61
83
|
};
|
|
@@ -14,22 +14,24 @@ exports.PACKAGE_JSON = {
|
|
|
14
14
|
typecheck: 'nx affected -t typecheck',
|
|
15
15
|
'typecheck:all': 'nx run-many -t typecheck',
|
|
16
16
|
postinstall: `[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true`,
|
|
17
|
-
'pg:synth': `nx run application:cdk synth '
|
|
18
|
-
'pg:deploy': `nx run application:cdk deploy --method 'direct' '
|
|
19
|
-
'pg:destroy': "nx run application:cdk destroy '
|
|
17
|
+
'pg:synth': `nx run application:cdk synth 'dev/**' --exclusively --profile playground`,
|
|
18
|
+
'pg:deploy': `nx run application:cdk deploy --method 'direct' 'dev/**' --exclusively --require-approval never --profile playground`,
|
|
19
|
+
'pg:destroy': "nx run application:cdk destroy 'dev/**' --profile playground",
|
|
20
20
|
audit: 'nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache',
|
|
21
21
|
},
|
|
22
22
|
dependencies: {
|
|
23
23
|
'@aligent/microservice-util-lib': '^1.2.0',
|
|
24
24
|
},
|
|
25
25
|
devDependencies: {
|
|
26
|
+
'@aligent/cdk-aspects': '^0.2.0',
|
|
26
27
|
'@aligent/cdk-step-function-from-file': '^0.3.2',
|
|
27
28
|
'@aligent/nx-openapi': '^1.0.0',
|
|
28
29
|
'@aligent/ts-code-standards': '^4.1.0',
|
|
29
30
|
'@nx/eslint': '22.1.3',
|
|
30
31
|
'@nx/eslint-plugin': '22.1.3',
|
|
31
32
|
'@nx/js': '22.1.3',
|
|
32
|
-
'@nx/
|
|
33
|
+
'@nx/vitest': '22.1.3',
|
|
34
|
+
'@nx/workspace': '22.1.3',
|
|
33
35
|
'@swc-node/register': '^1.10.10',
|
|
34
36
|
'@swc/core': '^1.13.3',
|
|
35
37
|
'@swc/helpers': '^0.5.17',
|
|
@@ -40,7 +42,7 @@ exports.PACKAGE_JSON = {
|
|
|
40
42
|
'@vitest/coverage-v8': '^3.2.4',
|
|
41
43
|
'@vitest/ui': '^3.2.4',
|
|
42
44
|
'aws-cdk': '^2.1033.0',
|
|
43
|
-
'aws-cdk-lib': '^2.
|
|
45
|
+
'aws-cdk-lib': '^2.235.1',
|
|
44
46
|
'cdk-nag': '^2.37.55',
|
|
45
47
|
constructs: '^10.4.3',
|
|
46
48
|
eslint: '^9.32.0',
|
|
@@ -60,6 +62,21 @@ exports.PACKAGE_JSON = {
|
|
|
60
62
|
vite: '^7.2.6',
|
|
61
63
|
vitest: '^3.2.4',
|
|
62
64
|
},
|
|
65
|
+
nx: {
|
|
66
|
+
includedScripts: [],
|
|
67
|
+
targets: {
|
|
68
|
+
parameters: {
|
|
69
|
+
executor: 'nx:run-commands',
|
|
70
|
+
options: { color: true, cwd: 'parameters' },
|
|
71
|
+
configurations: {
|
|
72
|
+
import: { command: 'store-parameters import {args.file} --delimiter=|' },
|
|
73
|
+
export: {
|
|
74
|
+
command: 'store-parameters export {args.file} --path={args.path} --delimiter=|',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
63
80
|
workspaces: ['application', 'clients', 'libs/*', 'services/*'],
|
|
64
81
|
packageManager: 'yarn@4.12.0+sha512.f45ab632439a67f8bc759bf32ead036a1f413287b9042726b7cc4818b7b49e14e9423ba49b18f9e06ea4941c1ad062385b1d8760a8d5091a1a31e5f6219afca8',
|
|
65
82
|
};
|
|
@@ -18,17 +18,17 @@ exports.TS_CONFIG_LIB_JSON = {
|
|
|
18
18
|
types: ['node'],
|
|
19
19
|
},
|
|
20
20
|
include: ['src/**/*.ts'],
|
|
21
|
-
exclude: ['
|
|
21
|
+
exclude: ['vitest.config.mjs', 'src/**/*.spec.ts', 'src/**/*.test.ts'],
|
|
22
22
|
references: [],
|
|
23
23
|
};
|
|
24
24
|
exports.TS_CONFIG_SPEC_JSON = {
|
|
25
25
|
extends: BASE_CONFIG,
|
|
26
26
|
compilerOptions: {
|
|
27
27
|
outDir: './out-tsc/vitest',
|
|
28
|
-
types: ['vitest/globals', 'vitest/importMeta', '
|
|
28
|
+
types: ['vitest/globals', 'vitest/importMeta', 'node', 'vitest'],
|
|
29
29
|
},
|
|
30
30
|
include: [
|
|
31
|
-
'
|
|
31
|
+
'vitest.config.mjs',
|
|
32
32
|
'src/**/*.test.ts',
|
|
33
33
|
'src/**/*.spec.ts',
|
|
34
34
|
'src/**/*.d.ts',
|
|
@@ -19,9 +19,9 @@ export declare function constructPackageJsonFile(input: PackageJsonInput): {
|
|
|
19
19
|
readonly typecheck: "nx affected -t typecheck";
|
|
20
20
|
readonly 'typecheck:all': "nx run-many -t typecheck";
|
|
21
21
|
readonly postinstall: "[ -d .git ] && git config core.hooksPath '.git-hooks' && chmod +x .git-hooks/* || true";
|
|
22
|
-
readonly 'pg:synth': "nx run application:cdk synth '
|
|
23
|
-
readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' '
|
|
24
|
-
readonly 'pg:destroy': "nx run application:cdk destroy '
|
|
22
|
+
readonly 'pg:synth': "nx run application:cdk synth 'dev/**' --exclusively --profile playground";
|
|
23
|
+
readonly 'pg:deploy': "nx run application:cdk deploy --method 'direct' 'dev/**' --exclusively --require-approval never --profile playground";
|
|
24
|
+
readonly 'pg:destroy': "nx run application:cdk destroy 'dev/**' --profile playground";
|
|
25
25
|
readonly audit: "nx run-many -t lint typecheck test --configuration coverage --skip-nx-cache";
|
|
26
26
|
} | {
|
|
27
27
|
readonly '@aligent/microservice-util-lib': "^1.2.0";
|
|
@@ -29,6 +29,27 @@ export declare function constructPackageJsonFile(input: PackageJsonInput): {
|
|
|
29
29
|
[k: string]: string;
|
|
30
30
|
} | {
|
|
31
31
|
node: string;
|
|
32
|
+
} | {
|
|
33
|
+
includedScripts: readonly [];
|
|
34
|
+
targets: {
|
|
35
|
+
readonly parameters: {
|
|
36
|
+
readonly executor: "nx:run-commands";
|
|
37
|
+
readonly options: {
|
|
38
|
+
readonly color: true;
|
|
39
|
+
readonly cwd: "parameters";
|
|
40
|
+
};
|
|
41
|
+
readonly configurations: {
|
|
42
|
+
readonly import: {
|
|
43
|
+
readonly command: "store-parameters import {args.file} --delimiter=|";
|
|
44
|
+
};
|
|
45
|
+
readonly export: {
|
|
46
|
+
readonly command: "store-parameters export {args.file} --path={args.path} --delimiter=|";
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
name: string;
|
|
52
|
+
node?: undefined;
|
|
32
53
|
};
|
|
33
54
|
};
|
|
34
55
|
export declare function constructProjectTsConfigFiles(type: 'application' | 'service'): {
|
|
@@ -24,6 +24,7 @@ function constructPackageJsonFile(input) {
|
|
|
24
24
|
...packageJson_1.PACKAGE_JSON,
|
|
25
25
|
devDependencies,
|
|
26
26
|
engines: { node: `^${input.nodeVersion}` },
|
|
27
|
+
nx: { name: `${input.name}-int`, ...packageJson_1.PACKAGE_JSON.nx },
|
|
27
28
|
}));
|
|
28
29
|
return packageJson;
|
|
29
30
|
}
|
|
@@ -78,16 +79,18 @@ async function addServiceStackToMainApplication(tree, service, projectName) {
|
|
|
78
79
|
const project = new ts_morph_1.Project();
|
|
79
80
|
const stackSource = project.addSourceFileAtPath(stacksPath);
|
|
80
81
|
const applicationStage = stackSource.getClassOrThrow('ApplicationStage');
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
82
|
+
const stageConstructor = applicationStage.getConstructors()[0];
|
|
83
|
+
if (!stageConstructor) {
|
|
83
84
|
throw new Error('Unable to find main application stage constructor');
|
|
84
85
|
}
|
|
85
86
|
stackSource.addImportDeclaration({
|
|
86
87
|
moduleSpecifier: `@services/${service.name}`,
|
|
87
88
|
namedImports: [service.constant, service.stack],
|
|
88
89
|
});
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
const sharedInfra = stageConstructor.getVariableStatement('sharedInfra');
|
|
91
|
+
const sharedPropsStatement = sharedInfra ? `...sharedInfra.getProps(),` : '';
|
|
92
|
+
stageConstructor.addStatements(`new ${service.stack}(this, ${service.constant}.NAME, { ...props, ${sharedPropsStatement} description: ${service.constant}.DESCRIPTION });`);
|
|
93
|
+
await stackSource.save();
|
|
91
94
|
}
|
|
92
95
|
/**
|
|
93
96
|
* Splits a kebab-case name into an array of capitalized parts.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types:
|
|
6
|
+
- published
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
name: Deploy to AWS
|
|
11
|
+
uses: aligent/workflows/.github/workflows/aws-cdk.yml@main
|
|
12
|
+
with:
|
|
13
|
+
deploy: true
|
|
14
|
+
deploy-command: yarn nx run application:cdk deploy
|
|
15
|
+
extra-arguments: --exclusively
|
|
16
|
+
github-environment: production
|
|
17
|
+
secrets: inherit
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: Staging Deployment
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
name: Deploy to AWS
|
|
11
|
+
uses: aligent/workflows/.github/workflows/aws-cdk.yml@main
|
|
12
|
+
with:
|
|
13
|
+
deploy: true
|
|
14
|
+
deploy-command: yarn nx run application:cdk deploy
|
|
15
|
+
extra-arguments: --exclusively
|
|
16
|
+
github-environment: staging
|
|
17
|
+
secrets: inherit
|
|
@@ -55,19 +55,34 @@ We follow [trunk-based development framework](https://trunkbaseddevelopment.com/
|
|
|
55
55
|
1. Create new branch from `main`
|
|
56
56
|
2. Make your changes following code standards
|
|
57
57
|
3. Ensure your changes pass linting, type checks and testes
|
|
58
|
-
4. Submit a pull request back to `main`
|
|
59
|
-
5. For deployment,
|
|
58
|
+
4. Submit a pull request back to `main`. A merge to `main` will deploy to `staging` environment.
|
|
59
|
+
5. For `production` deployment, create a release from `main`.
|
|
60
60
|
|
|
61
61
|
## Adding New Services
|
|
62
62
|
|
|
63
63
|
To add a new service to the monorepo:
|
|
64
64
|
|
|
65
65
|
1. Use the Aligent CDK generator `@aligent/nx-cdk`
|
|
66
|
+
```bash
|
|
67
|
+
yarn nx g @aligent/nx-cdk:service <service-name>
|
|
68
|
+
```
|
|
66
69
|
2. Add service infrastructure in
|
|
67
70
|
- `services/{service-name}/src/index.ts`
|
|
68
71
|
- `services/{service-name}/src/infra/`
|
|
69
72
|
3. Add Lambda handlers in `services/{service-name}/src/runtime/handlers/`
|
|
70
73
|
|
|
74
|
+
## Environment Parameters Management
|
|
75
|
+
|
|
76
|
+
Parameters are managed through the `parameters/{env}.csv` file by default
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Import values from `parameters/{env}.csv` to Parameter Store in AWS
|
|
80
|
+
yarn nx run <%= name %>-int:parameters:import --file=dev.csv
|
|
81
|
+
|
|
82
|
+
# Custom filename and parameter path can be passed in as arguments
|
|
83
|
+
yarn nx run <%= name %>-int:parameters:export --file=dev.csv --path=/my/dev/path
|
|
84
|
+
```
|
|
85
|
+
|
|
71
86
|
## License
|
|
72
87
|
|
|
73
88
|
MIT
|
|
@@ -2,23 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
This application manages the deployment of microservices and their shared infrastructure.
|
|
4
4
|
|
|
5
|
-
## Configuration
|
|
6
|
-
|
|
7
|
-
### Environment Parameters
|
|
8
|
-
|
|
9
|
-
Parameters are managed through the `parameters/.env.csv` file by default
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
# Pull down parameters from the playground environment to .env.csv
|
|
13
|
-
yarn nx run application:parameters
|
|
14
|
-
|
|
15
|
-
# Update parameters from .env.csv
|
|
16
|
-
yarn nx run application:parameters:import
|
|
17
|
-
|
|
18
|
-
# Custom filename and parameter path can be passed in as arguments
|
|
19
|
-
yarn nx run application:parameters --file .env.dev.csv --path /my/dev/path
|
|
20
|
-
```
|
|
21
|
-
|
|
22
5
|
## Deployment
|
|
23
6
|
|
|
24
7
|
### Using yarn script from workspace root (Recommended)
|
package/src/generators/preset/files/application/_internal/log-group-defaults-aspect.ts.template
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RemovalPolicy, type IAspect } from 'aws-cdk-lib';
|
|
2
|
+
import { CfnLogGroup, LogGroup, RetentionDays, type LogGroupProps } from 'aws-cdk-lib/aws-logs';
|
|
3
|
+
import { IConstruct } from 'constructs';
|
|
4
|
+
|
|
5
|
+
interface Config {
|
|
6
|
+
duration: 'SHORT' | 'MEDIUM' | 'LONG';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Aspect that automatically applies configuration-aware defaults to CloudWatch Log Groups
|
|
11
|
+
*
|
|
12
|
+
* Visits all constructs in the scope and automatically applies configuration-specific to log groups.
|
|
13
|
+
* Different configurations balance between cost optimization and data retention needs.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Apply configuration-specific defaults to all log groups
|
|
18
|
+
* Aspects.of(app).add(new LogGroupDefaultsAspect({ duration: 'SHORT' }));
|
|
19
|
+
*
|
|
20
|
+
* // Log groups automatically inherit configuration defaults
|
|
21
|
+
* new LogGroup(stack, 'MyLogGroup', {
|
|
22
|
+
* // retention and removal policy applied automatically
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogGroup.html
|
|
27
|
+
*/
|
|
28
|
+
export class LogGroupDefaultsAspect implements IAspect {
|
|
29
|
+
private readonly defaultProps: LogGroupProps;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new LogGroupDefaultsAspect
|
|
33
|
+
*
|
|
34
|
+
* @param config - Configuration identifier used to select appropriate defaults.
|
|
35
|
+
*/
|
|
36
|
+
constructor(config: Config) {
|
|
37
|
+
const props = this.retentionProperties(config.duration);
|
|
38
|
+
this.defaultProps = { ...props };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Get duration-specific log group properties
|
|
43
|
+
*
|
|
44
|
+
* @param duration - The duration to get the log group properties for
|
|
45
|
+
* @returns The log group properties for the duration
|
|
46
|
+
*/
|
|
47
|
+
private retentionProperties(duration: 'SHORT' | 'MEDIUM' | 'LONG') {
|
|
48
|
+
switch (duration) {
|
|
49
|
+
case 'SHORT':
|
|
50
|
+
return { retention: RetentionDays.ONE_WEEK, removalPolicy: RemovalPolicy.DESTROY };
|
|
51
|
+
case 'MEDIUM':
|
|
52
|
+
return {
|
|
53
|
+
retention: RetentionDays.SIX_MONTHS,
|
|
54
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
55
|
+
};
|
|
56
|
+
default:
|
|
57
|
+
return { retention: RetentionDays.TWO_YEARS, removalPolicy: RemovalPolicy.RETAIN };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Visits a construct and applies configuration-appropriate defaults
|
|
63
|
+
*
|
|
64
|
+
* Applies configuration-specific retention and removal policies to log groups
|
|
65
|
+
* that don't already have these properties explicitly set.
|
|
66
|
+
*
|
|
67
|
+
* @param node - The construct to potentially modify
|
|
68
|
+
*/
|
|
69
|
+
visit(node: IConstruct): void {
|
|
70
|
+
if (node instanceof LogGroup) {
|
|
71
|
+
if (this.defaultProps.removalPolicy) {
|
|
72
|
+
node.applyRemovalPolicy(this.defaultProps.removalPolicy);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.defaultProps.retention) {
|
|
76
|
+
const cfnLogGroup = node.node.defaultChild as CfnLogGroup;
|
|
77
|
+
if (cfnLogGroup && cfnLogGroup.retentionInDays === undefined) {
|
|
78
|
+
cfnLogGroup.retentionInDays = this.defaultProps.retention;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type IAspect } from 'aws-cdk-lib';
|
|
2
|
+
import { CfnFunction, Runtime, Tracing } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
|
|
4
|
+
import { IConstruct } from 'constructs';
|
|
5
|
+
|
|
6
|
+
interface Config {
|
|
7
|
+
runtime: Runtime;
|
|
8
|
+
sourceMap?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Aspect that automatically applies configuration-aware defaults to Node.js Lambda functions
|
|
13
|
+
*
|
|
14
|
+
* Visits all constructs in the scope and automatically applies configuration-specific runtime, tracing, and environment settings to Node.js Lambda functions.
|
|
15
|
+
* Different configurations can optimize for different priorities such as build speed, bundle size, or debugging capabilities.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Apply configuration-specific defaults to all Node.js functions
|
|
20
|
+
* Aspects.of(app).add(new NodeJsFunctionDefaultsAspect({
|
|
21
|
+
* runtime: Runtime.NODEJS_24_X,
|
|
22
|
+
* sourceMap: true,
|
|
23
|
+
* }));
|
|
24
|
+
*
|
|
25
|
+
* // Functions automatically inherit configuration defaults
|
|
26
|
+
* new NodejsFunction(stack, 'MyFunction', {
|
|
27
|
+
* code: Code.fromAsset('src/lambda'),
|
|
28
|
+
* handler: 'index.handler',
|
|
29
|
+
* // runtime, tracing, and source map support applied automatically
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @see https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.NodejsFunction.html
|
|
34
|
+
*/
|
|
35
|
+
export class NodeJsFunctionDefaultsAspect implements IAspect {
|
|
36
|
+
private readonly config: Required<Config>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new NodeJsFunctionDefaultsAspect
|
|
40
|
+
*
|
|
41
|
+
* @param config - Configuration identifier used to select appropriate defaults.
|
|
42
|
+
*/
|
|
43
|
+
constructor(config: Config) {
|
|
44
|
+
this.config = { ...config, sourceMap: config.sourceMap ?? true };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Visits a construct and applies runtime and tracing settings if it's a NodejsFunction
|
|
49
|
+
*
|
|
50
|
+
* Applies configuration-specific runtime, tracing, and environment settings to Node.js
|
|
51
|
+
* Lambda functions that don't already have these properties explicitly set.
|
|
52
|
+
*
|
|
53
|
+
* @param node - The construct to potentially modify
|
|
54
|
+
*/
|
|
55
|
+
visit(node: IConstruct): void {
|
|
56
|
+
if (node instanceof NodejsFunction) {
|
|
57
|
+
const cfnFunction = node.node.defaultChild as CfnFunction;
|
|
58
|
+
|
|
59
|
+
if (cfnFunction) {
|
|
60
|
+
cfnFunction.runtime = this.config.runtime.name;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (cfnFunction && cfnFunction.tracingConfig === undefined) {
|
|
64
|
+
cfnFunction.tracingConfig = { mode: Tracing.ACTIVE };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (this.config.sourceMap) {
|
|
68
|
+
node.addEnvironment('NODE_OPTIONS', '--enable-source-maps');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|