Skip to content

Commit

Permalink
Merge branch 'main' into jw-dl-cross-account-role
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLawes committed Oct 11, 2023
2 parents e58a9ce + f64910a commit c82c266
Show file tree
Hide file tree
Showing 25 changed files with 467 additions and 93 deletions.
3 changes: 2 additions & 1 deletion docs/setting-up-a-gucdk-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Requirements:
## Creating a new project
GuCDK provides a CLI tool to create a new project.
It will place files within a `cdk` directory at the root of the repository.
It will also generate a `riff-raff.yaml` file.

To initialise a new project run the following within your repository:

Expand Down Expand Up @@ -78,7 +79,7 @@ This ensures you have a short feedback loop.
We recommend performing the following steps in CI:
- `lint` to ensure a common code format
- `test` to run the snapshot tests to make sure there are no unexpected changes to the generated CFN (see [here](best-practices.md) for more detail)
- `synth` to generate your template as JSON to `cdk/cdk.out`
- `synth` to generate your template as JSON, and a `riff-raff.yaml` file to `cdk/cdk.out`

These steps are described in the `package.json` file.

Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@types/lodash.upperfirst": "^4.3.7",
"@types/node": "20.8.2",
"@types/yargs": "^17.0.26",
"aws-cdk": "2.95.1",
"aws-cdk": "2.100.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.50.0",
"eslint-plugin-custom-rules": "file:tools/eslint",
Expand All @@ -55,11 +55,11 @@
},
"dependencies": {
"@oclif/core": "2.15.0",
"aws-cdk-lib": "2.95.1",
"aws-cdk-lib": "2.100.0",
"aws-sdk": "^2.1469.0",
"chalk": "^4.1.2",
"codemaker": "^1.89.0",
"constructs": "10.2.70",
"constructs": "10.3.0",
"git-url-parse": "^13.1.0",
"js-yaml": "^4.1.0",
"lodash.camelcase": "^4.3.0",
Expand All @@ -69,9 +69,9 @@
"yargs": "^17.7.2"
},
"peerDependencies": {
"aws-cdk": "2.95.1",
"aws-cdk-lib": "2.95.1",
"constructs": "10.2.70"
"aws-cdk": "2.100.0",
"aws-cdk-lib": "2.100.0",
"constructs": "10.3.0"
},
"config": {
"commitizen": {
Expand Down
2 changes: 2 additions & 0 deletions script/ci-project-generation
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ npm pack --pack-destination $TMP_DIR
--stack cdk \
--stage CODE \
--stage PROD \
--region eu-west-1 \
--region us-east-1 \
--package-manager npm
)
5 changes: 4 additions & 1 deletion src/bin/commands/new-project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface NewProjectProps {
app: string;
stack: string;
stages: string[];
regions: string[];
yamlTemplateLocation?: string;
packageManager: PackageManager;
}
Expand Down Expand Up @@ -59,7 +60,7 @@ function validateConfig(config: NewProjectConfig): void {
}

function getConfig(props: NewProjectProps): NewProjectConfig {
const { init, app, stack, stages, yamlTemplateLocation, packageManager } = props;
const { init, app, stack, stages, regions, yamlTemplateLocation, packageManager } = props;

const rootDir = gitRootOrCwd();
const cdkDir = join(rootDir, "/cdk");
Expand All @@ -73,6 +74,7 @@ function getConfig(props: NewProjectProps): NewProjectConfig {
init,
yamlTemplateLocation,
stages,
regions,
cdkDir,
appName: {
kebab: kebabAppName,
Expand Down Expand Up @@ -113,6 +115,7 @@ export const newCdkProject = async (props: NewProjectProps): CliCommandResponse
stack: config.stackName,
imports: Imports.newAppImports(config.appName),
stages: config.stages,
regions: config.regions,
});

// lib directory
Expand Down
14 changes: 9 additions & 5 deletions src/bin/commands/new-project/utils/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface AppBuilderProps {
appName: Name;
stack: Name;
stages: string[];
regions: string[];
outputFile: string;
outputDir: string;
comment?: string;
Expand All @@ -26,7 +27,7 @@ export class AppBuilder {
}

async constructCdkFile(): Promise<void> {
const { comment, outputFile, imports, appName, stack, outputDir, stages } = this.config;
const { comment, outputFile, imports, appName, stack, outputDir, stages, regions } = this.config;

this.code.openFile(outputFile);
if (comment) {
Expand All @@ -36,12 +37,15 @@ export class AppBuilder {

imports.render(this.code);

this.code.line("const app = new App();");
this.code.line("const app = new GuRoot();");

stages.forEach((stage) => {
this.code.line(
`new ${appName.pascal}(app, "${appName.pascal}-${stage}", { stack: "${stack.kebab}", stage: "${stage}" });`,
);
regions.forEach((region) => {
const regionNoHyphen = region.replace("-", "");
this.code.line(
`new ${appName.pascal}(app, "${appName.pascal}-${regionNoHyphen}-${stage}", { stack: "${stack.kebab}", stage: "${stage}", env: { region: "${region}" } });`,
);
});
});

this.code.closeFile(outputFile);
Expand Down
8 changes: 4 additions & 4 deletions src/bin/commands/new-project/utils/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ export class Imports {

public static newAppImports({ kebab, pascal }: Name): Imports {
return new Imports({
"aws-cdk-lib": {
types: [],
components: ["App"],
},
"source-map-support/register": {
basic: true,
types: [],
components: [],
},
"@guardian/cdk/lib/constructs/root": {
types: [],
components: ["GuRoot"],
},
[`../lib/${kebab}`]: {
types: [],
components: [pascal],
Expand Down
9 changes: 9 additions & 0 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const parseCommandLineArguments = () => {
type: "array",
demandOption: true,
})
.option("region", {
description:
"The region(s) for your stack. Can be specified multiple times, e.g. --region eu-west-1 --region us-east-1",
type: "array",
default: ["eu-west-1"],
})
.option("package-manager", {
description:
"The Node package manager to use. Match this to the repository (package-lock.json = npm, yarn.lock = yarn). If the repository has neither file, and there is no strong convention in your team, we recommend npm.",
Expand Down Expand Up @@ -98,15 +104,18 @@ parseCommandLineArguments()
const stack = argv.stack as string;
const yamlTemplateLocation = argv["yaml-template-location"] as string | undefined;
const stage = argv.stage as string[];
const regions = argv.region as string[];
const packageManager = argv["package-manager"] as string;

const stages = stage.map((_) => _.toUpperCase());

return newCdkProject({
init,
app,
stack,
yamlTemplateLocation,
stages,
regions,
packageManager: packageManager as PackageManager,
});
}
Expand Down
Loading

0 comments on commit c82c266

Please sign in to comment.