CDK应用程序的持续集成/持续交付

aws-cdk.app-deliver的Python项目详细描述


CDK应用程序的持续集成/持续交付


Stability: Experimental

This is a developer preview (public beta) module. Releases might lack important features and might have future breaking changes.

This API is still under active development and subject to non-backward compatible changes or removal in any future version. Use of the API is not recommended in production environments. Experimental APIs are not subject to the Semantic Versioning model.


此库包含用于部署aws cdk应用程序的codepipline组合操作。

这个模块是AWS Cloud Development Kit项目的一部分。

限制

当前形式的构造库有以下限制:

  1. 它只能部署托管在与codeppipeline相同的aws帐户和区域中的堆栈。
  2. 无法成功部署使用Assets的堆栈。

开始

为了将PipelineDeployStackAction添加到codepiple中,需要有一个codepiple工件 包含在cdk app上调用cdk synth -o <dir>的结果。例如,可以使用 codebuild项目。

下面的示例定义了一个cdk应用程序,它包含3个堆栈:

  • CodePipelineStack在部署任何其他堆栈之前,管理codepipline资源和自我更新
  • ServiceStackAServiceStackB是服务基础架构堆栈,需要按此顺序部署
  ┏━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━━┓  ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
  ┃     Source     ┃  ┃     Build      ┃  ┃  Self-Update    ┃  ┃             Deploy              ┃
  ┃                ┃  ┃                ┃  ┃                 ┃  ┃                                 ┃
  ┃ ┌────────────┐ ┃  ┃ ┌────────────┐ ┃  ┃ ┌─────────────┐ ┃  ┃ ┌─────────────┐ ┌─────────────┐ ┃
  ┃ │   GitHub   ┣━╋━━╋━▶ CodeBuild  ┣━╋━━╋━▶Deploy Stack ┣━╋━━╋━▶Deploy Stack ┣━▶Deploy Stack │ ┃
  ┃ │            │ ┃  ┃ │            │ ┃  ┃ │PipelineStack│ ┃  ┃ │ServiceStackA│ │ServiceStackB│ ┃
  ┃ └────────────┘ ┃  ┃ └────────────┘ ┃  ┃ └─────────────┘ ┃  ┃ └─────────────┘ └─────────────┘ ┃
  ┗━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━━┛  ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

index.ts

importcodebuild=require('@aws-cdk/aws-codebuild');importcodepipeline=require('@aws-cdk/aws-codepipeline');importcodepipeline_actions=require('@aws-cdk/aws-codepipeline-actions');importcdk=require('@aws-cdk/core');importcicd=require('@aws-cdk/app-delivery');constapp=newcdk.App();// We define a stack that contains the CodePipelineconstpipelineStack=newcdk.Stack(app,'PipelineStack');constpipeline=newcodepipeline.Pipeline(pipelineStack,'CodePipeline',{// Mutating a CodePipeline can cause the currently propagating state to be// "lost". Ensure we re-run the latest change through the pipeline after it's// been mutated so we're sure the latest state is fully deployed through.restartExecutionOnUpdate: true,/* ... */});// Configure the CodePipeline source - where your CDK App's source code is hostedconstsourceOutput=newcodepipeline.Artifact();constsource=newcodepipeline_actions.GitHubSourceAction({actionName:'GitHub',output: sourceOutput,/* ... */});pipeline.addStage({stageName:'source',actions:[source],});constproject=newcodebuild.PipelineProject(pipelineStack,'CodeBuild',{/**  * Choose an environment configuration that meets your use case.  * For NodeJS, this might be:  *  * environment: {  *   buildImage: codebuild.LinuxBuildImage.UBUNTU_14_04_NODEJS_10_1_0,  * },  */});constsynthesizedApp=newcodepipeline.Artifact();constbuildAction=newcodepipeline_actions.CodeBuildAction({actionName:'CodeBuild',project,input: sourceOutput,outputs:[synthesizedApp],});pipeline.addStage({stageName:'build',actions:[buildAction],});// Optionally, self-update the pipeline stackconstselfUpdateStage=pipeline.addStage({stageName:'SelfUpdate'});selfUpdateStage.addAction(newcicd.PipelineDeployStackAction({stack: pipelineStack,input: synthesizedApp,adminPermissions: true,}));// Now add our service stacksconstdeployStage=pipeline.addStage({stageName:'Deploy'});constserviceStackA=newMyServiceStackA(app,'ServiceStackA',{/* ... */});// Add actions to deploy the stacks in the deploy stage:constdeployServiceAAction=newcicd.PipelineDeployStackAction({stack: serviceStackA,input: synthesizedApp,// See the note below for details about this option.adminPermissions: false,});deployStage.addAction(deployServiceAAction);// Add the necessary permissions for you service deploy action. This role is// is passed to CloudFormation and needs the permissions necessary to deploy// stack. Alternatively you can enable [Administrator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_job-functions.html#jf_administrator) permissions above,// users should understand the privileged nature of this role.deployServiceAAction.addToRolePolicy(newiam.PolicyStatement({actions:['service:SomeAction'],resources:[myResource.myResourceArn],// add more Action(s) and/or Resource(s) here, as needed}));constserviceStackB=newMyServiceStackB(app,'ServiceStackB',{/* ... */});deployStage.addAction(newcicd.PipelineDeployStackAction({stack: serviceStackB,input: synthesizedApp,createChangeSetRunOrder: 998,adminPermissions: true,// no need to modify the role with admin}));

buildspec.yml

存储库可以在根级别包含名为buildspec.yml的文件,或者 你可以把建筑规范排成一行。注意buildspec.yaml不兼容。

例如,一个typescriptjavascriptcdk应用程序可以添加以下buildspec.yml 在存储库的根目录:

version: 0.2
phases:
  install:
    commands:
      # Installs the npm dependencies as defined by the `package.json` file
      # present in the root directory of the package
      # (`cdk init app --language=typescript` would have created one for you)
      - npm install
  build:
    commands:
      # Builds the CDK App so it can be synthesized
      - npm run build
      # Synthesizes the CDK App and puts the resulting artifacts into `dist`
      - npm run cdk synth -- -o dist
artifacts:
  # The output artifact is all the files in the `dist` directory
  base-directory: dist
  files: '**/*'

PipelineDeployStackAction期望input包含 使用cdk synth -o <directory>合成cdk应用程序。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java当我点击MainActivity中的按钮以显示其他活动时,它不起作用   java游戏!框架:在请求之间获取控制器的组件/字段/对象   JavaBlackBerry:调用计算器并检索值?   java Struts2 jQuery插件提交按钮   java无法将更新的画布绘制到活动   java如何将Gson值放入HashMap   使用截取时出现java错误:RecyclerView:未连接适配器;跳过布局   java组织。冬眠HibernateException:在Hibernate搜索中编制索引时出错(在事务完成之前)   java Swagger服务器存根生成工作流   java JInternalFrame底部阴影问题   java nio缓冲区类中limit()的用法是什么   java水平回收器视图内部选项卡布局   java Maven无法找到依赖项   java如何管理不同应用程序实例的权限文件?