【问题标题】:Environments with multi-stages pipeline in AWSAWS 中具有多阶段管道的环境
【发布时间】:2021-10-28 22:38:14
【问题描述】:

当我们创建项目时,它部署在 Staging dev 上(参考下面使用的 yaml 模板)。现在,无论何时我们提交它都会这样做。现在我们的问题是我们需要从登台到生产的手动审批阶段的开发和生产环境。 我们根据下图添加了两个阶段(批准和生产)

有人可以帮忙说一下我该如何修改我下面的 YAML 代码:

如果 $CODEBUILD_BUILD_STAGE == 'prod' 目标桶 = $S3_BUCKET_PROD 别的 target_bucket = $S3_BUCKET_DEV

这是我未经批准和生产阶段的代码:

version: 0.2
env:
  variables:
    S3_BUCKET: "s3-frontend"
phases:
  install:
    runtime-versions:
      nodejs: 10
  pre_build:
    commands:
      - echo Installing source NPM dependencies
      - cd project
      # Install node dependancies.
      - npm install
      - npm install -g @angular/cli@"~9.1.1"
  build:
    commands:
      - echo Build started on `date`
      - export NODE_OPTIONS=--max_old_space_size=16384
      #building 
      - ng build --aot --configuration=production --build-optimizer --stats-json --output-path=dist/en
  post_build:
    commands:
      #only run frontend update when the build is success
      - bash -c "if [ /"$CODEBUILD_BUILD_SUCCEEDING/" == /"0/" ]; then exit 1; fi"
      - aws s3 rm s3://$S3_BUCKET --recursive
      #generating root language
      - aws s3 cp dist/en s3://$S3_BUCKET --recursive 
artifacts:
  files:
    - '**/*'
cache:
  paths:
    - '/root/.m2/**/*'
    - '/root/.npm/**/*'
    - 'build/**/*'
    - 'node_modules/**/*'

【问题讨论】:

    标签: amazon-web-services yaml aws-codepipeline


    【解决方案1】:

    我相信 CodeBuild 的约定是在调用项目时设置 var,因为我认为每一行都是一个单独的 shell。因此,例如在 cloudformation 模板中将存储桶作为参数“S3_BUCKET_DEV”和“S3_BUCKET_PROD”:

              - Name: Dev
                ActionTypeId:
                  Category: Build
                  Owner: AWS
                  Provider: CodeBuild
                  Version: "1"
                Configuration:
                  ProjectName: !Ref DeployProj
                  EnvironmentVariables: !Sub |
                    [
                      {"name":"S3_BUCKET","value":"${S3_BUCKET_DEV}","type":"PLAINTEXT"}
                    ]
    
                InputArtifacts:
                  - Name: Whatever
                RunOrder: 2
    
    
              - Name: Prod
                ActionTypeId:
                  Category: Build
                  Owner: AWS
                  Provider: CodeBuild
                  Version: "1"
                Configuration:
                  ProjectName: !Ref DeployProj
                  EnvironmentVariables: !Sub |
                    [
                      {"name":"S3_BUCKET","value":"$S3_BUCKET_PROD","type":"PLAINTEXT"}
                    ]
    
                InputArtifacts:
                  - Name: Whatever
                RunOrder: 2
    

    【讨论】:

    • 您好,对不起,我不熟悉您提供的这种结构。我更多地致力于 YAML 代码。如果我理解您的代码,您将运行代码构建两次,而要求是运行一次。然后进行检查:如果 MANUAL_APPROVAL 来自用户,则转到 PROD
    • 为了澄清一下,您不要在 buildspec 中设置变量,而是在管道中执行项目时将变量传递给 codebuild。该变量属于代码管道定义中的 Stage/Action。我的示例展示了如何在 Cloudformation 中执行此操作。如果您不使用 Cloudformation,您可以在控制台中编辑管道定义并在那里设置变量。
    猜你喜欢
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 2020-03-08
    • 2017-05-11
    相关资源
    最近更新 更多