Skip to content

Commit f7b1b04

Browse files
authored
feat(pulumi-aws): deploy environment variant (#4501)
1 parent abe709d commit f7b1b04

File tree

56 files changed

+481
-157
lines changed

Some content is hidden

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

56 files changed

+481
-157
lines changed

packages/api-apw/src/scheduler/handlers/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,16 @@ export interface ApwSettings {
122122
eventTargetId: string;
123123
}
124124

125+
const getVariant = (): string => {
126+
const value = process.env.WEBINY_ENV_VARIANT;
127+
if (!value || value === "undefined" || typeof value !== "string") {
128+
return "";
129+
}
130+
return String(value);
131+
};
132+
125133
export const getApwSettings = async (): Promise<ApwSettings> => {
126-
const variant = process.env.STAGED_ROLLOUTS_VARIANT;
134+
const variant = getVariant();
127135

128136
const params = {
129137
TableName: process.env.DB_TABLE as string,

packages/cli-plugin-deploy-pulumi/commands/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = (params, context) => {
66
name: "build",
77
createProjectApplicationWorkspace: true,
88
command: async ({ inputs, context, projectApplication }) => {
9-
const { env } = inputs;
9+
const { env, variant } = inputs;
1010

11-
const hookArgs = { context, env, inputs, projectApplication };
11+
const hookArgs = { context, env, variant, inputs, projectApplication };
1212

1313
await runHook({
1414
hook: "hook-before-build",

packages/cli-plugin-deploy-pulumi/commands/deploy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ module.exports = (params, context) => {
1313
telemetry: true,
1414
command: async commandParams => {
1515
const { inputs, context, projectApplication, pulumi, getDuration } = commandParams;
16-
const { env, folder, build, deploy } = inputs;
16+
const { env, variant, folder, build, deploy } = inputs;
1717

18-
const hookArgs = { context, env, inputs, projectApplication };
18+
const hookArgs = { context, env, variant, inputs, projectApplication };
1919

2020
context.info("Webiny version: %s", context.version);
2121
console.log();

packages/cli-plugin-deploy-pulumi/commands/deploy/executeDeploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = async ({ inputs, context, pulumi }) => {
4444
execa: {
4545
env: {
4646
WEBINY_ENV: inputs.env,
47+
WEBINY_ENV_VARIANT: inputs.variant || "",
4748
WEBINY_PROJECT_NAME: context.project.name,
4849
PULUMI_CONFIG_PASSPHRASE
4950
}

packages/cli-plugin-deploy-pulumi/commands/deploy/executePreview.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = async ({ inputs, context, pulumi }) => {
1212
execa: {
1313
env: {
1414
WEBINY_ENV: inputs.env,
15+
WEBINY_ENV_VARIANT: inputs.variant || "",
1516
WEBINY_PROJECT_NAME: context.project.name,
1617
PULUMI_CONFIG_PASSPHRASE
1718
}

packages/cli-plugin-deploy-pulumi/commands/deploy/pulumiLoginSelectStack.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
const { login } = require("../../utils");
2+
const { getStackName } = require("../../utils/getStackName");
23

34
module.exports = async ({ inputs, projectApplication, pulumi }) => {
4-
const { env } = inputs;
5+
const { env, variant } = inputs;
56

67
await login(projectApplication);
78

89
const PULUMI_SECRETS_PROVIDER = process.env.PULUMI_SECRETS_PROVIDER;
910
const PULUMI_CONFIG_PASSPHRASE = process.env.PULUMI_CONFIG_PASSPHRASE;
1011

12+
const stackName = getStackName({
13+
env,
14+
variant
15+
});
16+
1117
await pulumi.run({
12-
command: ["stack", "select", env],
18+
command: ["stack", "select", stackName],
1319
args: {
1420
create: true,
1521
secretsProvider: PULUMI_SECRETS_PROVIDER

packages/cli-plugin-deploy-pulumi/commands/destroy.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
const { createPulumiCommand, processHooks } = require("../utils");
2+
const { getStackName } = require("../utils/getStackName");
23

34
module.exports = createPulumiCommand({
45
name: "destroy",
56
// We want to create a workspace just because there are cases where the destroy command is called
67
// without the deployment happening initially (e.g. CI/CD scaffold's `pullRequestClosed.yml` workflow).
78
createProjectApplicationWorkspace: true,
89
command: async ({ inputs, context, projectApplication, pulumi, getDuration }) => {
9-
const { env, folder } = inputs;
10+
const { env, variant, folder } = inputs;
11+
12+
const stackName = getStackName({
13+
env,
14+
variant
15+
});
1016

1117
let stackExists = true;
1218
try {
1319
const PULUMI_SECRETS_PROVIDER = process.env.PULUMI_SECRETS_PROVIDER;
1420
const PULUMI_CONFIG_PASSPHRASE = process.env.PULUMI_CONFIG_PASSPHRASE;
1521

1622
await pulumi.run({
17-
command: ["stack", "select", env],
23+
command: ["stack", "select", stackName],
1824
args: {
1925
secretsProvider: PULUMI_SECRETS_PROVIDER
2026
},
@@ -29,11 +35,17 @@ module.exports = createPulumiCommand({
2935
}
3036

3137
if (!stackExists) {
32-
context.error(`Project application %s (%s} environment) does not exist.`, folder, env);
38+
const variantNameMessage = variant ? `, %s variant` : "";
39+
context.error(
40+
`Project application %s (%s environment${variantNameMessage}) does not exist.`,
41+
folder,
42+
env,
43+
variant
44+
);
3345
return;
3446
}
3547

36-
const hooksParams = { context, env, projectApplication };
48+
const hooksParams = { context, env, variant, projectApplication };
3749

3850
await processHooks("hook-before-destroy", hooksParams);
3951

@@ -47,6 +59,7 @@ module.exports = createPulumiCommand({
4759
stdio: "inherit",
4860
env: {
4961
WEBINY_ENV: env,
62+
WEBINY_ENV_VARIANT: variant || "",
5063
WEBINY_PROJECT_NAME: context.project.name
5164
}
5265
}

packages/cli-plugin-deploy-pulumi/commands/executeMigrations.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const {
99
} = require("@webiny/data-migration/cli");
1010

1111
module.exports = async (params, context) => {
12-
const apiOutput = getStackOutput({ folder: "apps/api", env: params.env });
12+
const apiOutput = getStackOutput({
13+
folder: "apps/api",
14+
env: params.env,
15+
variant: params.variant
16+
});
1317

1418
context.info("Executing data migration Lambda function...");
1519

packages/cli-plugin-deploy-pulumi/commands/index.js

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ module.exports = [
2323
describe: `Environment`,
2424
type: "string"
2525
});
26-
// yargs.option("variant", {
27-
// describe: `Variant (only for staged rollouts)`,
28-
// type: "string"
29-
// });
26+
yargs.option("variant", {
27+
describe: `Variant`,
28+
type: "string",
29+
required: false
30+
});
3031
yargs.option("build", {
3132
default: true,
3233
describe: `Build packages before deploying`,
@@ -118,10 +119,11 @@ module.exports = [
118119
describe: `Environment`,
119120
type: "string"
120121
});
121-
// yargs.option("variant", {
122-
// describe: `Variant (only for staged rollouts)`,
123-
// type: "string"
124-
// });
122+
yargs.option("variant", {
123+
describe: `Variant`,
124+
type: "string",
125+
required: false
126+
});
125127
yargs.option("debug", {
126128
default: false,
127129
describe: `Turn on debug logs`,
@@ -165,6 +167,11 @@ module.exports = [
165167
describe: `Environment`,
166168
type: "string"
167169
});
170+
yargs.option("variant", {
171+
describe: `Variant`,
172+
type: "string",
173+
required: false
174+
});
168175
yargs.option("package", {
169176
alias: "p",
170177
describe: `One or more packages that will be watched for code changes`,
@@ -228,6 +235,11 @@ module.exports = [
228235
describe: `Environment`,
229236
type: "string"
230237
});
238+
yargs.option("variant", {
239+
describe: `Variant`,
240+
type: "string",
241+
required: false
242+
});
231243
yargs.option("build", {
232244
describe: `While making code changes, re-build all relevant packages`,
233245
type: "boolean"
@@ -297,7 +309,11 @@ module.exports = [
297309
describe: `Environment`,
298310
type: "string"
299311
});
300-
312+
yargs.option("variant", {
313+
describe: `Variant`,
314+
type: "string",
315+
required: false
316+
});
301317
yargs
302318
.option("confirm-destroy-env", {
303319
describe: `Confirm environment name to destroy. Must be passed when destroying the whole project.`,
@@ -355,10 +371,11 @@ module.exports = [
355371
describe: `Environment`,
356372
type: "string"
357373
});
358-
// yargs.option("variant", {
359-
// describe: `Variant (staged rollouts only)`,
360-
// type: "string"
361-
// });
374+
yargs.option("variant", {
375+
describe: `Variant`,
376+
type: "string",
377+
required: false
378+
});
362379
yargs.option("json", {
363380
describe: `Emit output as JSON`,
364381
type: "boolean"
@@ -389,10 +406,11 @@ module.exports = [
389406
describe: `Environment`,
390407
type: "string"
391408
});
392-
// yargs.option("variant", {
393-
// describe: `Variant (only for staged rollouts)`,
394-
// type: "string"
395-
// });
409+
yargs.option("variant", {
410+
describe: `Variant`,
411+
type: "string",
412+
required: false
413+
});
396414
yargs.option("debug", {
397415
default: false,
398416
describe: `Turn on debug logs`,
@@ -422,7 +440,11 @@ module.exports = [
422440
type: "string",
423441
required: true
424442
});
425-
443+
yargs.option("variant", {
444+
describe: `Variant`,
445+
type: "string",
446+
required: false
447+
});
426448
yargs.option("force", {
427449
describe: `!!USE WITH CAUTION!! Force execution of the migrations.`,
428450
type: "boolean",

packages/cli-plugin-deploy-pulumi/commands/newWatch.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ module.exports = async (inputs, context) => {
153153
);
154154
});
155155

156-
const deploymentId = getDeploymentId({ env: inputs.env });
156+
const deploymentId = getDeploymentId({
157+
env: inputs.env,
158+
variant: inputs.variant
159+
});
157160
const iotEndpointTopic = `webiny-watch-${deploymentId}`;
158-
const iotEndpoint = await getIotEndpoint({ env: inputs.env });
161+
const iotEndpoint = await getIotEndpoint({
162+
env: inputs.env,
163+
variant: inputs.variant
164+
});
159165
const sessionId = new Date().getTime();
160166
const increaseTimeout = inputs.increaseTimeout;
161167

0 commit comments

Comments
 (0)