在 CDK CodePipelines 中添加手动审批阶段
Adding manual approval stage in CDK CodePipelines
我一直在使用 AWS CDK,我认为这是使用 AWS 的一种很好的方式。最近我遇到了一个我无法解决的问题。查看了文档和资源,但 none 已经解释了如何在 CDK 中执行此操作。所以我有两个代码管道,每个管道部署到暂存或生产。现在我想要在代码部署到生产环境之前进行手动批准。我将在下面显示我的简单代码以供参考:
import * as cdk from '@aws-cdk/core';
import { AppsPluginsCdkStack } from './apps-plugins-services/stack';
import {
CodePipeline,
ShellStep,
CodePipelineSource
} from '@aws-cdk/pipelines';
class ApplicationStage extends cdk.Stage {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new CdkStack(this, 'cdkStack');
}
}
class ProductionPipelineStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
//Create the CDK Production Pipeline
const prodPipeline = new CodePipeline(this, 'ProductionPipeline', {
pipelineName: 'ProdPipeline',
synth: new ShellStep('ProdSynth', {
// Use a connection created using the AWS console to authenticate to GitHub
input: CodePipelineSource.connection(
'fahigm/cdk-repo',
'develop',
{
connectionArn:
'AWS-CONNECTION-ARN' // Created using the AWS console
}
),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});
prodPipeline.addStage(new ApplicationStage(this, 'Production'));
}
}
class StagingPipelineStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
//Create the CDK Staging Pipeline
const stagePipeline = new CodePipeline(this, 'StagingPipeline', {
pipelineName: 'StagePipeline',
synth: new ShellStep('StageSynth', {
// Use a connection created using the AWS console to authenticate to GitHub
input: CodePipelineSource.connection(
'fahigm/cdk-repo',
'master',
{
connectionArn:
'AWS-CONNECTION-ARN' // Created using the AWS console
}
),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});
stagePipeline.addStage(new ApplicationStage(this, 'Staging'));
}
}
//
const app = new cdk.App();
new ProductionPipelineStack(app, 'ProductionCDKPipeline', {
env: { account: 'ACCOUNT', region: 'REGION' }
});
new StagingPipelineStack(app, 'StagingCDKPipeline', {
env: { account: 'ACCOUNT', region: 'REGION' }
});
app.synth();
现在我不知道该何去何从。该文档仅讨论如何从控制台执行此操作,但我想将其添加到代码中。非常感谢任何帮助!
CDK 文档实际上并没有讨论如何从控制台执行此操作,而是讨论了如何使用 CDK 执行此操作,并提供了示例。这是一个例子 straight from the docs:
The following example shows both an automated approval in the form of a ShellStep, and a manual approval in the form of a ManualApprovalStep added to the pipeline. Both must pass in order to promote from the PreProd to the Prod environment:
declare const pipeline: pipelines.CodePipeline;
const preprod = new MyApplicationStage(this, 'PreProd');
const prod = new MyApplicationStage(this, 'Prod');
pipeline.addStage(preprod, {
post: [
new pipelines.ShellStep('Validate Endpoint', {
commands: ['curl -Ssf https://my.webservice.com/'],
}),
],
});
pipeline.addStage(prod, {
pre: [
new pipelines.ManualApprovalStep('PromoteToProd'),
],
});
以下是关于手动批准步骤的文档:https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.ManualApprovalStep.html
我一直在使用 AWS CDK,我认为这是使用 AWS 的一种很好的方式。最近我遇到了一个我无法解决的问题。查看了文档和资源,但 none 已经解释了如何在 CDK 中执行此操作。所以我有两个代码管道,每个管道部署到暂存或生产。现在我想要在代码部署到生产环境之前进行手动批准。我将在下面显示我的简单代码以供参考:
import * as cdk from '@aws-cdk/core';
import { AppsPluginsCdkStack } from './apps-plugins-services/stack';
import {
CodePipeline,
ShellStep,
CodePipelineSource
} from '@aws-cdk/pipelines';
class ApplicationStage extends cdk.Stage {
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new CdkStack(this, 'cdkStack');
}
}
class ProductionPipelineStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
//Create the CDK Production Pipeline
const prodPipeline = new CodePipeline(this, 'ProductionPipeline', {
pipelineName: 'ProdPipeline',
synth: new ShellStep('ProdSynth', {
// Use a connection created using the AWS console to authenticate to GitHub
input: CodePipelineSource.connection(
'fahigm/cdk-repo',
'develop',
{
connectionArn:
'AWS-CONNECTION-ARN' // Created using the AWS console
}
),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});
prodPipeline.addStage(new ApplicationStage(this, 'Production'));
}
}
class StagingPipelineStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
//Create the CDK Staging Pipeline
const stagePipeline = new CodePipeline(this, 'StagingPipeline', {
pipelineName: 'StagePipeline',
synth: new ShellStep('StageSynth', {
// Use a connection created using the AWS console to authenticate to GitHub
input: CodePipelineSource.connection(
'fahigm/cdk-repo',
'master',
{
connectionArn:
'AWS-CONNECTION-ARN' // Created using the AWS console
}
),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});
stagePipeline.addStage(new ApplicationStage(this, 'Staging'));
}
}
//
const app = new cdk.App();
new ProductionPipelineStack(app, 'ProductionCDKPipeline', {
env: { account: 'ACCOUNT', region: 'REGION' }
});
new StagingPipelineStack(app, 'StagingCDKPipeline', {
env: { account: 'ACCOUNT', region: 'REGION' }
});
app.synth();
现在我不知道该何去何从。该文档仅讨论如何从控制台执行此操作,但我想将其添加到代码中。非常感谢任何帮助!
CDK 文档实际上并没有讨论如何从控制台执行此操作,而是讨论了如何使用 CDK 执行此操作,并提供了示例。这是一个例子 straight from the docs:
The following example shows both an automated approval in the form of a ShellStep, and a manual approval in the form of a ManualApprovalStep added to the pipeline. Both must pass in order to promote from the PreProd to the Prod environment:
declare const pipeline: pipelines.CodePipeline;
const preprod = new MyApplicationStage(this, 'PreProd');
const prod = new MyApplicationStage(this, 'Prod');
pipeline.addStage(preprod, {
post: [
new pipelines.ShellStep('Validate Endpoint', {
commands: ['curl -Ssf https://my.webservice.com/'],
}),
],
});
pipeline.addStage(prod, {
pre: [
new pipelines.ManualApprovalStep('PromoteToProd'),
],
});
以下是关于手动批准步骤的文档:https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.ManualApprovalStep.html