Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pulumi-aws): deploy environment variant #4501

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/api-apw/src/scheduler/handlers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,16 @@ export interface ApwSettings {
eventTargetId: string;
}

const getVariant = (): string => {
const value = process.env.WEBINY_ENV_VARIANT;
if (!value || value === "undefined" || typeof value !== "string") {
return "";
}
return String(value);
};

export const getApwSettings = async (): Promise<ApwSettings> => {
const variant = process.env.STAGED_ROLLOUTS_VARIANT;
const variant = getVariant();

const params = {
TableName: process.env.DB_TABLE as string,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-plugin-deploy-pulumi/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = (params, context) => {
name: "build",
createProjectApplicationWorkspace: true,
command: async ({ inputs, context, projectApplication }) => {
const { env } = inputs;
const { env, variant } = inputs;

const hookArgs = { context, env, inputs, projectApplication };
const hookArgs = { context, env, variant, inputs, projectApplication };

await runHook({
hook: "hook-before-build",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-plugin-deploy-pulumi/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module.exports = (params, context) => {
telemetry: true,
command: async commandParams => {
const { inputs, context, projectApplication, pulumi, getDuration } = commandParams;
const { env, folder, build, deploy } = inputs;
const { env, variant, folder, build, deploy } = inputs;

const hookArgs = { context, env, inputs, projectApplication };
const hookArgs = { context, env, variant, inputs, projectApplication };

context.info("Webiny version: %s", context.version);
console.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module.exports = async ({ inputs, context, pulumi }) => {
execa: {
env: {
WEBINY_ENV: inputs.env,
WEBINY_ENV_VARIANT: inputs.variant || "",
WEBINY_PROJECT_NAME: context.project.name,
PULUMI_CONFIG_PASSPHRASE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = async ({ inputs, context, pulumi }) => {
execa: {
env: {
WEBINY_ENV: inputs.env,
WEBINY_ENV_VARIANT: inputs.variant || "",
WEBINY_PROJECT_NAME: context.project.name,
PULUMI_CONFIG_PASSPHRASE
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const { login } = require("../../utils");
const { getStackName } = require("../../utils/getStackName");

module.exports = async ({ inputs, projectApplication, pulumi }) => {
const { env } = inputs;
const { env, variant } = inputs;

await login(projectApplication);

const PULUMI_SECRETS_PROVIDER = process.env.PULUMI_SECRETS_PROVIDER;
const PULUMI_CONFIG_PASSPHRASE = process.env.PULUMI_CONFIG_PASSPHRASE;

const stackName = getStackName({
env,
variant
});

await pulumi.run({
command: ["stack", "select", env],
command: ["stack", "select", stackName],
args: {
create: true,
secretsProvider: PULUMI_SECRETS_PROVIDER
Expand Down
21 changes: 17 additions & 4 deletions packages/cli-plugin-deploy-pulumi/commands/destroy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
const { createPulumiCommand, processHooks } = require("../utils");
const { getStackName } = require("../utils/getStackName");

module.exports = createPulumiCommand({
name: "destroy",
// We want to create a workspace just because there are cases where the destroy command is called
// without the deployment happening initially (e.g. CI/CD scaffold's `pullRequestClosed.yml` workflow).
createProjectApplicationWorkspace: true,
command: async ({ inputs, context, projectApplication, pulumi, getDuration }) => {
const { env, folder } = inputs;
const { env, variant, folder } = inputs;

const stackName = getStackName({
env,
variant
});

let stackExists = true;
try {
const PULUMI_SECRETS_PROVIDER = process.env.PULUMI_SECRETS_PROVIDER;
const PULUMI_CONFIG_PASSPHRASE = process.env.PULUMI_CONFIG_PASSPHRASE;

await pulumi.run({
command: ["stack", "select", env],
command: ["stack", "select", stackName],
args: {
secretsProvider: PULUMI_SECRETS_PROVIDER
},
Expand All @@ -29,11 +35,17 @@ module.exports = createPulumiCommand({
}

if (!stackExists) {
context.error(`Project application %s (%s} environment) does not exist.`, folder, env);
const variantNameMessage = variant ? `, %s variant` : "";
context.error(
`Project application %s (%s environment${variantNameMessage}) does not exist.`,
folder,
env,
variant
);
return;
}

const hooksParams = { context, env, projectApplication };
const hooksParams = { context, env, variant, projectApplication };

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

Expand All @@ -47,6 +59,7 @@ module.exports = createPulumiCommand({
stdio: "inherit",
env: {
WEBINY_ENV: env,
WEBINY_ENV_VARIANT: variant || "",
WEBINY_PROJECT_NAME: context.project.name
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ const {
} = require("@webiny/data-migration/cli");

module.exports = async (params, context) => {
const apiOutput = getStackOutput({ folder: "apps/api", env: params.env });
const apiOutput = getStackOutput({
folder: "apps/api",
env: params.env,
variant: params.variant
});

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

Expand Down
58 changes: 40 additions & 18 deletions packages/cli-plugin-deploy-pulumi/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
// yargs.option("variant", {
// describe: `Variant (only for staged rollouts)`,
// type: "string"
// });
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("build", {
default: true,
describe: `Build packages before deploying`,
Expand Down Expand Up @@ -118,10 +119,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
// yargs.option("variant", {
// describe: `Variant (only for staged rollouts)`,
// type: "string"
// });
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("debug", {
default: false,
describe: `Turn on debug logs`,
Expand Down Expand Up @@ -165,6 +167,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("package", {
alias: "p",
describe: `One or more packages that will be watched for code changes`,
Expand Down Expand Up @@ -228,6 +235,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("build", {
describe: `While making code changes, re-build all relevant packages`,
type: "boolean"
Expand Down Expand Up @@ -297,7 +309,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});

yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs
.option("confirm-destroy-env", {
describe: `Confirm environment name to destroy. Must be passed when destroying the whole project.`,
Expand Down Expand Up @@ -355,10 +371,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
// yargs.option("variant", {
// describe: `Variant (staged rollouts only)`,
// type: "string"
// });
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("json", {
describe: `Emit output as JSON`,
type: "boolean"
Expand Down Expand Up @@ -389,10 +406,11 @@ module.exports = [
describe: `Environment`,
type: "string"
});
// yargs.option("variant", {
// describe: `Variant (only for staged rollouts)`,
// type: "string"
// });
yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("debug", {
default: false,
describe: `Turn on debug logs`,
Expand Down Expand Up @@ -422,7 +440,11 @@ module.exports = [
type: "string",
required: true
});

yargs.option("variant", {
describe: `Variant`,
type: "string",
required: false
});
yargs.option("force", {
describe: `!!USE WITH CAUTION!! Force execution of the migrations.`,
type: "boolean",
Expand Down
10 changes: 8 additions & 2 deletions packages/cli-plugin-deploy-pulumi/commands/newWatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,15 @@ module.exports = async (inputs, context) => {
);
});

const deploymentId = getDeploymentId({ env: inputs.env });
const deploymentId = getDeploymentId({
env: inputs.env,
variant: inputs.variant
});
const iotEndpointTopic = `webiny-watch-${deploymentId}`;
const iotEndpoint = await getIotEndpoint({ env: inputs.env });
const iotEndpoint = await getIotEndpoint({
env: inputs.env,
variant: inputs.variant
});
const sessionId = new Date().getTime();
const increaseTimeout = inputs.increaseTimeout;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const getIotEndpoint = (params = {}) => {
.then(({ endpointAddress }) => {
const coreStackOutput = getStackOutput({
folder: "core",
env: params.env
env: params.env,
variant: params.variant
});

const watchCommandTopic = `webiny-watch-${coreStackOutput.deploymentId}`;
Expand Down
25 changes: 20 additions & 5 deletions packages/cli-plugin-deploy-pulumi/commands/output.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
const { createPulumiCommand } = require("../utils");
const { getStackName } = require("../utils/getStackName");

module.exports = createPulumiCommand({
name: "output",
createProjectApplicationWorkspace: false,
command: async ({ inputs, context, pulumi }) => {
const { env, folder, json } = inputs;
const { env, variant, folder, json } = inputs;

const stackName = getStackName({
env,
variant
});

let stackExists = true;
try {
const PULUMI_SECRETS_PROVIDER = process.env.PULUMI_SECRETS_PROVIDER;
const PULUMI_CONFIG_PASSPHRASE = process.env.PULUMI_CONFIG_PASSPHRASE;

await pulumi.run({
command: ["stack", "select", env],
command: ["stack", "select", `${stackName}`],
args: {
secretsProvider: PULUMI_SECRETS_PROVIDER
},
Expand All @@ -27,19 +33,28 @@ module.exports = createPulumiCommand({
}

if (stackExists) {
return pulumi.run({
return await pulumi.run({
command: ["stack", "output"],
args: {
json
},
execa: { stdio: "inherit" }
execa: {
stdio: "inherit"
}
});
}

if (json) {
return console.log(JSON.stringify(null));
}

context.error(`Project application %s (%s environment) does not exist.`, folder, env);
const variantMessage = variant ? `, %s variant` : "";

context.error(
`Project application %s (%s environment${variantMessage}) does not exist.`,
folder,
env,
variant
);
}
});
Loading
Loading