Skip to content

Commit c2cdbf2

Browse files
committed
feat(riff-raff.yaml)!: Support generation of a subset of GuStacks
Add support for the scenario where we create a singleton stack for shared infrastructure alongside application stacks. For example, a singleton stack that provisions an Elastic Container Registry, and a CODE and PROD application stack that pulls images from the registry. Previously, we had to create work-arounds with multiple `App`s. BREAKING CHANGE: `RiffRaffYamlFile` can no longer be directly instantiated Instead of directly instantiating `RiffRaffYamlFile`, please use `RiffRaffYamlFile.fromApp`: ```ts // Before const app = new App(); new RiffRaffYamlFile(app); // After const app = new App(); RiffRaffYamlFile.fromApp(app); ```
1 parent 91f9ecf commit c2cdbf2

5 files changed

Lines changed: 266 additions & 31 deletions

File tree

.changeset/young-pets-fetch.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
"@guardian/cdk": major
3+
---
4+
5+
Add support for the scenario where we create a singleton stack for shared infrastructure
6+
alongside application stacks.
7+
For example, a singleton stack that provisions an Elastic Container Registry,
8+
and a CODE and PROD application stack that pulls images from the registry.
9+
10+
Previously, we had to create work-arounds with multiple `App`s.
11+
12+
BREAKING CHANGE: `RiffRaffYamlFile` can no longer be directly instantiated
13+
Instead of directly instantiating `RiffRaffYamlFile`, please use `RiffRaffYamlFile.fromApp`:
14+
15+
```ts
16+
// Before
17+
const app = new App();
18+
new RiffRaffYamlFile(app);
19+
20+
// After
21+
const app = new App();
22+
RiffRaffYamlFile.fromApp(app);
23+
```

src/constructs/root.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { RiffRaffYamlFile } from "../riff-raff-yaml-file";
3030
*/
3131
export class GuRoot extends App {
3232
override synth(options?: StageSynthesisOptions): CloudAssembly {
33-
new RiffRaffYamlFile(this).synth();
33+
RiffRaffYamlFile.fromApp(this).synth();
3434
return super.synth(options);
3535
}
3636
}

src/riff-raff-yaml-file/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ new MyStack(app, "my-stack-PROD", {});
3838
```
3939

4040
### Advanced usage
41+
#### Additional deployment types
4142
As noted above, only specific deployment types are currently supported.
4243

4344
If you want to add additional deployment types, you can do so by instantiating `RiffRaffYamlFile` directly:
@@ -54,7 +55,7 @@ const { stack, region } = new MyStack(app, "my-stack", {
5455
env: { region: "eu-west-1" },
5556
});
5657

57-
const riffRaff = new RiffRaffYamlFile(app);
58+
const riffRaff = RiffRaffYamlFile.fromApp(app);
5859
const { riffRaffYaml: { deployments } } = riffRaff;
5960

6061
deployments.set("upload-my-static-files", {
@@ -79,6 +80,36 @@ riffRaff.synth();
7980

8081
When the CDK stack is synthesized, a `riff-raff.yaml` file will be created in the output directory, typically `/<repo-root>/cdk/cdk.out`.
8182

83+
#### Multiple Riff-Raff projects in a single repository
84+
If your repository deploys multiple Riff-Raff projects, use `RiffRaffYamlFile.fromStacks` to generate a `riff-raff.yaml` for a selection of `GuStack`s:
85+
86+
```ts
87+
import { App } from "aws-cdk-lib";
88+
import { RiffRaffYamlFile } from "@guardian/cdk/lib/riff-raff-yaml-file";
89+
90+
const app = new App();
91+
92+
const myInfraStack = new MyInfraStack(app, "my-infra-stack", {
93+
stack: "playground",
94+
stage: "INFRA",
95+
env: { region: "eu-west-1" },
96+
});
97+
98+
const myAppStackCODE = new MyAppStack(app, "my-stack-CODE", {
99+
stack: "playground",
100+
stage: "CODE",
101+
env: { region: "eu-west-1" },
102+
});
103+
const myAppStackPROD = new MyAppStack(app, "my-stack-PROD", {
104+
stack: "playground",
105+
stage: "CODE",
106+
env: { region: "eu-west-1" },
107+
});
108+
109+
RiffRaffYamlFile.fromStacks([myInfraStack], "playground::core-infra"); // Generates a file to `cdk.out/playground::core-infra/riff-raff.yaml`
110+
RiffRaffYamlFile.fromStacks([myAppStackCODE, myAppStackPROD], "playground::my-app"); // Generates a file to `cdk.out/playground::my-app/riff-raff.yaml`
111+
```
112+
82113
## Package layout
83114
`RiffRaffYamlFile` assumes CI has uploaded files in the following structure:
84115

0 commit comments

Comments
 (0)