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 Android Studio:我的短信应用程序不是默认短信应用程序的选项之一   java处理字符串问题   java为什么我的程序打印“null”而不是字符串?   java为什么要创建一个无限循环?   java循环在一段时间后将布尔值更改为false?   java Android Rest Api Post 400错误请求   java调用另一个方法以获取resultset并正确关闭连接?   java我想在2d数组中添加一行   Java:我需要从outputstream中获取字节数组   C语言中Java元注释的等价物#   java如何在从web下载图像时保持原始图像的dpi?   java中基于输入值的spring boot动态值   java从请求中获取主机名   java可以复制Swing代码并在intelliJ中的designer中查看它吗   spring如何使用java配置多个ldap   安卓如何在Java中使用具有多个类似参数的JSON请求/响应循环?   java LIbGDX如何在语言更改时翻译所有文本?